Академический Документы
Профессиональный Документы
Культура Документы
S COLLEGE OF SCIENCE
void main()
{
employee e;
clrscr();
e.getdata();
e.display();
getch();
}
1
P.E.S COLLEGE OF SCIENCE
Output:
enter name:Raj
enter desig:software-developer
basic salary:26000
name:Raj
desig:software-developer
salary:26000
2
P.E.S COLLEGE OF SCIENCE
3
P.E.S COLLEGE OF SCIENCE
Output:
details of employee1
Enter name:mantu
Enter designation:software-tester
Enter salary:50000
details of employee2
Enter name:raj
Enter designation:web-designer
Enter salary:40000
details of employee3
Enter name:harish
Enter designation:software-developer
Enter salary:35000
Employee1
name:mantu
designation:software-tester
salary:50000
Employee2
name:raj
designation:web-designer
salary:40000
Employee3
name:harish
designation:software-developer
salary:35000
4
P.E.S COLLEGE OF SCIENCE
void getdata(void);
friend void total(savings,current);
};
class current
{
public:
char name[20];
char acc_no[20];
char acc_type[10];
float balance;
void getdata(void);
friend void total(savings,current);
};
void savings::getdata(void)
{
cout<<"name:";
cin>>name;
cout<<"acc no:";
cin>>acc_no;
cout<<"acc type:savings"<<"\n";
cout<<"balance:";
cin>>balance;
}
void current::getdata(void)
{
cout<<"name:";
cin>>name;
cout<<"acc no:";
cin>>acc_no;
5
P.E.S COLLEGE OF SCIENCE
cout<<"acc type:current"<<"\n";
cout<<"balance:";
cin>>balance;
}
Output:
Name:mantu
acc no:8901273491
acc type:savings
balance:60000
name:mantu
acc no:8912374234
acc type:current
balance:20000
total balance:80000
6
P.E.S COLLEGE OF SCIENCE
7
P.E.S COLLEGE OF SCIENCE
Output:
details of accounts1
enter customer name:harish
enter acc no:912376
enter acc type:savings
enter balance:4500
details of accounts2
enter customer name:mantu
enter acc no:78912
enter acc type:current
enter balance:120000
details of accounts3
enter customer name:raj
enter acc no:712369
enter acc type:savings
enter balance:65000
details of accounts4
enter customer name:p2
enter acc no:789234
enter acc type:savings
enter balance:4300
details of accounts5
enter customer name:mrba
8
P.E.S COLLEGE OF SCIENCE
account1
customer:harish
acc no:912376
acc type:savings
balance:4500
account2
customer:mantu
acc no:78912
acc type:current
balance:120000
account3
customer:raj
acc no:712369
acc type:savings
balance:65000
account4
customer:p2
acc no:789234
acc type:savings
balance:4300
account5
customer:mrba
acc no:896762
acc type:current
balance:2540000
9
P.E.S COLLEGE OF SCIENCE
else
getch();
}
string operator+(string a,string b)
{
string c;
strcat(a.t,b.t);
strcpy(c.t,a.t);
return c;
}
10
P.E.S COLLEGE OF SCIENCE
Output:
11
P.E.S COLLEGE OF SCIENCE
#include<iostream.h>
#include<conio.h>
class complex
{
float x;
float y;
public:
complex(){}
complex(float real,float imag)
{
x=real;
y=imag;
}
complex operator+(complex);
complex operator*(complex);
complex operator-(complex);
void display(void);
};
complex complex::operator+(complex sum)
{
complex temp;
temp.x=x+sum.x;
temp.y=y+sum.y;
return(temp);
}
complex complex::operator*(complex pro)
{
complex temp;
temp.x=x*pro.x;
temp.y=y*pro.y;
return(temp);
}
complex complex::operator-(complex diff)
{
complex temp;
temp.x=x-diff.x;
temp.y=y-diff.y;
return(temp);
}
void complex::display(void)
{
cout<<x<<"+j"<<"("<< y <<")"<<"\n";
12
P.E.S COLLEGE OF SCIENCE
}
void main()
{
complex summ,differ,product,c1,c2;
clrscr();
c1=complex(2.5,3.5);
c2=complex(1.6,2.7);
summ=c1+c2;
product=c1*c2;
differ=c1-c2;
cout<<"c1=";
c1.display();
cout<<"c2=";
c2.display();
cout<<"sum=";
summ.display();
cout<<"product=";
product.display();
cout<<"difference=";
differ.display();
getch();
}
Output:
C1=2.5+j(3.5)
C2=1.6+j(2.7)
Sum=4.1+j(6.2)
Product=4+j(9.45)
Difference=0.9+j(0.8)
13
P.E.S COLLEGE OF SCIENCE
#include<iostream.h>
#include<conio.h>
class GF
{
public:
double height;
double base;
void getdata()
{
cout<<"enter base:";
cin>>base;
cout<<"enter height:";
cin>>height;
}
virtual double calcarea()=0;
virtual void display()=0;
};
class triangle:public GF
{
public:
double triangle_area;
double calcarea()
{
triangle_area=0.5*base*height;
return 0;
}
void display()
{
cout<<"area of triangle="<<triangle_area<<endl;
}
};
class rectangle:public GF
{
public:
14
P.E.S COLLEGE OF SCIENCE
double rectangle_area;
double calcarea()
{
rectangle_area=base*height;
return 0;
}
void display()
{
cout<<"area of rectangle="<<rectangle_area<<endl;
}
};
void main()
{
clrscr();
triangle t1;
rectangle r1;
t1.getdata();
t1.calcarea();
t1.display();
r1.getdata();
r1.calcarea();
r1.display();
getch();
}
Output:
Enter base:3
Enter height:2
Area of triangle:3
Enter base:4
Enter height:6
Area of rectangle=24
15
P.E.S COLLEGE OF SCIENCE
#include<iostream.h>
#include<conio.h>
#include<process.h>
const int max=4;
class stack
{
protected:
int stk[max];
int top;
public:
stack()
{
top=-1;
}
void push()
{
int n;
cout<<"enter item to be insert:";
cin>>n;
top++;
stk[top]=n;
cout<<"\n"<<n<<" inserted."<<endl;
}
int pop()
{
int m;
m=stk[top];
top--;
cout<<"\n"<<m<<"popped"<<endl;
return(m);
}
void show();
};
void stack::show()
{
if(top==-1)
cout<<"stack is empty";
else
{
cout<<"stack elements:";
for(int i=top;i>=0;i--)
16
P.E.S COLLEGE OF SCIENCE
cout<<"\n"<<stk[i];
}
}
class stack_status:public stack
{
public:
void push()
{
if(top==max-1)
cout<<"\n stack over flow"<<endl;
else
{
stack::push();
if(top==max-1)
cout<<"\n stack is full"<<endl;
}
}
int pop()
{
int m;
if(top==-1)
{
cout<<"\n stack under flow"<<endl;
return 0;
}
else
{
m=stack::pop();
if(top==-1)
cout<<"\n stack is empty";
return(m);
}
}
};
void main()
{
clrscr();
int num,s,choice;
stack_status S;
do
{
cout<<"\n\n......stack operation.....";
cout<<"\n 1.push";
cout<<"\n 2.pop";
cout<<"\n 3.display";
cout<<"\n 4.exit";
cout<<"\n enter your choice:";
17
P.E.S COLLEGE OF SCIENCE
cin>>choice;
switch(choice)
{
case 1:
S.push();
break;
case 2:
S.pop();
break;
case 3:
S.show();
break;
case 4:
exit(0);
default:
cout<<"\n wrong choice!!";
}
}while(choice!=4);
getch();
}
Output:
......stack operation......
1.push
2.pop
3.display
4.exit
enter your choice:1
enter item to be insert:12
12 inserted.
......stack operation......
1.push
2.pop
3.display
4.exit
enter your choice:1
enter item to be insert:23
23 inserted.
......stack operation......
18
P.E.S COLLEGE OF SCIENCE
1.push
2.pop
3.display
4.exit
enter your choice:3
stack elements:
23
12
......stack operation......
1.push
2.pop
3.display
4.exit
enter your choice:2
23 popped
......stack operation......
1.push
2.pop
3.display
4.exit
enter your choice:3
stack elements:
12
......stack operation......
1.push
2.pop
3.display
4.exit
enter your choice:4
19