Documente Academic
Documente Profesional
Documente Cultură
COMPUTER SCI.
PRACTICAL
FILE
ARVIND MISHRA
th
CLASS:12 S
YEAR:2014-2015
APEX PUBLIC SCHOOL
ROLL NO.
3
SIGNATURE
S.N
O
TOPIC
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
18.
19.
20.
/*
programme
}
else
{
for(i=0;i<l1;i++)
{
if(str1[i]!=str2[i])
{
flag=1;
break;
}
}
if(flag==1)
{
cout<<"\n Strings are not Equal ";
}
else
{
cout<<"\n Strings are Equal ";
}
}
}
void concat()
{
char str1[30], str2[30];
int l1=0,l2=0,i=0,flag=0;
cout<<"\n Enter the string1 (size<=30) ";
gets(str1);
while(str1[l1]!='\0')
{
l1++;
}
cout<<"\n Enter the string2 (size<=30) ";
gets(str2);
while(str2[l2]!='\0')
{
l2++;
PREPARED BY ARVIND MISHRA (XII S)
}
for(i=0;i<l2;i++)
{
str1[l1+i]=str2[i];
}
str1[l1+l2]='\0';
cout<<"\n The concatenated String is: ";
puts(str1);
}
void main()
{
clrscr();
cout<<"Enter your choice \n \t1.Find length of string\n\t"
"2.Compare two Strings \n\t3.Concatenate two strings\n\t4.Exit \n";
char ch;
cin>>ch;
do
{
if(ch=='1')
findlength();
if(ch=='2')
compare();
if(ch=='3')
concat();
cout<<"Enter your choice \n \t1.Find length of string\n\t"
"2.Compare two Strings \n\t3.Concatenate two strings\n\t4.Exit \n";
cin>>ch;
}while(ch!='4');
getch();
}
/* OUTPUT
Enter your choice
1.Find length of string
2.Compare two Strings
3.Concatenate two strings
PREPARED BY ARVIND MISHRA (XII S)
4.Exit
1
Enter the string (size<=30) PANKAJ KUMAR
Length Of the given String is: 12
Enter your choice
1.Find length of string
2.Compare two Strings
3.Concatenate two strings
4.Exit
2
Enter the string1 (size<=30) INDIA
Enter the string2 (size<=30) INDIA
Strings are Equal Enter your choice
1.Find length of string
2.Compare two Strings
3.Concatenate two strings
4.Exit
3
Enter the string1 (size<=30) INDIA
Enter the string2 (size<=30) IS GREATE
The concatenated String is: INDIA IS GRATE
Enter your choice
1.Find length of string
2.Compare two Strings
3.Concatenate two strings
4.Exit
4
10
11
12
cin>>ch;
}while(ch!='3');
getch();
}
/* OUTPUT
Enter no. of records (<=10): 2
Enter the country: INDIA
Enter the capital: DELHI
Enter the country: AMERICA
Enter the capital: NEW YORK
1.Search for capital
2.List all Records
3.Exit1
Enter the country : INDIA
capital is: DELHI
1.Search for capital
2.List all Records
3.Exit2
COUNTRY
CAPITAL
------------INDIA
DELHI
AMERICA
NEW YORK
1.Search for capital
2.List all Records
3.Exit3
*/
13
14
clrscr();
int a[10][10],i,j,m,n;
cout<<"\n EnterNo. of rows: ";
cin>>m;
cout<<"\nEnter the no. of columns: ";
cin>>n;
cout<<"\nEnter the Elements of the array: ";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
twodigit(a,m,n);
getch();
}
/* OUTPUT
EnterNo. of rows: 2
Enter the no. of columns: 2
Enter the Elements of the array: 10 2 11 5
The Two digit Numbers are: 10 y: 10 2 11 5
*/
15
16
cin>>(m1[i]);
cout<<"Enter Mark2 of Student "<<i<<": ";
cin>>(m2[i]);
cout<<"Enter Mark3 of Student "<<i<<": ";
cin>>(m3[i]);
tot[i]=m1[i]+m2[i]+m3[i];
}
char ch,ch1;
int flag=0;
cout<<"\n\t1.Report card for particular student"
"\n\t2.List all records\n\t3.Exit";
cin>>ch;
do
{
switch(ch)
{
case '1':
cout<<"\nEnter the Roll no.";
cin>>trn;
flag=0;
for(i=0;i<n;i++)
if(trn==rno[i])
{
cout<<"\n Name: "<<name[i]<<"\t";
cout<<"Roll No.: "<<rno[i];
cout<<"\nMark1: "<<m1[i];
cout<<"\nMark2: "<<m2[i];
cout<<"\nMark3: "<<m3[i];
cout<<"\n----------";
cout<<"\nTotal: "<<tot[i];
flag=1;
}
if(flag==0)
cout<<"Record not found";
break;
case '2':
cout<<"\nRollno\tName
\tMark1\tMark2\tMark3";
cout<<"\tTotal";
PREPARED BY ARVIND MISHRA (XII S)
17
18
cout<<"\n------\t----------\t----\t----\t----";
cout<<"\t-----";
for(i=0;i<n;i++)
{
cout<<"\n"<<rno[i]<<"\t"<<name[i]<<"\t"
<<m1[i]<<"\t"<<m2[i]<<"\t"<<m3[i]<<"\t"
<<tot[i];
}
break;
}
cout<<"\n\t1.Report card for particular student"
"\n\t2.List all records\n\t3.Exit";
cin>>ch;
}while(ch!='3');
getch();
}
/* OUTPUT
Enter no. of records: 2
Enter Name of Student 0: PANKAJ
Enter Roll No. of Student 0: 16
Enter Mark1 of Student 0: 70
Enter Mark2 of Student 0: 80
Enter Mark3 of Student 0: 90
Enter Name of Student 1: RAJU
Enter Roll No. of Student 1: 17
Enter Mark1 of Student 1: 99
Enter Mark2 of Student 1: 100
Enter Mark3 of Student 1: 56
1.Report card for particular student
2.List all records
3.Exit1
Enter the Roll no.17
Name: RAJU Roll No.: 17
Mark1: 99
Mark2: 100
Mark3: 56
---------Total: 255
PREPARED BY ARVIND MISHRA (XII S)
19
20
gotoxy(16,25);
cout <<"Roll";
gotoxy(26,25);
cout <<"Mark1";
gotoxy(36,25);
cout <<"Mark2";
gotoxy(46,25);
cout <<"Mark3";
gotoxy(56,25);
cout <<"Total";
int r = 30;
for(i=0;i<n;i++)
{
gotoxy(6,r);
cout <<st[i].name;
gotoxy(16,r);
cout <<st[i].roll;
gotoxy(26,r);
cout <<st[i].mark1;
gotoxy(36,r);
cout <<st[i].mark2;
gotoxy(46,r);
cout <<st[i].mark3;
gotoxy(56,r);
cout <<st[i].total;
r++;
}
break;
case 3:
int troll;
cout << "\nEnter the roll number to be searched ";
cin >> troll;
for(i=0;i<n;i++)
{
if (st[i].roll == troll)
{
cout << " \n Name "<<st[i].name;
cout << "\n Roll "<< st[i].roll;
cout << "\n Mark1 "<<st[i].mark1;
cout << "\n Mark2 "<<st[i].mark2;
PREPARED BY ARVIND MISHRA (XII S)
21
Mark3
203
240
Total
22
23
24
cout <<"Roll";
gotoxy(26,25);
cout <<"Mark1";
gotoxy(36,25);
cout <<"Mark2";
gotoxy(46,25);
cout <<"Mark3";
gotoxy(56,25);
cout <<"Total";
int r = 30;
for(i=0;i<n;i++)
{
gotoxy(6,r);
cout <<st[i].name;
gotoxy(16,r);
cout <<st[i].roll;
gotoxy(26,r);
cout <<st[i].mark1;
gotoxy(36,r);
cout <<st[i].mark2;
gotoxy(46,r);
cout <<st[i].mark3;
gotoxy(56,r);
cout <<st[i].total;
r++;
}
break;
case 3:
int troll;
cout << "\nEnter the roll number to be searched ";
cin >> troll;
for(i=0;i<n;i++)
{
if (st[i].roll == troll)
{
cout << " \n Name "<<st[i].name;
cout << "\n Roll "<< st[i].roll;
cout << "\n Mark1 "<<st[i].mark1;
cout << "\n Mark2 "<<st[i].mark2;
cout << "\n Mark3 "<<st[i].mark3;
cout << "\n total "<<st[i].total;
PREPARED BY ARVIND MISHRA (XII S)
25
}
}
break;
case 4:
exit(0);
}
cout << "\n Do U want to continue";
cin>>choice;
}while(choice == 'Y' ||choice =='y');
}
/* output
1. For enter
2. For tabular report
3. For Report card
4. For exit1
Enter how many students 2
Enter name pankaj
Enter Roll Number 16
Enter Mark1 70
Enter Mark2 80
Enter Mark3 90
Enter name nikhil
Enter Roll Number 49
Enter Mark1 90
Enter Mark2 80
Enter Mark3 33
Do U want to continuey
1. For enter
2. For tabular report
3. For Report card
4. For exit2
Name
Roll
Mark1
nikhil
49
90
pankaj 16
70
Do U want to continuey
1. For enter
2. For tabular report
3. For Report card
4. For exit3
Mark2 Mark3
80
90
80
90
Total
203
240
26
27
28
case '2':
cout<<"\nThe Array is Now Sorted";
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
break;
case '3':
cout<<"\nThe element to be searched";
int el;
cin>>el;
int first=0,last=n-1,mid=0,flag=0;
while(first<=last&&flag==0)
{
mid=(first+last)/2;
if(a[mid]==el)
{
flag=mid;
}
else if(a[mid]<el)
{
first=mid+1;
}
else
{
last=mid-1;
}
}
if(flag>0)
cout<<"\nThe Element is Found at: "<<+
+flag<<" in the sorted array";
else
cout<<"\n No such Element";
break;
PREPARED BY ARVIND MISHRA (XII S)
case '4':
cout<<"\n";
for(i=0;i<n;i++)
cout<<a[i]<<ends;
}
}while(ch!='5');
}
/* OUTPUT
1.Enter Array
2.Sort Array
3.Search
4.Display
5.Exit1
Enter no. of Elements (<=20): 5
10 20 5 4 30
1.Enter Array
2.Sort Array
3.Search
4.Display
5.Exit4
10
1.Enter Array
2.Sort Array
3.Search
4.Display
5.Exit2
The Array is Now Sorted
1.Enter Array
2.Sort Array
3.Search
4.Display
5.Exit4
4
1.Enter Array
2.Sort Array
PREPARED BY ARVIND MISHRA (XII S)
29
30
3.Search
4.Display
5.Exit3
The element to be searched10
The Element is Found at: 3 in the sorted array
1.Enter Array
2.Sort Array
3.Search
4.Display
5.Exit5
*/
31
void display()
{
cout<<"\n"<<name<<"\t"<<rollno<<"\t"<<marks<<"\t";
if(marks>=96)
cout<<"computer sc.";
else if(marks>=91&&marks<=95)
cout<<"Electronics";
else if(marks>=86&&marks<=90)
cout<<"Mechanical";
else if(marks>=81&&marks<=85)
cout<<"Electrical";
else if(marks>=76&&marks<=80)
cout<<"Chemical";
else if(marks>=71&&marks<=75)
cout<<"Civil";
else
cout<<"none";
}
};
void main()
{
clrscr();
student s;
int n,i,j;
fstream ofile,afile;
char ch,ch1;
do
{
cout<<"\n\t1.Add records\n\t2.Show Records\n\t3.Exit";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("st.dat",ios::app|ios::binary);
cout<<"\nEnter no. of records to be Entered: ";
cin>>n;
PREPARED BY ARVIND MISHRA (XII S)
for(i=0;i<n;i++)
{
s.input();
ofile.write((char*)&s,sizeof(student));
}
ofile.close();
break;
case '2' : cout<<"\nName\tRollno\tMarks\tStream";
afile.open("st.dat",ios::in);
while(afile)
{
afile.read((char *)&s,sizeof(student));
if (!afile)
break;
s.display();
}
afile.close();
break;
case '3' : exit(0);
}
}while(1);
getch();
}
/* OUTPUT
1.Add records
2.Show Records
3.Exit1
Enter no. of records to be Entered: 2
Enter Name: PANKAJ
Enter Rollno.: 16
enter marks100
Enter Name: RAM
Enter Rollno.: 22
enter marks80
1.Add records
PREPARED BY ARVIND MISHRA (XII S)
32
2.Show Records
3.Exit2
Name Rollno Marks Stream
PANKAJ 16
100 computer sc.
RAM 22
80
Chemical
1.Add records
2.Show Records
3.Exit3
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<iomanip.h>
class employee
{
int eno;
char name[30];
float salary;
public :
void input()
{
cout << "Enter Employee Number ";
cin >>eno;
cout << "Enter name ";
gets(name);
cout << "Enter salary ";
cin >>salary;
}
void show()
PREPARED BY ARVIND MISHRA (XII S)
33
{
cout << eno <<
setw(20)<<name<<setw(20)<<salary<<endl;
}
float rt_sal()
{
return salary;
}
}emp[10];
main()
{
int n,ch,i,j;
char choice;
do
{
clrscr();
cout << "1. For enter "<<endl;
cout << "2. For tabular report"<<endl;
cout << "3. For exit";
cin >> ch;
switch(ch)
{
case 1:
cout << "Enter how many employees ";
cin >>n;
for(i=0;i<n;i++)
{
emp[i].input();
}
break;
case 2:
employee temp;
for (i=0;i<n;i++)
{
for(j=i;j<n-1;j++)
{
if (emp[j].rt_sal()>emp[j+1].rt_sal())
{
temp = emp[j];
emp[j]=emp[j+1];
PREPARED BY ARVIND MISHRA (XII S)
34
emp[j+1]=temp;
}
}
}
gotoxy(6,6);
cout <<"Employee Number ";
gotoxy(26,6);
cout <<"Name";
gotoxy(46,6);
cout <<"Salary"<<endl;
int r = 8;
for(i=0;i<n;i++)
{
emp[i].show();
r++;
}
break;
case 3:
exit(0);
}
cout << "\n Do U want to continue";
cin>>choice;
}while(choice == 'Y' ||choice =='y');
}
/* output
1. For enter
2. For tabular report
3. For exit2
Employee Number
11
RAM
3
MOHAN
Name
2000
3000
Salary
Do U want to continuen
*/
35
36
37
char tmp[80];
afile.open("smp.txt",ios::in);
ofile.open("vwl.txt",ios::out);
while(!afile.eof())
{
afile.getline(tmp,80,' ');
if(tmp[0]=='a'||tmp[0]=='e'||tmp[0]=='i'||
tmp[0]=='o'||tmp[0]=='u')
{
ofile<<tmp;
ofile<<' ';
}
}
afile.close();
ofile.close();
break;
case '2' : cout<<"\nFormatted text:\t";
afile.open("vwl.txt",ios::in);
while(afile)
{
afile.get(ch);
cout<<ch;
}
afile.close();
break;
case '3' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
/* output
1.Enter Text
2.Show Text
3.Exit1
Enter The Text pankaj
PREPARED BY ARVIND MISHRA (XII S)
DO U want to continue y
1.Enter Text
2.Show Text
3.Exit2
Formatted text:
DO U want to continue y
1.Enter Text
2.Show Text
3.Exit1
Enter The Text arun
DO U want to continue y
1.Enter Text
2.Show Text
3.Exit2
Formatted text: arun
DO U want to continue n
*/
38
39
break;
case '2' :
char tmp1;
int v=0,d=0,w=0;
afile.open("smp.txt",ios::in);
while(!afile.eof())
{
afile.get(tmp1);
if(tmp1=='a'||tmp1=='e'||tmp1=='i'||
tmp1=='o'||tmp1=='u')
{
v++;
}
if(isdigit(tmp1))
{
d++;
}
if(tmp1==' '||tmp1=='.')
{
w++;
}
}
afile.close();
cout<<"\n No of Vowels: "<<v;
cout<<"\n No of digits: "<<d;
cout<<"\n No of words: "<<w;
break;
case '3' :
char tmp2;
afile.open("smp.txt",ios::in);
ofile.open("spl.txt",ios::out);
while(!afile.eof())
{
afile.get(tmp2);
if(tmp2==' ')
{
PREPARED BY ARVIND MISHRA (XII S)
40
ofile<<'#';
}
else
{
ofile<<tmp2;
}
}
afile.close();
ofile.close();
cout<<"\nFormatted text:\t";
afile.open("spl.txt",ios::in);
while(afile)
{
afile.get(ch);
cout<<ch;
}
afile.close();
break;
case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
/* output
3.Show Text
4.Exit1
Enter The Text my name is pankaj
DO U want to continue y
1.Create Text
2.Count vowels/words/digits
3.Show Text
4.Exit2
No of Vowels: 5
No of digits: 0
No of words: 3
DO U want to continue y
PREPARED BY ARVIND MISHRA (XII S)
41
42
1.Create Text
2.Count vowels/words/digits
3.Show Text
4.Exit3
Formatted text: my#name#is#pankaj
DO U want to continue n
*/
43
ofile.close();
break;
case '2' :
char tmp1;
afile.open("smp.txt",ios::in);
while(!afile.eof())
{
afile.get(tmp1);
if(isalpha(tmp1))
{
if (islower(tmp1))
{
if (tmp1=='a'||tmp1=='e'||tmp1=='i'||
tmp1=='o'||tmp1=='u')
cout << "\n Lower case vowel "<<tmp1;
else
cout<<"\n Lower case consonants
"<<tmp1;
}
if (isupper(tmp1))
{
if (tmp1=='A'||tmp1=='E'||tmp1=='I'||
tmp1=='O'||tmp1=='U')
cout << "\n Upper case vowel "<<tmp1;
else
cout<<"\n Lower case consonants
"<<tmp1;
}
}
}
afile.close();
break;
case '3' : ofile.open("smp.txt",ios::in);
afile.open("smp1.txt",ios::out);
char c;
while(ofile)
{
ofile.get(c);
c = tolower(c);
PREPARED BY ARVIND MISHRA (XII S)
44
if (c=='a'||c=='i'||c=='e'||c=='o'||c=='u')
afile.put(c);
}
ofile.close();
afile.close();
case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
/* OUPUT
1.Create Text
2.Read from File
3.create another file
4.Exit 1
Enter The Text INDIA
DO U want to continue Y
1.Create Text
2.Read from File
3.create another file
4.Exit 2
Upper case vowel I
Lower case consonants N
Lower case consonants D
Upper case vowel I
Upper case vowel A
DO U want to continue N
*/
45
double rt_tno()
{
return tno;
}
}tele;
// Function to append the records in file
void append()
{
ofstream tfile;
telephone tele;
tfile.open("tele.dat", ios :: app);
int n,i;
cout<< "Enter how many customers ";
cin>>n;
for (i =0; i<n ;i++)
{
tele.input();
tfile.write((char *)& tele,sizeof(tele));
}
tfile.close();
}
// Function to search a record in the file
void display()
{
ifstream tfile;
tfile.open("tele.dat",ios :: binary);
int no,flag;
flag = 0;
cout<< "\n Enter telephone number to be searched ";
cin>>no;
while(tfile)
{
tfile.read((char *)&tele , sizeof(tele));
if(!tfile)
break;
if (tele.rt_tno() == no)
{
tele.show();
flag = 1;
PREPARED BY ARVIND MISHRA (XII S)
46
}
}
if (flag == 0)
cout<< "\n Record does not exist ";
}
void main()
{
clrscr();
int ch;
cout << " 1. For append record ";
cout <<"\n 2. For search ";
cout << "\n 3. For exit";
cin >> ch;
switch (ch)
{
case 1:
append();
break;
case 2:
display();
break;
case 3 : exit(0);
}
}
/* OUTPUT
1. For append record
2. For search
3. For exit1
Enter how many customers 1
Enter the name MOHAN
Enter address BURARI
Enter the telephone number 555
1. For append record
2. For search
3. For exit2
Enter telephone number to be searched 555
47
48
Name MOHAN
Address BURARI
*/
49
{
return bgroup;
}
};
void main()
{
clrscr();
donor d;
int n,i,j;
fstream ofile,afile;
char ch,ch1;
do
{
cout<<"\n\t1.Add records\n\t2.Search Records\n\t3.List
Records\n\t4.Exit";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("dnr.dat",ios::out|ios::binary);
cout<<"\nEnter no. of records to be Entered: ";
cin>>n;
for(i=0;i<n;i++)
{
d.input();
ofile.write((char*)&d,sizeof(donor));
}
ofile.close();
break;
case '2' : cout<<"\nEnter Blood Group to be searched: ";
char bg[5],flag=0;
gets(bg);
afile.open("dnr.dat",ios::in);
while(afile)
{
afile.read((char *)&d,sizeof(donor));
if(!afile)
PREPARED BY ARVIND MISHRA (XII S)
break;
if (strcmp(bg,d.getbgroup())==0)
{
d.display();
flag=1;
}
}
if(flag==0)
cout<<"\n No record Found";
afile.close();
break;
case '3' :
afile.open("dnr.dat",ios::in);
while(afile)
{
afile.read((char *)&d,sizeof(donor));
if(!afile)
break;
d.display();
}
afile.close();
break;
case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
/* OUTPUT
1.Add records
2.Search Records
3.List Records
4.Exit1
Enter no. of records to be Entered: 1
PREPARED BY ARVIND MISHRA (XII S)
50
Blood Group: B+
1.Add records
2.Search Records
3.List Records
4.Exit2
Enter Blood Group to be searched: B+
Donor Name: PANKAJ Address: SANT NAGAR
DO U want to continue N
Blood Group: B+
*/
51
52
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
class Clothing
{
char Code[15];
char Type[15];
int Size;
char Material[20];
float Price;
public:
// Constructor to assign initial values
Clothing()
{
strcpy(Code, "NOT ASSIGNED");
strcpy(Type, "NOT ASSIGNED");
strcpy(Material, "NOT ASSIGNED");
Size = 0;
Price = 0;
}
// Function to calculate value
void CalPrice()
{
PREPARED BY ARVIND MISHRA (XII S)
53
if (strcmp(Material, "COTTON") ==
0)
{
Price = 1500;
}
else
if (strcmp(Material, "SHIRT") == 0)
{
Price = 1200 * (1200 *
(25/100));
}
}
// Function to input the values
void Enter()
{
cout << "Enter code : ";
gets(Code);
cout << "Enter type : ";
gets(Type);
cout << "Enter size : ";
cin >> Size;
cout << "Enter Material : ";
gets(Material);
CalPrice();
}
// Function to display values
void Show()
{
cout << "Code : ";
puts(Code);
cout << "Type : ";
puts(Type);
cout << "Size : " << Size << endl;
cout << "Material : ";
puts(Material);
cout << "Price : " << Price;
}
};
void main()
{
PREPARED BY ARVIND MISHRA (XII S)
54
clrscr();
Clothing C;
C.Enter();
C.Show();
}
/* OUTPUT
Enter code : 01
Enter type : SHIRT
Enter size : 50
Enter Material : COTTON
Code : 01
Type : SHIRT
Size : 50
Material : COTTON
Price : 1500
*/
55
for(i=0;i<n;i++)
{
s.input();
ofile.write((char*)&s,sizeof(students));
}
ofile.close();
break;
case '2' : cout<<"\nEnter Roll No. to be searched: ";
int sn,flag=0;
cin>>sn;
afile.open("std.dat",ios::in);
while(afile)
{
afile.read((char *)&s,sizeof(students));
if(!afile)
break;
if (sn==s.getsno())
{
s.display();
flag=1;
break;
}
}
if(flag==0)
cout<<"\n No record Found";
afile.close();
break;
case '3' :
cout<<"\nEnter Roll No. to be Deleted ";
int sn1,flag1=0;
cin>>sn1;
afile.open("std.dat",ios::in|ios::binary);
ofile.open("tmpstd.dat",ios::out|ios::binary);
while(afile)
{
afile.read((char *)&s,sizeof(students));
if(!afile)
break;
if (sn1==s.getsno())
{
PREPARED BY ARVIND MISHRA (XII S)
56
57
flag1=1;
}
else
{
ofile.write((char
*)&s,sizeof(students));
}
}
if(flag1==0)
cout<<"\n No record Found";
afile.close();
ofile.close();
afile.open("tmpstd.dat",ios::in|ios::binary);
ofile.open("std.dat",ios::out|ios::binary);
while(afile)
{
afile.read((char *)&s,sizeof(students));
ofile.write((char *)&s,sizeof(students));
}
afile.close();
ofile.close();
break;
case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
/* OUTPUT
Enter Fees: 2500
Enter Student Name: RAM
Enter Roll No.: 30
PREPARED BY ARVIND MISHRA (XII S)
Fees: 3000
Y
1.Add records
2.Search Records
3.Delete Records
4.Exit3
Enter Roll No. to be Deleted 30
DO U want to continue Y
1.Add records
2.Search Records
3.Delete Records
4.Exit2
PREPARED BY ARVIND MISHRA (XII S)
58
59
60
61
62
63
64
65
do
{
cout << "\n\t\t Main Menu";
cout << "\n\t1. Addition of Stack";
cout << "\n\t2. Deletion from Stack";
cout << "\n\t3. Traverse of Stack";
cout << "\n\t4. Exit from Menu";
cout << "\n\nEnter your choice from above ";
cin >> choice;
switch (choice)
{
case 1:
do
{
cout << "Enter the roll no. : ";
cin >> troll;
cout << "Enter age : ";
cin >> tage;
top = push(top, troll, tage);
cout << "\nDo you want to add more
elements <Y/N> ? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 2:
opt = 'Y'; // Initialize for the second loop
do
{
top = pop(top);
if (troll != -1)
cout << "Value deleted from Stack is
" << troll;
cout << "\nDo you want to delete more
elements <Y/N> ? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
PREPARED BY ARVIND MISHRA (XII S)
case 3:
show_Stack(top);
break;
case 4:
exit(0);
}
}
while (choice != 4);
}
// Function body for adds stack elements
node *push(node *top, int val, int tage)
{
node *temp;
temp = new node;
temp->roll = val;
temp->age = tage;
temp->link = NULL;
if(top ==NULL)
top = temp;
else
{
temp->link = top;
top = temp;
}
return(top);
}
// Function body for delete stack elements
node *pop(node *top)
{
node *temp;
int tage, troll;
if (top == NULL )
{
cout << "Stack Empty ";
troll = -1;
}
else
{
temp = top;
PREPARED BY ARVIND MISHRA (XII S)
66
top = top->link;
troll = temp->roll;
tage = temp->age;
temp->link = NULL;
cout << "\n\tPopped Roll Number is : " << temp->roll;
cout << "\n\tPopped Age is : " << temp->age;
delete temp;
}
return (top);
}
// Function body for show stack elements
void show_Stack(node *top)
{
node *temp;
temp = top;
cout << "The values are \n";
while (temp != NULL)
{
cout << "\n" << temp->roll << "\t" << temp->age;
temp = temp->link;
}
}
/* output
Do you want to add more elements <Y/N> ? y
Enter the roll no. : 12
Enter age : 22
Do you want to add more elements <Y/N> ? n
Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack
4. Exit from Menu
Enter your choice from above 3
The values are
PREPARED BY ARVIND MISHRA (XII S)
67
12
11
10
22
21
20
Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack
4. Exit from Menu
21
20
Main Menu
1. Addition of Stack
2. Deletion from Stack
3. Traverse of Stack
4. Exit from Menu
68
69
70
switch (choice)
{
case 1:
do
{
cout << "Enter the value to be added in the stack
";
cin >> val;
push(stack, val, top);
cout << "\nDo you want to add more elements
<Y/N> ? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 2:
opt = 'Y'; // Initialize for the second loop
do
{
val = pop(stack, top);
if (val != -1)
cout << "Value deleted from statck is " << val;
cout << "\nDo you want to delete more elements
<Y/N> ? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 3:
show_Stack(stack, top);
break;
case 4:
exit(0);
}
}
while (choice != 4);
}
// Function body for add stack with array
void push(int stack[], int val, int &top)
{
if (top == MAX - 1)
{
PREPARED BY ARVIND MISHRA (XII S)
71
72
73
int choice;
char val;
char opt = 'Y';
74
case
rear = -1;
front = -1;
// Initialization of Queue
do
{
cout << "\n\t\t Main Menu";
cout << "\n\t1. Addition of Queue";
cout << "\n\t2. Deletion from Queue";
cout << "\n\t3. Traverse of Queue";
cout << "\n\t4. Exit from Menu";
cout << "\n\nEnter Your choice from above ";
cin >> choice;
switch (choice)
{
case 1:
do
{
cout << "Enter the value to be
added in the queue ";
cin >> val;
add_Q(queue, front, val, rear);
cout << "Do you want to add
more element <Y/N>? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 2:
opt = 'Y'; // Initialize for the
second loop
do
{
val = del_Q(queue, front,
rear);
if (val != -1)
cout << "Value deleted
from Queue is " << val;
PREPARED BY ARVIND MISHRA (XII S)
75
value = queue[front];
}
return (value);
}
// Function body to show circular queue with array
void show_Q(char queue[], int front, int rear)
{
cout << "The values are ";
do
{
front = (front + 1) % MAX;
cout << "\n" << queue[front];
}while(front != rear);
}
/*
OUTPUT
Enter the value to be added in the queue 1
Do you want to add more element <Y/N>? y
Enter the value to be added in the queue 2
Do you want to add more element <Y/N>? y
Enter the value to be added in the queue 3
Do you want to add more element <Y/N>? y
Enter the value to be added in the queue 4
Do you want to add more element <Y/N>? n
Main Menu
1. Addition of Queue
2. Deletion from Queue
3. Traverse of Queue
4. Exit from Menu
Enter Your choice from above 3
The values are
1
2
3
4
Main Menu
PREPARED BY ARVIND MISHRA (XII S)
76
1. Addition of Queue
2. Deletion from Queue
3. Traverse of Queue
4. Exit from Menu
Enter Your choice from above 2
Value deleted from Queue is 1
Do you want to delete more element <Y/N>? n
Main Menu
1. Addition of Queue
2. Deletion from Queue
3. Traverse of Queue
4. Exit from Menu
Enter Your choice from above 3
The values are
2
3
4
Main Menu
1. Addition of Queue
2. Deletion from Queue
3. Traverse of Queue
4. Exit from Menu
Enter Your choice from above 4
*/
77
78
79
/*************************SQL*************/
---------------------------------------------------------------------------------------------------------------------//CREATION OF TABLE EMPLOYEE;
/* EMP_CODE AS NUMBER
EMP_NAME AS CHARACTER
DESIG AS CHARACTER
HEAD AS NUMBER
DOJ(DATE OF JOINING) AS CHARACTER
BASIC AS NUMBER
DEPT_CODE AS NUMBER
*/
SQL> create table employee
2 (
3 EMP_CODE NUMBER(4) PRIMARY KEY,
4 EMP_NAME VARCHAR(25) NOT NULL,
5 DESIG VARCHAR(25) NOT NULL,
6 HEAD NUMBER(4),
7 DOJ DATE NOT NULL,
8 BASIC NUMBER(6,2) DEFAULT 0,
9 DEPT_CODE NUMBER(2) REFERENCES
DEPARTMENT(DEPT_CODE)
10 );
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
80
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
81
//DESCRIBE EMPLOYEE;
Name
Null? Type
------------------------------- -------- ---EMP_CODE
NOT NULL NUMBER(38)
EMP_NAME
VARCHAR2(25)
DESIGN
CHAR(20)
HEAD
NUMBER(38)
DOJ
DATE
BASIC
NUMBER(38)
DEPT_CODE
NUMBER(38)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//DESCRIBE DEPARTMENT;
Name
Null? Type
PREPARED BY ARVIND MISHRA (XII S)
82
108
2250
109
2500
110
4000
joy iyer
83
assistant
105
09-DEC-92
30
imran khan
steno
105
17-NOV-91
107
12-JAN-93
30
tinu anand
as. engineer
10
10 rows selected.
---------------------------------------------------------------------------------------------------------------------Content of table department
SQL> select * from department;
DEPT_CODE DEPT_NAME
--------- -------------------- --------10 accounts
20 research
30 sales
40 operation
FLOOR NUMBER
1
2
3
4
--------------------------------------------------------------------------------------------------------------------------
//
QUERIES
84
1
2
3
4
85
86
87
88
Query 12. list name of employee who joined the company before
their respective head did.
Ans: select distinct( e.emp_name) from employee e, employee h
where e.emp_code=h.head and e.doj<h.doj;
EMP_NAME
------------------------raju
ramaswamy
suraj patel
89
90
Query 15: list the name of the employee who are earning the
lowest salary in each department
Ans : select emp_name from employee where basic in(select min(basic) from
employee group by desig);
EMP_NAME
------------------------JOY IYER
BINAY KUMAR
RAJ
IMRAN KHAN
TINU ANAND
RAMASWAMY
SURAJ PATEL
RAJU
Query 16: list the salary of employee with employee code 102 by
500
Ans: select basic+500 from employee where emp_code=102;
BASIC+500
--------2500
Query 17: list the name of those employee who do not head any
one but still get highest salary in department;
Ans : SQL> select emp_name from employee where basic=(select
max(basic) from employee where emp_code in (s
elect emp_code from employee where emp_code not in head));
EMP_NAME
------------------------RAJIV KUMAR
91
Query 18: ;list the name of the employees who are earning more
than the lowest salary of an employee in department 30.
Ans : select emp_name from employee where dept_code=30 and basic >
(select min(basic) from employee where dept_code=30);
EMP_NAME
------------------------AMAR ROY
SURAJ PATEL
BINAY KUMAR
IMRAN KHAN
92
salesman
105
01-MAY-91
engineer
101
09-JAN-91
assistant
105
09-DEC-92
steno
105
17-NOV-91
as. engineer
107
12-JAN-93
THE END