0% found this document useful (0 votes)
32 views

Program File

Uploaded by

Harsh Srivastava
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Program File

Uploaded by

Harsh Srivastava
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 68

PRACTICAL 1

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void findlength()
{
char str[30];
int l=0;
cout<<"\n Enter the string (size<=30) ";
gets(str);
while(str[l]!='\0')
{
l++;
}
cout<<"\n Length Of the given String is: "<<l<<endl;
}
void compare()
{
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++;
}
if(l2!=l1)
{
cout<<"\n Strings are not Equal ";
}
else
{
for(i=0;i<l1;i++)
{
if(str1[i]!=str2[i])
{
flag=1;
break;
}
}

1
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++;
}
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";

2
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();
}

3
4
PRACTICAL 2

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<iomanip.h>
void main()
{
clrscr();
char a[][30]={ "COUNTRY",
"India",
"China",
"Mongila",
"Australia",
"Russia",
"Saudi Arabia",
"Mayanmar",
"Kazakhstan",
"Japan",
"United Kingdom",
"Brazil",
"New Zealand",
"United Sates Of America",
"Switzland",
"Denmark",
"Iceland",
}
,b[][30]={ "CAPITAL",
"Delhi",
"Bejing",
"Ulan Bator",
"Canberra",
"Moscow",
"Riyadh",
"Naypidaw",
"Astana",
"Tokyo",
"London",
"Brasilia",
"Wellington",
"Washington D.C.",
"Bern",
"Copenhagen",
"Reykjavik",
},c[20],d;
cout<<"Enter Your Desiered Option";

5
cout<<"\nEnter 1. For Capital Of Given Country";
cout<<"\nEnter 2. For tabular form of country and
capital\n";
cin>>d;
switch(d)
{
case '1':clrscr();
cout<<"Enter your country\n";
gets(c);
for(int i=1;a[i][1]!='\0';++i)
{
if(strcmpi(c,a[i])==0)
{
cout<<"the capital
is\n"<<b[i];
break;
}
}
break;
case '2':clrscr();
cout<<"The tabular form\n";
for(i=0;i<17;++i)
{

cout<<setw(30)<<a[i]<<"\t|\t"<<b[i]<<endl;
}
break;
default:clrscr();cout<<"wrong input";
}
getch();
}

6
7
PRACTICAL 3

#include<iostream.h>

#include<conio.h>

void twodigit(int a[10][10],int m,int n)


{
int i,j,flag=0;
cout<<"The Two digit Numbers are: ";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
if(a[i][j]>=10&&a[i][j]<=99)
{
cout<<a[i][j]<<ends;
flag=1;
}

}
if(flag==0)
cout<<"None";
}
void main()
{
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();
}

8
9
PRACTICAL 4

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

class report_card
{
public : char name[30];
int roll;
float m1,m2,m3,total,perc;
void getdata()
{ clrscr();
cout<<"Enter The Name Of Student\n";
gets(name);
cout<<"Enter Roll No.\n";
cin>>roll;
cout<<"Enter Marks In First Subject (Out Of
100)\n";
cin>>m1;
cout<<"Enter Marks In Second Subject (Out Of
100)\n";
cin>>m2;
cout<<"Enter Marks In Third Subject (Out Of
100)\n";
cin>>m3;
total=m1+m2+m3;
perc=total/3.0;
}
void showdata()
{ clrscr();
cout<<"Name\t : "<<name<<endl;
cout<<"Roll No\t :"<<roll<<endl;
cout<<"Marks :"<<endl;
cout<<"\t1.First Subject (Out Of
100)\t"<<m1<<endl;
cout<<"\t2.Second Subject (Out Of
100)\t"<<m2<<endl;
cout<<"\t3.Third Subject (Out Of
100)\t"<<m3<<endl;
cout<<"\nTotal Marks(Out Of 300) :
\t"<<total<<"/"<<"300"<<endl;
cout<<"\nPercentage In 3 Subjects :
\t"<<perc<<"%";
}
};
void main()

10
{ clrscr();
int n=4,m;
report_card s[4];
for(int i=0;i<3;++i)
{
s[i].getdata();
}
clrscr();
cout<<"Enter Student Number Whose Result You Want (1-3)\n";
cin>>m;
s[m-1].showdata();
getch();
}

11
12
PRACTICAL 6

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[20],n,i,j,temp;
char ch;

