Vous êtes sur la page 1sur 31

XII RECORD PROGRAMS 2011-2012

PROGRAM 1:
#include<iostream.h>
#include<conio.h>
void MIX()
{
int la,lb,lc,k=0;
int a[10];
int b[10];
cout<<"\nEnter the limit for Array A?\n"<<endl;
cin>>la;
cout<<"\nEnter the limit for Array B?\n"<<endl;
cin>>lb;
lc=la+lb;
int j = (lc-1);
int c[20];
cout<<"\nEnter the Values for Array A:\n"<<endl;
for(int i=0;i<la;i++)
cin>>a[i];
cout<<"\nEnter the Values for Array B:\n"<<endl;
for(i=0;i<lb;i++)
cin>>b[i];
cout<<"\nThe Values for Array C is:\n\n"<<endl;
for(i=0;i<la;i++)
{
if(a[i]%2==0)
{
c[k]=a[i];
k++;
}
else
{
c[j]=a[i];
j--;
}
}
for(i=0;i<lb;i++)
{
if(b[i]%2==0)
{
c[k]=b[i];
k++;
}
else
{

c[j]=b[i];
j--;
}
}
for(i=0;i<lc;i++)
cout<<c[i]<<"\t";
}
void main()
{
clrscr();
MIX();
getch();
}

PROGRAM 2:
#include<iostream.h>
#include<conio.h>
void MERGE(int a[20],int b[20],int c[40],int m,int n)
{
int k=0,i=m-1,j=n-1;
cout<<endl;
while(i>=0 && j>=0)
{
if(a[i]>=b[j])
c[k++]=a[i--];
else
c[k++]=b[j--];
}
if(i==0 )
{
for(int r=j;r>=0;r--)
c[k++]=b[r];
}
else
{
for(int r=i;r>=0;r--)
c[k++] = a[r];
}
cout<<"\n\nMERGED ARRAY ELEMENTS - DESCENDING ORDER :\n";
for(i=0;i<k;i++)
cout<<c[i]<<endl;

}
void main()
{
clrscr();
int a[20],b[20],c[40],i,m,n,j,t;
cout<<"\n\nENTER SIZE FOR ARRAY A :\t";
cin>>m;
cout<<"\n\nENTER ELEMENTS FOR ARRAY A :\n";
for(i=0;i<m;i++)
cin>>a[i];
cout<<"\n\nENTER SIZE FOR ARRAY B :\t";
cin>>n;
cout<<"\n\nENTER ELEMENTS FOR ARRAY B :\n";
for(i=0;i<n;i++)
cin>>b[i];
for(i=1;i<m;i++)
{
t=a[i];
for(j=i-1;j>=0 && t<a[j]; j--)
a[j+1]=a[j];
a[j+1]=t;
}
cout<<"\n\nASCENDING ORDER - ARRAY A : ";
for(i=0;i<m;i++)
cout<<a[i]<<" ";
for(i=1;i<n;i++)
{
t=b[i];
for(j=i-1;j>=0 && t<b[j];j--)
b[j+1]=b[j];
b[j+1]=t;
}
cout<<"\n\nASCENDING ORDER - ARRAY B : ";
for(i=0;i<n;i++)
cout<<b[i]<<" ";
MERGE(a,b,c,m,n);
getch();
}
PROGRAM 3:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>

void sort(int p[],int n)


