1.
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
Enter your choice:1
Enter the item:
24
Do you want to continue:y
Enter the item:
25
Do you want to continue:y
The stack is full
1. Push
2. Pop
3. List
4. Exit
Enter your choice:3
35
24
25
1. Push
2. Pop
3. List
4. Exit
Enter your choice:2
Deleted item:35
Do you want to continue:y
The stack is empty
1.push
2.pop
3.list
4.exit
Enter your choice:4
2.ARITHMETIC OPERATION
#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()
cout<<"\n Arithmetic operator\n";
cout<<"\n\n Enter the value of a:";
cin>>a;
cout<<"\n Enter the value of b:";
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()
cout<<"\n The sum is:"<<c;
cout<<"\n The difference is:"<<d;
cout<<"\n The product is:"<<e;
cout<<"\n The division is:"<<f;
Void main()
clrscr();
arith m;
m.get();
m.add();
m.sub();
m.mult();
m.div();
m.disp();
getch();
}
OUTPUT:
Arithmetic operator:
Enter the value of a:2
Enter the value of b:3
The sum is :5
The difference is: -1
The product is :6
The division is:0.666667
3 CONSTRUCTOR AND DESTRUCTOR
#include<iostream.h>
#include<conio.h>
inline int rem(int a)
int z=a%10;
return(z);
class digit
int n;
public:
digit();
~digit();
void call();
};
digit::digit()
cout<<"\n Enter the number:";
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:
Enter the number:300
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*();
float operator/(int a);
void display();
};
void FLOAT::get()
cout<<"\n enter the value:";
cin>>a;
cout<<"\n enter the value b:";
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()
cout<<"\n The sum is:"<<c;
cout<<"\n The difference is:"<<d;
cout<<"\n The product is:"<<e;
cout<<"\n The division is:"<<f;
void main()
clrscr();
FLOAT f;
float w;
f.get();
f.operator+();
f.operator-();
f.operator*();
f.operator/(w);
f.display();
getch();
}
OUTPUT:
Enter the value of a:3
Enter the value of b:4
The sum is:7
The difference is:-1
The product is: 12
The division is: 0.75
5 STRING MANIPULATORS
#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
public:
char s1[50],s2[50],s3[100];
void get();
void operator=(char s3[100]);
char operator+();
void dis();
};
void string::get()
cout<<"\n enter first string:";
cin>>s1;
cout<<"\n enter second string:";
cin>>s2;
}
void string::operator=(char s3[100])
if(strcmp(s1,s2)==s3[50])
cout<<"\n Strings are same:";
else
cout<<"\n Strings are different";
char string::operator+()
s3[100]=s1[50]+s2[50];
return(0);
void string::dis()
cout<<"\n The concadinated string is:"<<strcat(s1,s2);
}
void main()
clrscr();
char x[50];
string s;
s.get();
s.operator=(x);
s.operator+();
s.dis();
getch();
OUTPUT
Enter the first string: sam
Enter the second string:sam
Strings are same
The concatenated string is :sam sam
Enter the first string: sam
Enter the second string:Raja
Strings are different
The concatenated string is :sam Raja
6.EMPLOYEE DETAILS
#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:
Enter the emp number : 23
Enter the name : Jasmine
Enter the basic pay:12500
Enter the department:cs
Enter the grade:A
The pf is:1562.5
The hra is:3125
7. SHAPES
#include<iostream.h>
#include<conio.h>
#include<math.h>
class shape
public:
float a,b,c,d,e,h,l,ar,pr;
virtual void callarea(){};
virtual void callperi(){};
};
class square:public shape
public:
void get()
cout<<"\n square";
cout<<"\n Enter the size:";
cin>>l;
}
void callarea()
ar=l*l;
void callperi()
pr=4*l;
void dis()
cout<<"\n The area of square is:"<<ar;
cout<<"\n The perimeter of square is:"<<pr<<endl;
};
class rectangle:public shape
public:
void get()
cout<<"\n rectangle:";
cout<<"\n Enter the depth:";
cin>>d;
cout<<"\n Enter the breath:";
cin>>e;
}
void callarea()
ar=d*e;
void callperi()
pr=2*(d+e);
void dis()
cout<<"\n The area of rectangle is:"<<ar;
cout<<"\n The perimeter of rectangle is:"<<pr<<endl;
};
class triangle:public shape
public:
void get()
cout<<"\n triangle";
cout<<"\n Enter the value of a & b & c:";
cin>>a>>b>>c;
cout<<"\n Enter the value of h:";
cin>>h;
}
void callarea()
ar=(b*h)/2;
void callperi()
pr=a+b+c;
void dis()
cout<<"\n The area of triangle :"<<ar;
cout<<"\n The perimeter of a triangle is:"<<pr;
};
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
Enter the size:2
The area of square is :1.049829
The perimeter of square is: 8
Rectangle:
Enter the depth: 3
Enter the breath: 4
The area of rectangle is : 5.88965
The perimeter of rectangle is: 14
Triangle:
Enter the value of a & b & c:
Enter the value of h:6
The area of a triangle : 9
The perimeter of a triangle : 9
8. FRIEND FUNCTION
#include<iostream.h>
#include<conio.h>
class B;
class A
public:
int a;
float b;
void get()
cout<<"\n\t class A:";
cout<<"\n Enter the intger value:";
cin>>a;
cout<<"\n Enter the float value:";
cin>>b;
friend void change(A,B);
};
class B
public:
int c;
float d;
void get()
cout<<"\n\t class B:";
cout<<"\n Enter the integer value:";
cin>>c;
cout<<"\n Enter the float value:";
cin>>d;
friend void disp(A,B);
};
void change(A x,B y)
cout<<"\n class A integer value:"<<x.a;
cout<<"\n class A float value:"<<x.b;
cout<<"\n class B integer value:"<<y.c;
cout<<"\n class B float value:"<<y.d;
};
void main()
clrscr();
A f;
B g;
f.get();
g.get();
change(f,g);
getch();
}
OUTPUT
Class A:
Enter the integer value:3
Enter the float value: 3.5
Class B:
Enter the integer value : 4
Enter the float value : 4.5
Class A integer value : 3
Class A float value: 3.5
Class B integer value: 4
Class B float value : 4.5
9. SUM OF MATRIX
#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();
int matrix(int x);
void sum();
void disp();
};
void add::get()
cout<<"\n Enter the order of matrix:";
cin>>m;
}
int add::matrix(int x)
cout<<"\n Enter the value of matrix a:";
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()
cout<<"\n Enter the value of matrix b:";
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;
cout<<"\n matrix a \n\n";
for(i=0;i<m;i++)
for(j=0;j<m;j++)
cout<<"\t"<<a[i][j];
cout<<"\n";
cout<<"\n matrix B \n\n";
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
cout<<"\t"<<b[i][j];
cout<<"\n";
cout<<"\n The sum of above matrix:\n\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";
cout<<"\n The individual sum of matrix a :"<<p;
cout<<"\n The individual sum of matrix b :"<<q;
cout<<"\n The individual sum of matrix c :"<<r;
void main()
{
clrscr();
add a;
int x;
a.get();
a.matrix(x);
a.matrix();
a.sum();
a.disp();
getch();
}
OUTPUT
Enter the order of matrix: 2
Enter the value for matrix A:
11
12
13
14
Enter the value for matrix B:
15
16
17
18
Matrix A
11 12
13 14
Matrix B
15 16
17 18
The sum of above matrix:
26 28
30 32
The individual sum of matrix A: 50
The individual sum of matrix B: 66
The individual sum of matrix C: 116
10. PALINDROME
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
clrscr();
int a,i;
char s1[10],*s2[10];
cout<<"\n Enter the string:";
cin>>s1;
strcpy(*s2,s1);
cin>>s1;
strcpy(*s2,s1);
strrev(s1);
a=strlen(s1);
i=strcmp(s1,*s2);
if(i==0)
cout<<"\n The string is palindrome";
else
cout<<"\n The string is not a palindrome";
cout<<"\n The length of the string is:"<<a;
getch();
OUTPUT
Enter the string : MADAM
The string is palindrome
The length of the string is: 5
Enter the string : DEEP
The string is not a palindrome
The length of the string is: 4
11. FILE WITH LINE NUMBER
#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);
cout<<"\n Enter the input:\n";
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
Enter the input:
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);
cout<<"\n Enter the content of file1:";
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
Enter the content of file1: Abdul
Enter the content of file2: Kalam
AbdulKalam