do
{
cout<<"\n\t1.Enter Array\n\t2.Sort
Array\n\t3.Search\n\t4.Display\n\t5.Exit";
cin>>ch;
switch(ch)
{
case '1':
cout<<"\nEnter no. of Elements (<=20):
";
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
break;
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;

13
}
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;
case '4':
cout<<"\n";
for(i=0;i<n;i++)
cout<<a[i]<<ends;

}while(ch!='5');
}

14
15
PRACTICAL 7

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<ctype.h>
class student
{
char name[30];
int rollno;
int marks;

16
public:
void input()
{
cout<<"\nEnter Name: ";
gets(name);
cout<<"Enter Rollno.: ";
cin>>rollno;
cout<<"enter marks";
cin>>marks;
}
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\n";
cout<<"Enter your choice: ";
cin>>ch;
switch(ch)

17
{
case '1' :
ofile.open("st.dat",ios::app|
ios::binary);
cout<<"\nEnter no. of records to be
Entered: ";
cin>>n;
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);
}
cout<<"\n\t DO U want to continue <Y/N>: ";
cin>>ch1;
}while(tolower(ch1)!='n');
getch();
}

18
PRACTICAL 8

#include<iostream.h>

19
#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()
{
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();

20
}

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];
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');
}

21
22
PRACTICAL 9

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int n,j;
fstream ofile,afile;
char str[100];
char ch,ch1;

do
{
cout<<"\n\t1.Enter Text\n\t2.Show Text\n\t3.Exit";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("smp.txt",ios::out);
cout<<"\nEnter The Text ";
gets(str);
ofile<<str;
ofile.close();
char tmp[20];
afile.open("smp.txt",ios::in);
ofile.open("vwl.txt",ios::out);
while(!afile.eof())
{
afile.getline(tmp,20,' ');
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)
{

23
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();\}

PRACTICLAL 10

24
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void main()
{
clrscr();
int n,j;
fstream ofile,afile;
char str[100];
char ch,ch1;

do
{
cout<<"\n\t1.Create Text\n\t2.Count
vowels/words/digits\n\t3.Show Text\n\t4.Exit";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("smp.txt",ios::out);
cout<<"\n Enter The Text ";
gets(str);
ofile<<str;
ofile.close();
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;

25
cout<<"\n No of digits: "<<d+1;
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==' ')
{
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();
}

26
27
PRACTICAL 11

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void main()
{
clrscr();
int n,j;
fstream ofile,afile;
char str[100];
char ch,ch1;
do
{
cout<<"\n\t1.Create Text\n\t2.Read from
File\n\t3.create another file";
cout << "\n 4.Exit ";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("smp.txt",ios::out);
cout<<"\n Enter The Text ";
gets(str);
ofile<<str;
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;
}

28
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);
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();
}

29
PRACTICAL 12

30
# include <fstream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
class telephone
{
char name[30];
char address[50];
double tno;
public :
void input()
{
cout<<"\n Enter the name ";
gets(name);
cout << "\n Enter address ";
gets(address);
cout<<"\n Enter the telephone number ";
cin>>tno;
}
void show()
{
cout << "\n Name "<<name;
cout << "\n Address "<<address;
}
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));
}

31
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;
}
}
if (flag == 0)
cout<< "\n Record does not exist ";
}
void main()
{
clrscr();
int ch;
char ch1;
do
{
cout << "1. For append record ";
cout <<"\n2. For search ";
cout << "\n3. For exit";
cout<<"Enter your choice: ";
cin >> ch;
switch (ch)
{
case 1: append();
break;
case 2: display();
break;
case 3 : exit(0);
}
cout<<"\n\t DO U want to continue <Y/N>: ";
cin>>ch1;

32
}while(tolower(ch1)!='n');}

PRACTICAL 13

33
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
class donor
{
char name[30];
char address[30];
char bgroup[5];
public:
void input()
{
cout<<"\nEnter Donor Name: ";
gets(name);
cout<<"Enter Address: ";
gets(address);
cout<<"Enter Blood Group: ";
gets(bgroup);
}
void display()
{
cout<<"\nDonor Name: "<<name<<"\tAddress:
"<<address<<"\tBlood Group: "<<bgroup<<"\t";

}
char *getbgroup()
{
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)

34
{
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)
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();
}

35
afile.close();
break;

case '4' : exit(0);


}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}