{
int i,j,pos,current;
for(i=1;i<=n-1;i++)
{
current=p[i];
pos=0;
while(pos<i && p[pos]<=current)
pos++;
if(pos!=i)
{
for(j=i-1;j>=pos;j--)
p[j+1]=p[j];
p[pos]=current;
}
}
}
int bsearch(int p[],int n,int data)
{
int low=0,high=n-1,mid;
while(low<=high)
{
mid=(low+high)/2;
if(p[mid]==data)
return (1);
else if(data>p[mid])
low=mid+1;
else
high=mid-1;
}
return 0;
}
void main()
{
clrscr();
int p[10],n,i,t,data;
cout<<"\nEnter the size \t";
cin>>n;
cout<<"\n\nEnter the values:\n";
for(i=0;i<n;i++)
{
cin>>p[i];
cout<<endl;
}
sort(p,n);

cout<<"\n\n\t\tSORTED ELEMENTS IN ASCENDING ORDER"<<endl;


cout<<"\t\t-----------------------------------"<<endl;
for(i=0;i<n;i++)
cout<<"\t\t\t\t"<<p[i]<<"\n\n";
cout<<"\n\nEnter data to be searched:\t";
cin>>data;
t=bsearch(p,n,data);
if(t==0)
cout<<"\n\n\n\t\tNUMBER IS NOT PRESENT!!!";
else
cout<<"\n\n\n\t\tNUMBER IS PRESENT!!!";
getch();
}
PROGRAM 4:
#include<iostream.h>
#include<conio.h>
void accept(int a[10][10],int m,int n)
{
int i,j,sum=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if((i+j)%2!=0)
cout<<" ";
else
{
cout<<a[i][j];
sum=sum+a[i][j];
}
}
cout<<"\tsum:"<<sum<<endl;
sum=0;
}
}
void main()
{
clrscr();
int a[10][10],m,n,i,j;
cout<<"Enter the size of matrix:";
cin>>m>>n;
cout<<"Enter the values:";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
for(i=0;i<m;i++)

{
for(j=0;j<n;j++)
cout<<a[i][j]<<"\t";
cout<<endl;
}
accept(a,m,n);
getch();
}
PROGRAM 5:
#include<iostream.h>
#include<conio.h>
void count_odd_even(int a[10][10],int m,int n)
{
int i,j,e=0,o=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]%2==0)
e++;
else
o++;
}
cout<<"\nEven nos in\t"<<i<<"st Row:"<<e<<endl;
cout<<"\nOdd nos in\t"<<i<<"st Row:"<<o<<endl;
e=0;
o=0;
}
e=0;o=0;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[j][i]%2==0)
e++;
else
o++;
}
cout<<"\nEven nos in\t"<<i<<"st Column:"<<e<<endl;
cout<<"\nOdd nos in\t"<<i<<"st Column:"<<o<<endl;
e=0;
o=0;
}
}
void main()
{

clrscr();
int a[10][10],m,n,i,j;
cout<<"Enter the size of matrix:";
cin>>m>>n;
cout<<"Enter the values:";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<a[i][j]<<"\t";
cout<<endl;
}
count_odd_even(a,m,n);
getch();
}
PROGRAM 6:
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
struct library
{
int bno,no,price;
char title[20],author[20];
}l[100];
void input(int n)
{
cout<<"\n\nEnter details for "<<n<< " records:"<<endl;
for(int i=0;i<n;i++)
{
cout<<"\n\nEnter the book no:"<<endl;
cin>>l[i].bno;
cout<<"\nTitle"<<endl;
gets(l[i].title);
cout<<"\nAuthor"<<endl;
gets(l[i].author);
cout<<"\nNo of copies: "<<endl;
cin>>l[i].no;
cout<<"\nPrice"<<endl;
cin>>l[i].price;
}
}

