C++ PGM Printouts
C++ PGM Printouts
STACK OPERATION
#include<iostream.h>
#include<conio.h>
class stack
{
public:
int top,n,x,y,a,b;
int s[10];
void sta();
void push();
void pop();
void list();
void exist();
};
void stack::sta()
{
cout<<"\n enter the limit of stack:";
cin>>x;
top=0;
}
void stack::push()
{
ph:
char a;
if(top>=x)
{
cout<<"\n the stack is full"<<endl;
}
else
{
cout<<"\n enter the item:"<<endl;
cin>>n;
top=top+1;
s[top]=n;
cout<<"\n do you want to continue:";
cin>>a;
if(a=='y')
{
goto ph;
}
}
}
void stack::pop()
{
pop:
char b;
if(top<=0)
{
cout<<"\n the stack is empty:"<<endl;
}
else
{
cout<<"\n deleted item:"<<s[top];
top=top-1;
cout<<"\n do you want to continue:";
cin>>b;
if(b=='y')
{
goto pop;
}
}
}
void stack::list()
{
if(top<=0)
{
cout<<"the stack is empty:"<<endl;
}
else
{
for(int i=top;i>0;i--)
{
cout<<s[i]<<"\n";
}
}
}
void main()
{
stack s;
int ch;
clrscr();
s.sta();
do
{
cout<<"\n 1.push";
cout<<"\n 2.pop";
cout<<"\n 3.list";
cout<<"\n 4.exit";
cout<<"\n enter your choice:";
cin>>ch;
switch(ch)
{
case 1:
s.push();
break;
case 2:
s.pop();
break;
case 3:
s.list();
break;
case 4:
break;
}
}
while(ch!=4);
getch();
}
OUTPUT:
1.push
2. pop
3. list
4. exit
24
25
1. Push
2. Pop
3. List
4. Exit
35
24
25
1. Push
2. Pop
3. List
4. Exit
Deleted item:35
1.push
2.pop
3.list
4.exit
#include<iostream.h>
#include<conio.h>
class arith
public:
int a,b;
float c,d,e,f;
void get();
void add();
void sub();
void mult();
void div();
void disp();
};
void arith::get()
cin>>a;
cin>>b;
void arith::add()
c=a+b;
void arith::sub()
d=a-b;
void arith::mult()
e=a*b;
}
void arith::div()
f=(float)a/(float)b
void arith::disp()
Void main()
clrscr();
arith m;
m.get();
m.add();
m.sub();
m.mult();
m.div();
m.disp();
getch();
}
OUTPUT:
Arithmetic operator:
The sum is :5
The product is :6
#include<iostream.h>
#include<conio.h>
int z=a%10;
return(z);
class digit
int n;
public:
digit();
~digit();
void call();
};
digit::digit()
cin>>n;
}
void digit::call()
int s,t,g;
t=0;
s=1;
b:
for(int i=1;i<=3;i++)
s=rem(n);
n=n/10;
t=t+s;
if(t>9)
n=t;
t=0;
goto b;
else
cout<<"\n sum="<<t;
}
digit::~digit()
n=0;
void main()
clrscr();
digit d;
d.call();
getch();
OUTPUT:
Sum=3
4 OPERATOR OVERLOADING
#include<iostream.h>
#include<conio.h>
#include<string.h>
class FLOAT
public:
float a,b,c,d,e,f;
void get();
float operator+();
float operator-();
float operator*();
void display();
};
void FLOAT::get()
cin>>a;
cin>>b;
}
float FLOAT::operator+()
c=a+b;
return(c);
float FLOAT::operator-()
d=a-b;
return(d);
float FLOAT::operator*()
e=a*b;
return(e);
float FLOAT::operator/(int a)
f=a/b;
return(f);
}
void FLOAT::display()
void main()
clrscr();
FLOAT f;
float w;
f.get();
f.operator+();
f.operator-();
f.operator*();
f.operator/(w);
f.display();
getch();
}
OUTPUT:
#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
public:
char s1[50],s2[50],s3[100];
void get();
char operator+();
void dis();
};
void string::get()
cin>>s1;
cin>>s2;
}
void string::operator=(char s3[100])
if(strcmp(s1,s2)==s3[50])
else
char string::operator+()
s3[100]=s1[50]+s2[50];
return(0);
void string::dis()
}
void main()
clrscr();
char x[50];
string s;
s.get();
s.operator=(x);
s.operator+();
s.dis();
getch();
OUTPUT
#include<iostream.h>
#include<conio.h>
#include<process.h>
class emp
{
public:
int eno,bp;
char name[10],g,dep[10],grade;
void get();
};
class pay:public emp
{
public:
float hra,da,gp,np,pf;
void call();
void disp();
};
void emp::get()
{
cout<<"\n \t pay slip:";
cout<<"\n Enter the emp no:";
cin>>eno;
cout<<"\n Enter the name:";
cin>>name;
cout<<"\n Enter the basic pay:";
cin>>bp;
cout<<"\n Enter the department:";
cin>>dep;
cout<<"\n Enter the grade:";
cin>>g;
}
void pay::call()
{
if(g=='a'||g=='A')
{
hra=bp*0.25;
da=bp*0.40;
pf=bp*0.125;
}
else
if(g=='b'||g=='B')
{
hra=bp*0.20;
da=bp*0.30;
pf=bp*0.125;
}
if(g=='c'||g=='C')
{
hra=bp*0.15;
da=bp*0.20;
pf=bp*0.85;
}
gp=bp+da+hra;
np=gp-pf;
}
void pay::disp()
{
cout<<"\n The pf is:"<<pf;
cout<<"\n The hra is:"<<hra;
cout<<"\n The gross pay is:"<<gp;
cout<<"\n The net pay is:"<<np;
}
void main()
{
clrscr();
pay p;
p.get();
p.call();
p.disp();
getch();
}
OUTPUT:
Payslip:
The pf is:1562.5
#include<iostream.h>
#include<conio.h>
#include<math.h>
class shape
public:
float a,b,c,d,e,h,l,ar,pr;
};
public:
void get()
cout<<"\n square";
cin>>l;
}
void callarea()
ar=l*l;
void callperi()
pr=4*l;
void dis()
};
public:
void get()
cout<<"\n rectangle:";
cin>>d;
cin>>e;
}
void callarea()
ar=d*e;
void callperi()
pr=2*(d+e);
void dis()
};
public:
void get()
cout<<"\n triangle";
cin>>a>>b>>c;
cin>>h;
}
void callarea()
ar=(b*h)/2;
void callperi()
pr=a+b+c;
void dis()
};
void main()
clrscr();
square s;
s.get();
s.callperi();
s.dis();
rectangle r;
r.get();
r.callperi();
r.dis();
triangle t;
t.get();
t.callarea();
t.callperi();
t.dis();
getch();
}
OUTPUT
Rectangle:
Triangle:
#include<iostream.h>
#include<conio.h>
class B;
class A
public:
int a;
float b;
void get()
cin>>a;
cin>>b;
};
class B
public:
int c;
float d;
void get()
cin>>c;
cin>>d;
};
};
void main()
clrscr();
A f;
B g;
f.get();
g.get();
change(f,g);
getch();
}
OUTPUT
Class A:
Class B:
#include<iostream.h>
#include<conio.h>
class add
public:
int i,j,m,n,a[10][10];
int b[10][10],c[20][20];
void get();
float matrix();
void sum();
void disp();
};
void add::get()
cin>>m;
}
int add::matrix(int x)
for(i=0;i<m;i++)
for(j=0;j<m;j++)
cout<<"\n\t";
cin>>a[i][j];
cout<<"\n";
return(x);
float add::matrix()
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
cout<<"\n\t";
cin>>b[i][j];
cout<<"\n";
return(0);
void add::sum()
for(i=0;i<m;i++)
for(j=0;j<m;j++)
c[i][j]=a[i][j]+b[i][j];
}
void add::disp()
int p=0;
float q,r;
q=r=0;
for(i=0;i<m;i++)
for(j=0;j<m;j++)
cout<<"\t"<<a[i][j];
cout<<"\n";
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
cout<<"\t"<<b[i][j];
cout<<"\n";
for(i=0;i<m;i++)
for(j=0;j<m;j++)
cout<<"\t"<<c[i][j];
p=p+a[i][j];
q=q+b[i][j];
cout<<"\n";
void main()
{
clrscr();
add a;
int x;
a.get();
a.matrix(x);
a.matrix();
a.sum();
a.disp();
getch();
}
OUTPUT
11
12
13
14
15
16
17
18
Matrix A
11 12
13 14
Matrix B
15 16
17 18
26 28
30 32
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
clrscr();
int a,i;
char s1[10],*s2[10];
cin>>s1;
strcpy(*s2,s1);
cin>>s1;
strcpy(*s2,s1);
strrev(s1);
a=strlen(s1);
i=strcmp(s1,*s2);
if(i==0)
else
getch();
OUTPUT
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
clrscr();
ofstream a;
char x[50];
a.open("kkk",ios::out);
a.close();
a.open("kkk",ios::app);
cin.read(x,50);
a<<x;
a.close();
ifstream b;
b.open("kkk",ios::in);
int r=1;
while(b.eof()==0)
cout<<"\n ["<<r<<"]";
b>>x;
cout<<x<<endl;
r++;
getch();
OUTPUT
Welcome
To
Bacas
College
Of
Arts
And
Science
[1] welcome
[2]to
[3] bacas
[4] college
[5]of
[6]Arts
[7]and
[8] science
12. MERGE FILE
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
clrscr();
ofstream a;
char x[50];
a.open("aaa",ios::out);
cin>>getline(x,50);
a<<x;
a.close();
ofstream b;
char y[50];
b.open("bbb",ios::out);
cout<<"\n Enter the content of file2:";
cin.getline(y,50);
b<<y;
b.close();
ofstream c;
ifstream d;
ifstream e;
ifstream f;
c.open("ccc",ios::in);
char z[100];
d.open("aaa",ios::in);
cout<<"\n\t\t";
c<<x;
d.close();
e.open("bbb",ios::in);
c<<y;
e.close();
c.close();
ifstream();
f.open("ccc",ios::in);
while(f.eof()==0)
f>>x;
f>>y;
cout<<x<<y;
f.close();
getch();
OUTPUT
AbdulKalam