36
37
38
PRACTICAL 14
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
class book
{
char bname[30];
int bno;
float price;
public:
void input()
{
cout<<"\nEnter Book Name: ";
gets(bname);
cout<<"Enter BOOK No.: ";
cin>>bno;
cout<<"Enter Price";
cin>>price;
}
void setprice()
{
cout<<"\nEnter Price";
cin>>price;
}
void display()
{
cout<<"\nBook Name: "<<bname<<"\tBook No.:
"<<bno<<"\tPrice: "<<price<<"\t";

}
int getbno()
{
return bno;
}

};
void main()
{
clrscr();
book b;
int n,i,j;
fstream ofile,afile;

char ch,ch1;

39
do
{
cout<<"\n\t1.Add records\n\t2.Search
Records\n\t3.Modify Records\n\t4.Exit";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("bk.dat",ios::out|
ios::binary);
cout<<"\nEnter no. of records to be
Entered: ";
cin>>n;
for(i=0;i<n;i++)
{
b.input();

ofile.write((char*)&b,sizeof(book));
}
ofile.close();
break;
case '2' : cout<<"\nEnter Book No. to be
searched: ";
int bn,flag=0;
cin>>bn;
afile.open("bk.dat",ios::in);
while(afile)
{
afile.read((char
*)&b,sizeof(book));
if(!afile)
break;
if (bn==b.getbno())
{
b.display();
flag=1;
break;
}
}
if(flag==0)
cout<<"\n No record Found";
afile.close();
break;
case '3' :
cout<<"\nEnter Book No. to be modified
";
int bn1,flag1=0,r=0;

40
cin>>bn1;
afile.open("bk.dat",ios::in|ios::out|
ios::binary);
while(afile)
{
afile.read((char
*)&b,sizeof(book));
if(!afile)
break;
if (bn1==b.getbno())
{
b.setprice();

afile.seekp(r*sizeof(b),ios::beg);
afile.write((char
*)&b,sizeof(book));
flag1=1;
break;
}
r++;
}
if(flag1==0)
cout<<"\n No record Found";
afile.close();
break;

case '4' : exit(0);


}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}

41
42
PRACTICAL 16
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
class Sports{
char sname[30];
int sno;
float fees;
public:
void input()
{
cout<<"\nEnter sports Name: ";
gets(sname);
cout<<"Enter sports No.: ";
cin>>sno;
cout<<"Enter Fees: ";
cin>>fees;
}
void display()
{
cout<<"\nSports Name: "<<sname<<"\tSports No.:
"<<sno<<"\tFees: "<<fees<<"\t";

}
int getsno()
{
return sno;
}

};
void main()
{
clrscr();
Sports s;
int n,i,j;
fstream ofile,afile;

char ch,ch1;

do
{
cout<<"\n\t1.Add records\n\t2.Search
Records\n\t3.Delete Records\n\t4.Exit\n";
cout << "Enter your choice... ";
cin>>ch;

43
switch(ch)
{
case '1' :
ofile.open("Sport.dat",ios::out|
ios::binary);
cout<<"\nEnter no. of records to be
Entered: ";
cin>>n;
for(i=0;i<n;i++)
{
s.input();

ofile.write((char*)&s,sizeof(Sports));
}
ofile.close();
break;
case '2' : cout<<"\nEnter Sports No. to be
searched: ";
int sn,flag=0;
cin>>sn;
afile.open("Sport.dat",ios::in);
while(afile)
{
afile.read((char
*)&s,sizeof(Sports));
if(!afile)
break;
cout << s.getsno();
if (sn==s.getsno())
{
s.display();
flag=1;
break;
}
}
if(flag==0)
cout<<"\n No record Found";
afile.close();
break;
case '3' :
cout<<"\nEnter Sports No. to be Deleted
";
int sn1,flag1=0;
cin>>sn1;
afile.open("Sport.dat",ios::in|
ios::binary);

44
ofile.open("TSport.dat",ios::out|
ios::binary);
while(afile)
{
afile.read((char
*)&s,sizeof(Sports));
if(!afile)
break;
if (sn1==s.getsno())
{
flag1=1;
}
else
{
ofile.write((char
*)&s,sizeof(Sports));
}

}
if(flag1==0)
cout<<"\n No record Found";
afile.close();
ofile.close();

afile.open("TSport.dat",ios::in|
ios::binary);
ofile.open("Sport.dat",ios::out|
ios::binary);
while(afile)
{
afile.read((char
*)&s,sizeof(Sports));
ofile.write((char
*)&s,sizeof(Sports));

}
afile.close();
ofile.close();

break;

case '4' : exit(0);


}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');

45
getch();
}

46
PRACTICAL 17
// This program illustrates the basic operation of
add queue, delete queue and show queue
// using linked list.
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
// Declares a queue structure
struct node
{
int Eno;
float Salary;
node *link;
};
// Functions prototype to add queue, delete queue,
and show queue
node *add_Q(node *rear, int val,float val1); // Add
queue
node *del_Q(node *front, int &val, float &val1);//
Delete queue
void show_Q(node *front); // Show queue
// Main programming logic
void main()
{
node *front, *rear;
int val;
float val1;
int choice;
char opt = 'Y'; // To continue the do loop
in case
front = rear = NULL; // Initialization of
Queue
clrscr();
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)
{

47
case 1:
do
{
cout << "Enter the
value to be added in the queue ";
cin >> val;
cin >> val1;
rear = add_Q(rear,
val,val1);
if (front == NULL)
front = rear;
cout << "\nDo 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
{
front = del_Q(front,
val, val1);
if (front == NULL)
rear = front;
if (val != -1)
cout << "Value
deleted from Queue is " << val;
cout << "\nDo you
want to delete more element <Y/N>? ";
cin >> opt;
} while (toupper(opt) ==
'Y');
break;
case 3:
show_Q(front);
break;
case 4:
exit(0);
}
}
while (choice != 4);
}
// Function body to add queue elements
node *add_Q(node *rear, int val, float val1)
{

48
node *temp;
temp = new node;
temp->Eno = val;
temp->Salary = val1;
temp->link = NULL;
rear->link = temp;
rear = temp;
return (rear);
}
// Function body to delete queue elements
node *del_Q(node *front, int &val, float &val1)
{
node *temp;
clrscr();
if (front == NULL)
{
cout << "Queue Empty ";
val = -1;
}
else
{
temp = front;
front = front->link;
val = temp->Eno;
val1 = temp->Salary;
temp->link = NULL;
delete temp;
}
return (front);
}
// Function body to show queue elements
void show_Q(node *front)
{
node *temp;
temp = front;
clrscr();
cout << "The Queue values are";
while (temp != NULL)
{
cout <<"\nENO : "<< temp->Eno;
cout <<"\nSalary : "<<temp->Salary;
temp = temp->link;
}
}