void display(int n)
{
cout<<"\n\nBook No"<<"\tTitle"<<"\tAuthor"<<"\t No of
copies"<<"\tPrice"<<endl;
cout<<"\n------------------------------------------------------------------"<<endl;
for(int i=0;i<n;i++)
cout<<"\n\n"<<l[i].bno<<"\t"<<l[i].title<<"\t"<<l[i].author<<
"\t\t"<<l[i].no<<"\t" <<l[i].price<<endl;
}
void calc(char eg[20],int n)
{
int flag=0;
for(int i=0;i<n;i++)
if(strcmp(eg,l[i].author)==0)
{
cout<<"\n\n\n\t\tRECORD FOUND!!!\n\n"<<endl;
cout<<"\n\nBook No"<<"\tTitle"<<"\tAuthor"<<"\t No of
copies"<<"\tPrice"<<endl;
cout<<"\n------------------------------------------------------------------"<<endl;
cout<<"\n\n"<<l[i].bno<<"\t"<<l[i].title<<"\t"<<l[i].author<<
"\t\t"<<l[i].no<<"\t" <<l[i].price<<endl;
flag=1;
}
if(flag==0)
cout<<"\n\n\n\t\tRECORD DOES NOT EXIST!!!\n"<<endl;
}
void main()
{
clrscr();
char eg[20];
int n;
cout<<"\n\nEnter the no of records to be stored:\n"<<endl;
cin>>n;
input(n);
display(n);
cout<<"\n\nEnter the author name to be Searched:\n";
gets(eg);
calc(eg,n);
getch();
}
PROGRAM 7:
#include<iostream.h>
#include<conio.h>

struct com
{
int r,i;
}c;
com SUM(com z1,com z2)
{
com z3;
z3.r=z1.r+z2.r;
z3.i=z1.i+z2.i;
return z3;
}
com DIFF(com z1,com z2)
{
com z4;
z4.r=z1.r-z2.r;
z4.i=z1.i-z2.i;
return z4;
}
void main()
{
clrscr();
com z1,z2,z3,z4;
cout<<"\n\nEnter real and imaginary part of complex no. 1:";
cin>>z1.r>>z1.i;
cout<<"\n\nEnter real and imaginary part of complex no. 2:";
cin>>z2.r>>z2.i;
z3=SUM(z1,z2);
cout<<"\n\nThe sum of complex no.s:";
cout<<z3.r<<" "<<z3.i<<"i";
z4=DIFF(z1,z2);
cout<<"\n\nThe difference of complex no.s:";
cout<<z4.r<<" "<<z4.i<<"i";
getch();
}
PROGRAM 8:
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class publisher
{
long id,stockqty;
char title[40];

char author[40];
double price,stockvalue;
double valcal()
{
return(price*stockqty);
}
public:
publisher()
{
stockqty=0;
stockvalue=0.0;
price=0.0;
strcpy(title,"\0");
strcpy(author,"\0");
}
void Enter()
{
cout<<"\n\nEnter ID:\t";
cin>>id;
cout<<"\n\nTitle:\t";
gets(title);
cout<<"\n\nAuhtor:\t";
gets(author);
cout<<"\n\nStock Quantity:\t";
cin>>stockqty;
cout<<"\n\nPrice:\t";
cin>>price;
}
void Takestock(int x)
{
stockqty+=x;
stockvalue=valcal();
}
void Sale(int y)
{
stockqty-=y;
stockvalue=valcal();
}
void Dispstock()
{
cout<<"\n\n\n\t\t\tCUSTOMER DETAILS"<<endl;
cout<<"\n\t\t\t--------------"<<endl;
cout<<"\n\n\nID:\t"<<id<<endl;
cout<<"\n\n\nTITLE:\t"<<title<<endl;
cout<<"\n\n\nAUTHOR:\t"<<author<<endl;
cout<<"\n\n\nPRICE:\t"<<price<<endl;
cout<<"\n\n\nSTOCK QUANTITY:\t"<<stockqty<<endl;
cout<<"\n\n\nSTOCK VALUE:\t"<<stockvalue<<endl;

}
};
void main()
{
clrscr();
publisher p;
int n;
p.Enter();
cout<<"\n\nEnter the additional quantity of stock:\t";
cin>>n;
p.Takestock(n);
p.Sale(n);
clrscr();
p.Dispstock();
getch();
}
PROGRAM 9:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class empsal
{
char name[30];
int age;
long int salary;
int HRA;
int DA;
float PF;
long int gsal,netsal,tax;
public:
void getvalue()
{
cout<<"\n\nNAME:\t";
gets(name);
cout<<"\n\nAGE:\t";
cin>>age;
cout<<"\n\nSALARY:\t";
cin>>salary;
cout<<"\n\nHRA:\t";
cin>>HRA;
cout<<"\n\nDA:\t";
cin>>DA;
cout<<"\n\nPF:\t";
cin>>PF;
}
void compute()

{
gsal=salary+HRA+DA;
if(salary<=10000)
{
tax=.02*gsal;
netsal=gsal-(PF+tax);
}
else if((salary>10000)&&(salary<=50000))
{
tax=.05*gsal;
netsal=gsal-(PF+tax);
}
else if(salary>50000)
{
tax=.1*gsal;
netsal=gsal-(PF+tax);
}
}
void prnresult()
{
cout<<name<<"\t\t"<<age<<"\t\t"<<gsal<<"\t\t\t"<<netsal<<"\n\n";
}
};
void main()
{
clrscr();
int n;
empsal s[20];
cout<<"\n\n\nENTER NUMBER OF EMPLOYEES:\t";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n\n"<<" EMPLOYEE "<<i+1<<" DETAILS:"<<"\n\n";
s[i].getvalue();
s[i].compute();
}
clrscr();
cout<<"\n\n\n\t\t\tEMPLOYEE DETAILS\n";
cout<<"\t\t\t----------------\n\n\n";
cout<<"\n\nNAME\t\tAGE\t\tGROSS SALARY\t\tNET SALARY\n\n";
cout<<"---------------------------------------------------------------------\n\n\n";
for(i=0;i<n;i++)
s[i].prnresult();
getch();
}

