Professional Documents
Culture Documents
Submitted by:
Ravinder Kumar
Roll no: 1120021
Section: E1
Submitted to:
Dr.
Assistant Professor
Page | 1
SN
EXPERMINENT NAME
PAGE NO
3
4
4
6
9
Page | 2
11
15
20
Page | 3
Page | 4
class mahesh
{
int money;
public:
void getdat()
{
cout<<"enter the money with mahesh:";
cin>>money;
}
friend void comp(mukesh m1, mahesh m2);
};
comp(m1,m2);
getch();
}
img=b;
}
void show()
{
if(img>0)
cout<<real<<"+j"<<img<<endl;
else
cout<<real<<"-j"<<(-1)*img<<endl;
}
complex operator+(complex);
complex operator*(complex);
};
complex complex::operator+(complex c2)
{
complex c3;
c3.real=real+c2.real;
c3.img=img+c2.img;
cout<<" addtion = ";
return(c3);}
complex complex::operator*(complex c2)
{
complex c4;
c4.real=(real*c2.real)-(img*c2.img);
c4.img=(img*c2.real)+(real*c2.img);
cout<<" multiplication= ";
Page | 7
return(c4);
}
int main()
{
complex c1(5.5,4.6);
complex c2(6.7,-9.5);
complex c3;
complex c4;
c1.show();
c2.show();
c3=c1+c2;
c3.show();
c4=c1*c2;
c4.show();
getch();}
Page | 8
{
if(age>p1.age)
return (*this);
else
return p1;
}
void main()
{
person p("RAHUL",30);
person p1("\nSURESH",25);
person p2;
p2=p.greater(p1);
p2.display();
getch();
Page | 10
}
};
class balram
{
public:
int m2;
void getdata2(int y)
{
m2=y;
}
};
void main()
{
clrscr();
total a;
a.getdata1(45);
a.getdata2(35);
a.sum();
a.display();
getch();
}
B) Multilevel inheritances:
#include<iostream.h>
#include<conio.h>
Page | 13
class student
{
protected: int rollno;
public:
void getnumber(int a)
{
rollno=a;
}
void putnumber()
{
cout<<"ROLL NO:"<<rollno;
}};
class marks:public student
{
public:
int s1,s2;
void getm(int a,int b)
{
s1=a;
s2=b;
}};
class result:public marks
{
int total;
public:
Page | 14
void sum()
{
total=s1+s2;
}
void show()
{
putnumber();
cout<<"TOTAL MARKS"<<total<<endl;
}};
void main()
{ clrscr();
result r;
r.getnumber(13);
r.getm(75,99);
r.sum();
r.show();
getch();
}
Page | 15
Page | 16
public:
void roll()
{
cout<<"\n the roll no of the student is 1120013";
}
void mark()
{
cout<<"\n the marks obtained is 96:";
}
};
class sports
{
public:
void medal()
{
cout<<"\n Binit has won gold medal";
}
};
void main()
{
clrscr();
result r;
r.rs();
r.name();
r.mark();
r.medal();
getch();
}
Page | 18
B) Hierarchical inheritance
#include<iostream.h>
#include<conio.h>
class k
{
public:
int a;
void getnumber()
{
cout<<"enter the number:";
cin>>a;
}};
class b:public k
{
public:
void square()
{
getnumber();
cout<<"\n square of the number is:"<<(a*a);
}};
class c:public k
{
Page | 19
public:
void cube()
{
getnumber();
cout<<"\n the cube of the number is:"<<(a*a*a);
}};
void main()
{
clrscr();
b b1;
b1.square();
c c1;
c1.cube();
getch();
}
Page | 20
}
};
};
void main()
{
clrscr();
base b;
base *bptr;
bptr=&b;
bptr->show();
bptr->display();
Page | 22
derived d;
bptr=&d;
bptr->show();
bptr->display();
getch();
}
Page | 23