49
50
51
PRACTICAL 18
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
// Declares a stack structure
struct node
{
int roll;
int age;
node *link;
};
// Function prototype declaration for add stack, delete stack,
and show stack
node *push(node *top, int val, int tage); // Add stack
node *pop(node *top); // Delete stack
void show_Stack(node *top); // Show stack
// Main programming logic
void main()
{
node *top;
int troll, tage, choice;
char opt = 'Y'; // To continue the do loop in
case
top = NULL; // Initialization of Stack
clrscr();
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);

52
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;
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)

53
{
node *temp;
int tage, troll;
clrscr();
if (top == NULL )
{
cout << "Stack Empty ";
troll = -1;
}
else
{
temp = top;
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;
clrscr();
cout << "The values are \n";
while (temp != NULL)
{
cout << "\n" << temp->roll << "\t" << temp->age;
temp = temp->link;
}
}

54
55
56
PRACTICAL 19
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX 100 // Shows maximum array length
int stack[MAX]; // Declares array global variable
int top; // Declares integer top
// Function prototypes of add stack, delete stack, and
// show stack in array implementation
void push(int stack[], int val, int &top); // Add stack
int pop(int stack[], int &top); // Delete stack
void show_Stack(int stack[], int top); // Show stack
void main()
{
int choice, val;
char opt = 'Y'; // To continue the do loop in
case
top = -1; // Initialization of Queue
clrscr();
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 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

57
{
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)
{
cout << "Stack Full ";
}
else
{
top = top + 1;
stack[top] = val;
}
}
// Function body for delete stack with array
int pop(int stack[], int &top)
{
int value;
if (top < 0)
{
cout << "Stack Empty ";
value = -1;
}
else
{
value = stack[top];
top = top - 1;
}
return (value);

58
}
// Function body for show stack with array
void show_Stack(int stack[], int top)
{
int i;
if (top < 0)
{
cout << "Stack Empty";
return;
}
i = top;
clrscr();
cout << "The values are ";
do
{
cout << "\n" << stack[i];
i = i - 1;
}while(i >= 0);
}

59
60
61
62
SQL STATEMENTS

63
64
65
66
67
68

You might also like