PROGRAM 10:
#include <iostream.h>
#include<string.h>
#include <conio.h>
class Travel
{
long travelcode;
char place[30];
char season[30];
float total_fare,discount;
public:
Travel()
{
travelcode=101;
strcpy(place,"Udaipur");
strcpy(season,"General");
total_fare=0;
discount=0;
}
void newtravel()
{
cout<<"Enter travelcode,place,season,totalfare:";
cin>>travelcode>>place>>season>>total_fare;
if(strcmp(season,"Diwali")==0)
{
discount=(10.0/100.0)*total_fare;
total_fare=total_fare-discount;
}
else if(strcmp(season,"Holi")==0)
{
discount=(5.0/100.0)*total_fare;
total_fare=total_fare-discount;
}
else if(strcmp(season,"Christmas")==0)
{
discount=(15.0/100.0)*total_fare;
total_fare=total_fare-discount;
}
else if(strcmp(season,"Summer")==0)
{
discount=(20.0/100.0)*total_fare;
total_fare=total_fare-discount;
}
else
{
discount=0;
total_fare=total_fare-discount;

}
}
void showtravel()
{
cout<<"Travelcode\tPlace\tSeason\tTotalfare\n";
cout<<travelcode<<"\t\t"<<place<<"\t"<<season<<"\t"<<total_fare;
}
};
void main()
{
clrscr();
Travel t;
t.newtravel();
t.showtravel();
getch();
}
PROGRAM 11:
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void main()
{
clrscr();
fstream x;
int li,sp,sc,word,num,dig,alp;
li=sp=sc=word=num=alp=0;
char st[100];
x.open("story.txt",ios::out);
cout<<"\n\nEnter the story to be copied in to the file"<<endl;
cout<<"---------------------------------------------"<<endl;
cout<<"\n(Enter quit to terminate)"<<endl<<endl;
gets(st);
while(strcmp(st,"quit")!=0)
{
x<<st;
gets(st);
if(strcmp(st,"\n"))
x<<"\n";
}
x.close();
cout<<"\n\nReading the contents from the file"<<endl;
cout<<"-------------------------------------\n"<<endl;
x.open("story.txt",ios::in);

while(x.getline(st,100))
{
cout<<st<<endl;
li++;
for(int i=0;i<strlen(st);i++)
{
if(isspace(st[i]))
sp++;
if(isspace(st[i]) || st[i]=='.')
word++;
else if(isalpha(st[i]))
alp++;
else if(isdigit(st[i]))
num++;
else
sc++;
}
}
x.close();
cout<<"\n\n\n Number of lines in the file : "<<li;
cout<<"\n\n\n Number of Spaces in the file : "<<sp;
cout<<"\n\n\n Number of Words in the file : "<<word;
cout<<"\n\n\n Number of Alphabets in the file : "<<alp;
cout<<"\n\n\n Number of Digits in the file : "<<num;
cout<<"\n\n\n Number of Special Characters in the file : "<<sc;
getch();
}
PROGRAM 12:
#include<fstream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
fstream x,y;
char ch[100],c;
x.open("school.txt",ios::out);
cout<<"\n Enter Information abt your school\n"<<endl;
cout<<"\nEnter quit to terminate\n"<<endl;
gets(ch);
while(strcmp(ch,"quit")!=0)
{

x<<ch;
gets(ch);
if(strcmp(ch,"\n"))
x<<"\n";
}
x.close();
x.open("school.txt",ios::in);
cout<<"\n\n\n Reading Information from the file:\n "<<endl;
while(!x.eof())
{
x.getline(ch,100,'.');
cout<<ch;
}
x.close();
cout<<"\n\n Case Conversion\n"<<endl;
cout<<"\n---------------------\n"<<endl;
x.open("school.txt",ios::in);
y.open("newschool.txt",ios::out);
while(!x.eof())
{
x.get(c);
if(isupper(c))
c=tolower(c);
else if(islower(c))
c=toupper(c);
y.put(c);
}
x.close();
y.close();
y.open("newschool.txt",ios::in);
while(!y.eof())
{
y.getline(ch,100,'.');
cout<<ch;
}
getch();
}
PROGRAM 13:
#include<fstream.h>
#include<conio.h>
#include<process.h>
struct player
{
int pcode;
char pna[25],game[15],country[25];
}p;

void read()
{
cout<<endl;
cout<<"\nEnter the following:\n\n";
cout<<"Player code:";
cin>>p.pcode;
cout<<"\nPlayer Name:";
cin>>p.pna;
cout<<"\nGame:";
cin>>p.game;
cout<<"\nCountry:";
cin>>p.country;
}
void disp()
{
cout<<"\n"<<p.pcode<<"\t\t\t"<<p.pna<<"\t\t"<<p.game<<"\t\t"<<p.country<<"\n";
}
void readfile()
{
char ch='y';
fstream x("player.dat",ios::out|ios::binary);
while(ch=='y')
{
read();
x.write((char*)&p,sizeof(p));
cout<<"\nAny more Records?(y/n)\n";
cin>>ch;
}
x.close();
}
void displayfile()
{
fstream x("player.dat",ios::in|ios::binary);
if(!x)
cout<<"\n File Does not Exist"<<endl;
else
{
cout<<"\nDetails in the file are:"<<endl;
cout<<"\nPLAYER CODE \t\t NAME \t\t GAME \t\t
COUNTRY\n"<<endl;
while(x.read((char*)&p,sizeof(p)))
disp();
}
x.close();
}

void modify()
{
int c,i=0,r=0;
fstream x("player.dat",ios::in|ios::out|ios::binary);
if(!x)
cout<<"\nFile does not exist"<<endl;
else
{
cout<<"\n\nEnter the player code to be modified:\n";
cin>>c;
while(x.read((char*)&p,sizeof(p)))
{
r++;
if(p.pcode==c)
{
i++;
cout<<"\n\nEnter the New values:\n";
read();
x.seekg((r-1)*sizeof(p),ios::beg);
x.write((char*)&p,sizeof(p));
}
}
}
x.close();
if(i==0)
cout<<"\nRECORD DOES NOT EXIST";
else
cout<<"\nRECORD IS UPTO DATE";
}
void main()
{
clrscr();
int ch;
do
{
cout<<" \n\t\t\tMENU"<<endl;
cout<<"\n\t\t\t-----"<<endl;
cout<<"\n\n1)Accept\n\n2)Modify\n\n3)Display\n\n4)Exit\n\n";
cout<<"\n\nEnter your choice:\n";
cin>>ch;
switch(ch)
{
case 1:
readfile();
clrscr();
break;
case 2:

modify();
getch();
clrscr();
break;
case 3:
displayfile();
getch();
clrscr();
break;
case 4:
exit(0);
break;
default:
cout<<"Enter correct choice"<<endl;
getch();
clrscr();
break;
}
}while(ch!=4);
getch();
}
PROGRAM 14:
#include<fstream.h>
#include<conio.h>
struct student
{
char na[20],sec;
int e,m,p,c,cs,tot,std;
float avg;
};
void create()
{
fstream x("student.dat",ios::out|ios::binary);
student s;
char ch='y';
while(ch=='y')
{
cout<<"Enter name,std,sec,5 sub marks:\n";
cin>>s.na>>s.std>>s.sec>>s.e>>s.p>>s.m>>s.c>>s.cs;
s.tot=s.e+s.m+s.p+s.c+s.cs;
s.avg=s.tot/5;
x.write((char*)&s,sizeof(s));
cout<<"Any more records?(y/n)\n";
cin>>ch;
}

x.close();
}
void display()
{
fstream x("student.dat",ios::in|ios::binary);
student s;
clrscr();
cout<<"\n\n\n\n\n"<<"\t\t\t\tSTUDENT DETAILS\n\n"<<endl;
for(int i=0;i<80;i++)
cout<<"-";
cout<<"Name\tStd\tSec\tMark1\tMark2\tMark3\tMark4\tMark5\tTot\tAvg";
cout<<endl;
for(i=0;i<80;i++)
cout<<"-";
while(x.read((char*)&s,sizeof(s)))
{
if(x.eof())
break;
cout<<s.na<<"\t"<<s.std<<"\t"<<s.sec<<"\t"<<s.e<<"\t"<<s.m<<"\t"<<s.p<<"\t"<<s.c<<
"\t"<<s.cs<<"\t"<<s.tot<<"\t"<<s.avg<<"\t";
if(s.e>=40&&s.m>=40&&s.m>=40&&s.c>=40&&s.cs>=40)
cout<<"\nRESULT:Pass\n\n\n";
else
cout<<"\nRESULT:Fail\n\n\n"<<endl;
}
x.close();
}
void main()
{
clrscr();
create();
display();
getch();
}
PROGRAM 15:
#include<iostream.h>
#include<conio.h>
#include<process.h>
int sum(int a[],int n)
{
long int s=0;

for(int i=0;i<n;i++)
s+=a[i];
return s;
}
int sum(int a[],int n,char d)
{
long int s=0;
for(int i=0;i<n;i++)
{
if(d=='E'&& a[i]%2==0)
s+=a[i];
if(d=='O'&&a[i]%2!=0)
s+=a[i];
}
return s;
}
void main()
{
clrscr();
int a[100],n,i,c;
char ch;
cout<<"\nEnter the Number of Elelments:\n"<<endl;;
cin>>n;
cout<<"\n\nEnter "<<n<<" Numbers:\n";
for(i=0;i<n;i++)
cin>>a[i];
cout<< "\n\t\t\t MENU\n"<<endl;
cout<<"\t\t\t-----\n"<<endl;
cout<<"\n\n1. Sum of all NUMBERS\n";
cout<<"\n\n2. Sum of all EVEN NUMBERS\n";
cout<<"\n\n3. Sum of all ODD NUMBERS\n";
cout<<"\n\n4. EXIT\n";
do
{
cout<<"\n\n Enter your choice:\t";
cin>>c;
switch(c)
{
case 1:
cout<<"\n\nSUM OF ALL NUMBERS:\t"<<sum(a,n);
break;
case 2:
ch='E';
cout<<"\n\n SUM OF ALL EVEN
NUMBERS:\t"<<sum(a,n,ch);
break;

case 3:
ch='O';
cout<<"\n\n SUM OF ALL ODD
NUMBERS:\t"<<sum(a,n,ch);
break;
case 4:
exit(0);
default:
cout<<"\n\n Enter Proper Option";
break;
}
}while(c!=4);
getch();
}
PROGRAM 16:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class publication
{
char title[25];
float price;
public:
void getdata()
{
cout<<"\n\n\n\nEnter the title:\t";
gets(title);
cout<<"\nEnter Price:\t";
cin>>price;
}
void putdata()
{
cout<<"\nTitle: "<<title<<endl;
cout<<"\nPrice: Rs. "<<price<<endl;
}
};
class book:public publication
{
int npage;
public:
void getdata()
{
publication::getdata();
cout<<"\nEnter the no. of pages:\t";
cin>>npage;

}
void putdata()
{
publication::putdata();
cout<<"\nNo. of pages: "<<npage;
}
};
class tape:private publication
{
float ptime;
public:
void getdata()
{
publication::getdata();
cout<<"\nEnter the play time in minutes:";
cin>>ptime;
}
void putdata()
{
publication::putdata();
cout<<"\nPlay time: "<<ptime<<" minutes";
}
};
void main()
{
clrscr();
int ch;
book b;
tape t;
b.getdata();
b.putdata();
t.getdata();
t.putdata();
getch();
}
PROGRAM 17:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
#define max 100
char stack[max];
int top;

void push(char stack[],char val,int &top)


{
if(top==max)
{
cout<<"\n\nStack is full";
}
else
{
top=top+1;
stack[top]=val;
}
}
char pop(char stack[],int &top)
{
char value;
if(top<0)
{
cout<<"\nStack is empty"; value=-1;
}
else
{
value=stack[top];
top=top-1;
}
return(value);
}
void show_stack(char stack[],int top)
{
int i;
i=top;
if(top<0)
{
cout<<"\n\nStack is empty";
return;
}
cout<<"\n\nThe values are:";
do
{
cout<<"\n\n"<<stack[i];
i=i-1;
}while(i>=0);
}
void main()
{

clrscr();
int ch;
char val;
char opt='y';
top=-1;
do
{
cout<<"\n\n\n\t\t\tSTACK OPERATION"<<endl;
cout<<"\t\t\t--------------"<<endl;
cout<<"\n\n 1) PUSH\n\n 2) POP";
cout<<"\n\n 3) DISPLAY\n\n 4) Exit";
cout<<"\n\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:
do
{
cout<<"\n\nEnter value to be added:";
cin>>val;
push(stack,val,top);
cout<<"\n\nDo you want to add more elements?(y/n)\n";
cin>>opt;
}while(toupper(opt)=='Y');
clrscr();
break;
case 2:
do
{
val=pop(stack,top);
if(val!=-1)
cout<<"\n\nValue deleted from stack is "<<val;
cout<<"\n\nDo you want to delete more elements?(y/n)\n";
cin>>opt;
}while(toupper(opt)=='Y');
clrscr();
break;
case 3:
show_stack(stack,top);
getch();
clrscr();
break;
case 4:
exit(0);

default:
cout<<"\n\nEnter proper choice"<<endl;
}
}while(ch!=4);
getch();
}
PROGRAM 18:
#include<iostream.h>
#include<conio.h>
const int size=10;
void insert(int a[],int&front,int&rear,int val)
{
if(rear==size)
{
cout<<"\n\nQueue is full";
return;
}
else if(rear==-1)
front=0;
rear++;
a[rear]=val;
cout<<"\n\nValue is inserted";
}
void Delete(int a[],int&front,int&rear)
{
if(front==-1)
{
cout<<"\n\nQueue is empty";
return;
}
cout<<"\n\nDeleted value is "<<a[front]<<endl;
if(front==rear)
front=rear=-1;
else
front++;
}
void display(int a[],int front,int rear)
{
if(front==-1)
{
cout<<"\n\nQueue is empty";

return;
}
cout<<"\n\nThe Value is:";
for(int i=front;i<=rear;i++)
cout<<a[i]<<" ";
}
void main()
{
clrscr();
int a[size],front=-1,rear=-1,val,ch;
do
{
cout<<"\n\n\t\t\tQUEUE OPERATION\n\n";
cout<<"\t\t\t------------------------\n\n"<<endl;
cout<<"\n\n 1) Insert\n\n 2) Delete\n\n 3) Display\n\n 4) Exit\n\n";
cout<<"\n\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n\nEnter a value:";
cin>>val;
insert(a,front,rear,val);
getch();
clrscr();
break;
case 2:
Delete(a,front,rear);
getch();
clrscr();
break;
case 3:
display(a,front,rear);
getch();
clrscr();
break;
}
}while(ch!=4);
getch();
}
PROGRAM 19:
#include<iostream.h>
#include<conio.h>
#include<process.h>

struct node
{
int data;
node*next;
}*ptr,*temp,*first;
void insert(int val)
{
ptr=new node;
ptr->data=val;
ptr->next=NULL;
if(first==NULL)
first=ptr;
else
{
temp=first;
first=ptr;
first->next=temp;
}
}
void Delete()
{
if(first==NULL)
cout<<"\nList is empty";
else
{
cout<<"\nDeleted no is:"<<first->data;
first=first->next;
}
}
void display(node*s)
{
if(s==NULL)
cout<<"\nList is empty";
else
{
cout<<"\n\nThe number in the list are:\n\n"<<endl;
while(s!=NULL)
{
cout<<s->data<<" ";
s=s->next;
}
}
}

void main()
{
clrscr();
int d,ch;
first=NULL;
do
{
cout<<"\n\n\t\t\tSTACK LINKED LIST\n\n";
cout<<"\t\t\t----------------\n\n\n";
cout<<"\n 1) Insert\n\n 2) Delete\n\n 3) Display\n\n 4) Exit\n\n\n Enter
your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n\nEnter any no:";
cin>>d;
insert(d);
clrscr();
break;
case 2:
Delete();
getch();
clrscr();
break;
case 3:
display(first);
getch();
clrscr();
break;
case 4:
exit(0);
}
}while(ch!=4);
getch(); }
PROGRAM 20:
#include<iostream.h>
#include<conio.h>
struct node
{
float data;
node*next;

}*ptr,*rear,*front;
void insert(float val)
{
ptr=new node;
ptr->data=val;
ptr->next=NULL;
if(front==NULL)
front=rear=ptr;
else
{
rear->next=ptr;
rear=ptr;
}
}
void Delete()
{
ptr=front;
if(front==NULL)
{
cout<<"\n\nQueue is empty";
return;
}
cout<<"\n\nDeleted value is"<<ptr->data;
if(front==rear)
front=rear=NULL;
else
{
front=front->next;
}
}
void display()
{
ptr=front;
if(front==NULL)
cout<<"\n\nQueue is empty";
else
{
cout<<"\n";
while(ptr!=NULL)
{
cout<<ptr->data<<" ";
ptr=ptr->next;
}
}
}

void main()
{
clrscr();
int ch;
float val;
front=rear=NULL;
do
{
cout<<"\n\n\n\t\t\tQUEUE LINKED LIST\n"<<endl;
cout<<"\t\t\t------------------\n\n"<<endl;
cout<<"\n 1) Insert\n\n 2) Delete\n\n 3) Display\n\n 4) Exit\n";
cout<<"\n\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n\nEnter any no:";
cin>>val;
insert(val);
clrscr();
break;
case 2:
Delete();
getch();
clrscr();
break;
case 3:
display();
getch();
clrscr();
break;
}
}while(ch!=4);
getch();
}

Vous aimerez peut-être aussi