0% found this document useful (0 votes)
72 views78 pages

Computer Engineering.: SR No. Unit Practical Exercises/Experiments Approx. Hrs. Required 1 1 1 2

The document provides details about 14 practical exercises/experiments for OOP course. It includes developing programs using C++ structures, reference variables, input-output functions, call by reference and return by reference, defining classes for student, distance, shape and employee, using array of objects and static member functions, passing and returning objects, operator overloading, scope resolution operators, constructors, destructors, inheritance, pointer to derived classes, and 'this' keyword. Sample code and outputs are provided for some of the exercises.

Uploaded by

Dhruv Sojitra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views78 pages

Computer Engineering.: SR No. Unit Practical Exercises/Experiments Approx. Hrs. Required 1 1 1 2

The document provides details about 14 practical exercises/experiments for OOP course. It includes developing programs using C++ structures, reference variables, input-output functions, call by reference and return by reference, defining classes for student, distance, shape and employee, using array of objects and static member functions, passing and returning objects, operator overloading, scope resolution operators, constructors, destructors, inheritance, pointer to derived classes, and 'this' keyword. Sample code and outputs are provided for some of the exercises.

Uploaded by

Dhruv Sojitra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 78

OOP(1030106301) COMPUTER ENGINEERING.

Sr No. Unit Practical Exercises/Experiments Approx. Hrs.


Required
1 1 Develop program using C++ structure. 2

2 Develop programs using reference variables. 4


1
3 1 Develop programs using formatted and unformatted i/o 4
functions.
4 2 Develop programs using call by reference and return by 4
reference.
5 Define minimum 3 different classes (such as student, 4
2 distance, shape, and employee etc) and test those classes
functionality.
6 Develop Programs using an array of objects and static 4
2 member functions.
7 Develop programs to pass objects as an argument and 4
2 returning object.
8 3 Develop programs that define the concept of operator 4
overloading.
9 3 Develop programs using Scope Resolution Operators. 4

10 4 Develop programs using various types of constructors and 6


destructors.

Develop programs using single, multilevel, multiple 6


11 5 inheritance
12 Develop programs using constructors in derived classes. 4
5

13 6 Develop programs using pointer to derived classes 4

14 6 Develop programs using ‘this’ keyword. 2

DHRUV SOJITRA
C++
(20270106160) Page 1
OOP(1030106301) COMPUTER ENGINEERING.

UNIT-1

Sr No. Unit Practical Exercises/Experiments Approx. Hrs.


Required
1 1 Develop program using C++ structure. 2

2 Develop programs using reference variables. 4


1
3 1 Develop programs using formatted and unformatted i/o 4
functions.
ACTICAL-1
AIM:DEVELOP PROGRAM USING C++ STRUCTURE.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();

DHRUV SOJITRA
(20270106160) Page 2
OOP(1030106301) COMPUTER ENGINEERING.

char a[15],b[15],c[11];
cout<<"\n enter your name:";
cin>>a;
cout<<"\n enter your department:";
cin>>b;
cout<<"\n enter your enrollmentnumber:";
cin>>c;
cout<<"\n your name is: "<<a;
cout<<"\n your department: "<<b;
cout<<"\n your enr_no: "<<c;
getch();
}

 OUTPUT

-PRACTICAL-2
AIM:DEVELOP PROGRAM USING REFERENCE VARIABLES.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();

DHRUV SOJITRA
(20270106160) Page 3
OOP(1030106301) COMPUTER ENGINEERING.

int x;
int&y=x;
y=50;
cout<<"\n x";
x=x++;
cout<<"\n value of x:"<<x;
cout<<"\n value of y:"<<y;
getch();
}

 OUTPUT

PRACTICAL-3
AIM :Develop
Programs Using
Formatted i/o
Functions.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
float x=2.345475;
clrscr();

cout<<setw(6)<<14<<endl;
cout<<setw(5)<<28<<endl;
cout<<setprecision(3)<<x<<endl;

DHRUV SOJITRA
(20270106160) Page 4
OOP(1030106301) COMPUTER ENGINEERING.

cout<<setprecision(4)<<x<<endl;
cout<<setw(7)<<setioSflags(ios::scientific)<<x<<endl;
cout<<setw(8)<<resetiosflags(ios::scientific)<<x<<endl;

 OUTPUT

PARTICLE : 4
AIM :Develop Programs Using Unformatted i/o Functions.

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
charstr[50];

cout<<"\n enter string:";


cin.getline(str,50);

DHRUV SOJITRA
(20270106160) Page 5
OOP(1030106301) COMPUTER ENGINEERING.

int len=strlen(str);
cout.write(str,len)<<endl;
int length=len-7;
cout.write(str,length)<<endl;
getch();
}

 OUTPUT

PRACTICAL-5
AIM: Develop program in C++ to find out addition, subtraction, multiplication, division
operations of two integer numbers using switch case.
#include<iostream.h>
#include<conio.h>
int main()
{
int a,b,c,ch;
clrscr();
cout<<"enter value of a and b:";
cin>>a>>b;
cout<<"\n1. Addition";
cout<<"\n2. Substraction";

DHRUV SOJITRA
(20270106160) Page 6
OOP(1030106301) COMPUTER ENGINEERING.

cout<<"\n3. Multiplication";
cout<<"\n4. Division";
cout<<"\nEnter your choice:";
cin>>ch;
switch (ch)
{
case 1:
c=a+b;
cout<<"Addition is:"<<c;
break;

case 2:
c=a-b;
cout<<"Substraction is:"<<c;
break;
case 3:
c=a*b;
cout<<"Multipliaction is:"<<c;
break;
case 4:
c=a/b;
cout<<"division is:"<<c;
break;
default:
cout<<"You entered wrong choice";
break;
}
getch();
return 0;
}

DHRUV SOJITRA
(20270106160) Page 7
OOP(1030106301) COMPUTER ENGINEERING.

 OUTPUT

Practical: 6
AIM: Develop a program to print even and odd numbers using for loop.

#include <iostream.h>
#include <conio.h>
int main()
{
int i,num;
clrscr();
cout<<"Enter the maximum number:\n";
cin>>num;
cout<<"Even numbers are:";

DHRUV SOJITRA
(20270106160) Page 8
OOP(1030106301) COMPUTER ENGINEERING.

for(i=2;i<=num;i+=2)
{
cout<<i<<"";
}
cout<<"\n Odd numbers are:";
for(i=1;i<=num;i+=2)
{
cout<<i<<"";
}
getch();
return 0;
}

 Output

DHRUV SOJITRA
(20270106160) Page 9
OOP(1030106301) COMPUTER ENGINEERING.

Practical: 7
AIM: Develop a program to print 1 to 10 numbers using while loop.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0;
while(a<10)
{
++a;
cout<<a<<endl;
}
getch();
}

 Output

DHRUV SOJITRA
(20270106160) Page 10
OOP(1030106301) COMPUTER ENGINEERING.

UNIT-2
4 2 Develop programs using call by reference and return by 4
reference.
5 Define minimum 3 different classes (such as student, 4
2 distance, shape, and employee etc) and test those classes
functionality.
6 Develop Programs using an array of objects and static 4
2 member functions.
7 Develop programs to pass objects as an argument and 4
2 returning object.

PRACTICAL-1(i)
AIM : Develop program using call by reference.
#include <iostream.h>
#include <conio.h>
void swap(int &a, int&b)
{
int temp=a;
a=b;

DHRUV SOJITRA
(20270106160) Page 11
OOP(1030106301) COMPUTER ENGINEERING.

b=temp;
}
void main()
{
int a,b;
clrscr();
cout<<"Enter The Numbre Of A :"<<endl;
cin>>a;
cout<<"Enter The Number of B :"<<en dl;
cin>>b;
cout<<"Befor A :"<<a<<" Befor B : "<<b<<endl;
swap(a,b);
cout<<"After A :"<<a<<" After B :"<<b<<endl;
getch();

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 12
OOP(1030106301) COMPUTER ENGINEERING.

DHRUV SOJITRA
(20270106160) Page 13
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-1(ii)
AIM : Develop program using return by reference.

#include <iostream.h>

#include <conio.h>

int &max(int &x,int &y)

if(x>y)

return x;

else

return y;

void main()

int a,b,c;

clrscr();

cout<<"Enter The Numbre Of A :"<<endl;

cin>>a;

cout<<"Enter The Number of B :"<<endl;

cin>>b;

int &max(int &x, int &y);

c=max(a,b);

max(a,b)=1;

cout<<" max number is "<<c<<endl;

DHRUV SOJITRA
(20270106160) Page 14
OOP(1030106301) COMPUTER ENGINEERING.

getch();

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 15
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-2(i)
AIM:- Create a class student and test classic functionality.
#include<iostream.h>
#include<conio.h>
class student
{
private:
char name[15],department[15];
int enrollment_no;
public:
void getdata()
{
clrscr();
cout<<"Enter The Name:";
cin>>name;
cout<<"Enter The Department:";
cin>>department;
cout<<"Enter The Enrollment_No:";
cin>>enrollment_no;
}
void display()
{
cout<<"\nName:"<<name;
cout<<"\nDepartment:"<<department;
cout<<"\nEnrollment_No:"<<enrollment_no;
}
};

void main()

DHRUV SOJITRA
(20270106160) Page 16
OOP(1030106301) COMPUTER ENGINEERING.

{
student s;
s.getdata();
s.display();
getch();
}

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 17
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-2(ii)
AIM: create a class employee and test classic functionality.
#include<iostream.h>
#include<conio.h>

class employee
{
private:
char name[20],job[15];
float salary;
public:
void getdata()
{
clrscr();
cout<<"Enter The Name:";
cin>>name;
cout<<"Enter The Job:";
cin>>job;
cout<<"Enter The Salary:";
cin>>salary;
}
void display()
{
cout<<"\n Name:"<<name;
cout<<"\n Job:"<<job;
cout<<"\n Salary:"<<salary;

DHRUV SOJITRA
(20270106160) Page 18
OOP(1030106301) COMPUTER ENGINEERING.

}
};
void main()
{
employee e;
e.getdata();
e.display();
getch();
}
\

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 19
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-2(iii)
Aim: Create a class shape and test classic funtonally.
#include<iostream.h>
#include<conio.h>
class shape
{
private:
float r,l,b,a,c,d,e;
public:
void getdata();
void display();
};

void shape::getdata()
{
cout<<"\n enter length:";
cin>>l;
cout<<"\n enter radius:";
cin>>r;
cout<<"\n enter breath:";
cin>>b;

a=3.14*r*r;
e=0.5*l*b;
c=l*l;
d=l*b;
}

void shape::display()

DHRUV SOJITRA
(20270106160) Page 20
OOP(1030106301) COMPUTER ENGINEERING.

{
cout<<"\n area of circle="<<a;
cout<<"\n area of triangle="<<e;
cout<<"\n area of sque="<<c;
cout<<"\n area of rectangle="<<d;
}

void main()
{
clrscr();
shape a1;
a1.getdata();
a1.display();
getch();
}

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 21
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-3(i)
AIM:- Develop Programs using as array of objects.
#include<iostream.h>

#include<conio.h>
class student
{
private:
int enrollno;
char name[20] depar[20];
public:
void getdata();
void putdata();
};
void student::getdata()
{
cout<<"Enter Enroll_No: ";
cin>>enrollno;
cout<<"Enter Student Name: ";
cin>>name;
cout<<"enter depatrment";
cin>>depar;
}
void student::putdata()
{
cout<<"\n Student Roll_No:"<<enrollno;
cout<<"\n Student Name:"<<name;
cout<<"\n depatrment:"<<depar;
}
void main()

DHRUV SOJITRA
(20270106160) Page 22
OOP(1030106301) COMPUTER ENGINEERING.

{
clrscr();
int i;
student s1[10];

for(i=1;i<=10;i++)
{
s1[i].getdata();
}
for(i=1;i<=10;i++)
{
s1[i].putdata();
}
getch();
}

DHRUV SOJITRA
(20270106160) Page 23
OOP(1030106301) COMPUTER ENGINEERING.

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 24
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-3(ii)
AIM:Develop pogram using as static function.
#include<iostream.h>
#include<conio.h>

class item
{
static int count;
int number;
public:
void getdata(int a)
{
number=a;
count ++;
}
void getcount()
{
cout<<"\n count="<<count;
cout<<"\n number="<<number;

}
};
int item::count;
void main()
{
clrscr();
item a,b,c;
a.getcount();
b.getcount();

DHRUV SOJITRA
(20270106160) Page 25
OOP(1030106301) COMPUTER ENGINEERING.

c.getcount();

a.getdata(100);
b.getdata(200);
c.getdata(300);
cout<<"\n";
cout<<"\n After reading data \n";
a.getcount();
b.getcount();
c.getcount();
getch();
}

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 26
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-3(iii)
AIM:-Develop program using as static member function.
#include<iostream.h>
#include<conio.h>

class demo
{
private:
static int x,y;
public:
static void print()
{
cout<<"\n x="<<x;
cout<<"\n y="<<y;
}
};
int demo::x=10;
int demo::y=20;
void main()
{
demo d;
cout<<"\n printing through class name:";
demo::print();
getch();
}

DHRUV SOJITRA
(20270106160) Page 27
OOP(1030106301) COMPUTER ENGINEERING.

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 28
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-4(i)
AIM:- Develop to pass object an argument.
#include<iostream.h>
#include<conio.h>

class test
{
private:
int x;
public:
void getdata(int m)
{
x=m;
}
void squareroot(test t1)
{
x=t1.x * t1.x;
}
void show()
{
cout<<"Squreroot of number is: "<<x<<endl;
}

};

void main()
{
test t11,t12;
t11.getdata(5);
t12.squareroot(t11);
t12.show();
getch();
}

DHRUV SOJITRA
(20270106160) Page 29
OOP(1030106301) COMPUTER ENGINEERING.

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 30
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-4(ii)
AIM:-Develop program returning object.
#include<iostream.h>
#include<conio.h>

class example
{
public:
int a;
friend example add(example ,example);
void disp(example e)
{
cout<<"addition is:\n"<<e.a;
}
};
example add (example e1,example e2)
{
example e3;
e3.a=e1.a+e2.a;
return(e3);
}
void main()
{
clrscr();
example e11,e12,e13;
e11.a=100;
e12.a=200;
e13=add(e11,e12);
e13.disp(e13);

DHRUV SOJITRA
(20270106160) Page 31
OOP(1030106301) COMPUTER ENGINEERING.

getch();
}

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 32
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-5(i)
AIM:-Develop C++ program using friend function.
#include<iostream.h>
#include<conio.h>
class box
{
private:
int x;
public:
void intialize()
{
x=0;
}
friend int printx(box b);
};
int printx(box b)
{
b.x+= 10;
return(b.x);
}
void main()
{
clrscr();
box b1;
b1.intialize();
cout<<"\n x="<<printx(b1);
getch();
}

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 33
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-5(ii)
AIM:- Develop C++ program using friend with multiple class function.
#include<iostream.h>
#include<conio.h>
class B;
class A
{
private:
int x;
public:
void setdata(int dx)
{
x=dx;
}
friend void min(A,B)

};
class B
{
private:
int y;
public:
void setdata(int dy)
{
y=dy;
}
friend void min(A,B)
};
void min(A a1,B b1)

DHRUV SOJITRA
(20270106160) Page 34
OOP(1030106301) COMPUTER ENGINEERING.

{
if(a1.x<b1.y)
{
cout<<a1.x<<"is minimum";
}
else
{
cout<<b1.y<<"is maximum";
}
}
void main()
{
float a,b;
clrscr();
A aa;
B bb;

cout<<"\n enter the value of A and B:";


cin>>a>>b;

aa.setdata(a);
bb.setdata(b);
min(aa,bb);
getch();
}

DHRUV SOJITRA
(20270106160) Page 35
OOP(1030106301) COMPUTER ENGINEERING.

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 36
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-5(iii)
AIM:- Develop C++ program using friend with constructer function.
#include<iostream.h>
#include<conio.h>
class box
{
private:
int x;
public:
box()
{
x=10;
}
friend int printx(box b);
};
int printx(box b)
{
b.x+=10;
return 0;
}

void main()
{
clrscr();
box b;
cout<<"\n value of x="<<printx(b);
getch();
}

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 37
OOP(1030106301) COMPUTER ENGINEERING.

UNIT-3
8 3 Develop programs that define the concept of operator 4
overloading.
9 3 Develop programs using Scope Resolution Operators. 4

DHRUV SOJITRA
(20270106160) Page 38
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-1
AIM:-Develop program that define the concept of operator overloading
#include<iostream.h>
#include<conio.h>
class shape
{
int x,y,z;
public:
void getdata(int a,int b,int c);
void display();
void operator-();
};

void shape::getdata(int a,int b,int c)


{
x=a;
y=b;
z=c;
}
void shape::display()
{
cout<<x<<"\t";
cout<<y<<"\t";
cout<<z<<"\t";
}
void shape::operator-()
{
cout<<"\n";
x=-x;
y=-y;
z=-z;
}
void main()
{
clrscr();
shape s;
s.getdata(10,-20,30);
s.display();

-s;
cout<<"s";
s.display();
getch();

DHRUV SOJITRA
(20270106160) Page 39
OOP(1030106301) COMPUTER ENGINEERING.

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 40
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-2
AIM:-Develop program scope resolution operators.
#include<iostream.h>
#include<conio.h>
int m=10;
void main()
{
int m=20;
clrscr();
{
cout<<"inner block";
int k=m;
int m=30;
cout<<"\n k="<<k;
cout<<"\n m="<<m;
cout<<"\n ::m="<<::m;
}
cout<<"\n";
cout<<"\n outer block";
cout<<"\n m="<<m;
cout<<"\n ::m="<<::m;
getch();
}

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 41
OOP(1030106301) COMPUTER ENGINEERING.

UNIT-4
10 4 Develop programs using various types of constructors and 6
destructors.

DHRUV SOJITRA
(20270106160) Page 42
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-1
AIM:-Develop C++ program using simple constructor.
#include<iostream.h>?
#include<conio.h>
class dhruv
{
int x,y;
public:
dhruv()
{
x=160;
y=1789;
}
void display()
{
cout<<"\n value of x="<<x;
cout<<"\n value of y="<<y;
}
};
int main()
{
clrscr();
dhruv d;
d.display();
getch();
return 0;
}
 OUTPUT

DHRUV SOJITRA
(20270106160) Page 43
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-2
AIM:- Develop C++ program using default constructor.
#include<iostream.h>?
#include<conio.h>
class shape
{
int l,b;
float r;
public:
shape(float r,int l,int b=10)
{
float cir,rec,squ;

cir=3.14*r*r;
cout<<"\n area of circal="<<cir;

rec=l*b;
cout<<"\n area of reactangle="<<rec;

squ=l*l;
cout<<"\n area of squre="<<squ;
}
};
int main()
{
clrscr();
shape obj(5,9);
getch();
return 0;
}

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 44
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-3
AIM:- Develop C++ program using simple constructor.
#include<iostream.h>

#include<conio.h>

class dhruv

private:

int x,y;

public:

dhruv()

x=0;

y=0;

dhruv(int a)

x=a;

y=a;

dhruv(int a, int b)

x=a;

y=b;

void show()

cout<<"\n value of x="<<x;

cout<<"\n value of y="<<y;

.cout<<"\n";

DHRUV SOJITRA
(20270106160) Page 45
OOP(1030106301) COMPUTER ENGINEERING.

};

int main()

dhruv d1,d2(30),d3(30,40);

clrscr();

d1.show();

d2.show();

d3.show();

getch();

return 0;

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 46
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-4
AIM:- Develop C++ program using copy constructor.
#include<iostream.h>

#include<conio.h>

class dhruv

private:

int x,y;

public:

dhruv()

cout<<"\n enter the value of x:";

cin>>x;

cout<<"\n enter the value of y:";

cin>>y;

dhruv(dhruv &c)

x=c.x;

y=c.y;

void setdata()

cout<<"\n x="<<x;

cout<<"\n y="<<y;

cout<<"\n";

};

void main()

DHRUV SOJITRA
(20270106160) Page 47
OOP(1030106301) COMPUTER ENGINEERING.

clrscr();

dhruv d;

d.setdata();

dhruv d2(d);

cout<<"\n copy value of dhruv's class";

d2.setdata();

getch();

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 48
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-5
AIM:- Develop C++ program using daynemic constructor.
#include<iostream.h>

#include<conio.h>

class dhruv

private:

int x,y;

char *name;

public:

dhruv()

x=0;

name new chare[x+1];

dhruv(char+y)

x=strlen(y);

name=new char[x+1]

strcpy(name,y1)

void show()

cout<<"\n name";

};

void main()

clrscr(c;

har *str;

DHRUV SOJITRA
(20270106160) Page 49
OOP(1030106301) COMPUTER ENGINEERING.

cout<<"\n enter the name:";

cin>>str;

dhruv d1(str),d2(rajubhai sojitra);

d1.show();

d2.show();

getch();

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 50
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-6
AIM:- Develop C++ program using simple destructor.
#include<iostream.h>
#include<conio.h>
int count=0;
class dhruv
{
private:
int x,y;
public:
dhruv()
{
count ++;
cout<<"\n creat object are:"<<count;
}
~dhruv()
{
cout<<"\n destucter object"<<count;
count --;
}
};

void main()
{
clrscr();
dhruv d1;
{
dhruv d2,d3,d4,d5;
}

getch();
}

DHRUV SOJITRA
(20270106160) Page 51
OOP(1030106301) COMPUTER ENGINEERING.

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 52
OOP(1030106301) COMPUTER ENGINEERING.

Develop programs using single, multilevel, multiple 6


11 5 inheritance
12 Develop programs using constructors in derived classes. 4
5

UNIT-5

DHRUV SOJITRA
(20270106160) Page 53
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-1
AIM:-Develop C++ program using Single inheritance.
#include<iostream.h>
#include<conio.h>
class worker
{
public:
int e_id;
char name[20],des[20];
// public:
void get()
{
cout<<"\n enter the employee id:";
cin>>e_id;
cout<<"\n enter the employee name:";
cin>>name;
cout<<"\n enter the desgnation:";
cin>>des;
}
};

class salary:public worker


{
private:
float bp,hra,da,pf,np;
public:

DHRUV SOJITRA
(20270106160) Page 54
OOP(1030106301) COMPUTER ENGINEERING.

void get1()
{
cout<<"\n enter the basic pay:";
cin>>bp;
cout<<"\n enter the dearess allowance:";
cin>>da;
cout<<"\n enter the human resource allowance:";
cin>>hra;
cout<<"\n enter the probitablity fund:";
cin>>pf;
}

void cal()
{
np=bp+hra+da-pf;
}

void show()
{
//cout<<"\n employee name:"<<name;
//cout<<"\n basic pay:%f dearess allowance:%f human resource
allowance:%f probitablity fund:%f"<<bp,da,hra,pf;
cout<<e_id<<"\t \t"<<name<<"\t"<<des<<"\t"<<bp<<"\
t"<<da<<"\t"<<hra<<"\t"<<pf<<"\t"<<np;
}
};

DHRUV SOJITRA
(20270106160) Page 55
OOP(1030106301) COMPUTER ENGINEERING.

void main()
{
int i,n;
// char ch;
salary s[20];
clrscr();
cout<<"\n how many add employee member:";
cin>>n;
for(i=0;i<n;i++)
{
s[i].get();
s[i].get1();
s[i].cal();
}
cout<<"\n employee_id\t name\t des\t bp\t da\t hra\t pf\t np";
cout<<"\n --------------------------------------------------------------------";
for(i=0;i<n;i++)
{
cout<<"\n";
s[i].show();
}
getch();
}

DHRUV SOJITRA
(20270106160) Page 56
OOP(1030106301) COMPUTER ENGINEERING.

 OUTPUT

PRACTICAL-2
AIM:- Develop C++ program using Multilevel inheritance.

DHRUV SOJITRA
(20270106160) Page 57
OOP(1030106301) COMPUTER ENGINEERING.

#include<iostream.h>

#include<conio.h>

class dhruv

public:

int d;

void getdata()

cout<<"\n enter the numaber:";

cin>>d;

void putdata()

cout<<"\n number is:"<<d;

};

class dhruv2:public dhruv

public:

int j;

void squre()

getdata();

j=d*d;

putdata();

cout<<"\n squre is:"<<j;

};

DHRUV SOJITRA
(20270106160) Page 58
OOP(1030106301) COMPUTER ENGINEERING.

class dhruv3:public dhruv2

public:

int c;

void qube()

squre();

c=j*d;

cout<<"\n cube is:"<<c;

};

void main()

clrscr();

dhruv3 D;

D.qube();

getch();

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 59
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-3

DHRUV SOJITRA
(20270106160) Page 60
OOP(1030106301) COMPUTER ENGINEERING.

AIM:- Develop C++ program using Multiple inheritance.


#include<iostream.h>

#include<conio.h>

class marks

protected:

int m,r_no,o,d,c,ds;

char name[20];

public:

void get()

cout<<"\n Enter the roll_no:";

cin>>r_no;

cout<<"\n enter student name:";

cin>>name;

cout<<"\n Enter the maths marks:";

cin>>m;

cout<<"\n enter the o.s.marks:";

cin>>o;

cout<<"\n enter the dbms marks:";

cin>>d;

cout<<"\n enter the c++ marks:";

cin>>c;

cout<<"\n enter the ds marks:";

cin>>ds;

};

class sports

protected:

int sm;

DHRUV SOJITRA
(20270106160) Page 61
OOP(1030106301) COMPUTER ENGINEERING.

public:

void getsm()

cout<<"\n \n Enter the sports marks:";

cin>>sm;

};

class find:public marks,public sports

protected:

int total,avg;

public:

void display()

//get();

//getsm();

total=o+d+c+m+ds+sm;

avg=total/6;

//cout<<"\n Roll no:"<<e_no;

cout<<"\n Total:"<<total;

cout<<"\n Avarege:"<<avg;

};

void main()

clrscr();

find f;

f.get();

f.getsm();

f.display();

DHRUV SOJITRA
(20270106160) Page 62
OOP(1030106301) COMPUTER ENGINEERING.

getch();

 OUTPUT

PRACTICAL-4
AIM:- Develop C++ program using hybrid inheritance .

DHRUV SOJITRA
(20270106160) Page 63
OOP(1030106301) COMPUTER ENGINEERING.

#include<iostream.h>

#include<conio.h>

class marks

protected:

int r_no,su1,su2;

char name[20];

public:

void get()

cout<<"\n Enter the roll_no:";

cin>>r_no;

cout<<"\n enter student name:";

cin>>name;

cout<<"\n enter two subject marks:";

cin>>su1>>su2;

};

class sports

protected:

int sm;

public:

void getsm()

cout<<"\n \n Enter the sports marks:";

cin>>sm;

};

class find:public marks,public sports

DHRUV SOJITRA
(20270106160) Page 64
OOP(1030106301) COMPUTER ENGINEERING.

protected:

int total,avg;

public:

void display()

//get();

//getsm();

total=su1+su2+sm;

avg=total/6;

//cout<<"\n Roll no:"<<e_no;

cout<<"\n Total:"<<total;

cout<<"\n Avarege:"<<avg;

};

void main()

clrscr();

find f;

f.get();

f.getsm();

f.display();

getch();

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 65
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-5

DHRUV SOJITRA
(20270106160) Page 66
OOP(1030106301) COMPUTER ENGINEERING.

AIM:- Develop C++ program using hybride inheritance.


#include<iostream.h>

#include<conio.h>

class dhruv

public:

dhruv()

cout<<"hello";

cout<<"\n i am dhruv sojitra";

};

class dhruv2:public dhruv

public:

dhruv2()

// dhruv();

cout<<"\n i am study in bmu";

};

class dhruv3:public dhruv2

public:

dhruv3()

//dhruv2();

cout<<"\n my enrollment number are:20270106160";

};

class manan

DHRUV SOJITRA
(20270106160) Page 67
OOP(1030106301) COMPUTER ENGINEERING.

public:

manan()

cout<<"\n hello friend.";

cout<<"\n i am manan dhruv's frnd";

};

class show:public dhruv3,public manan

public:

show()

//dhruv3();

cout<<"\n";

// manan();

};

void main()

clrscr();

show d;

getch();

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 68
OOP(1030106301) COMPUTER ENGINEERING.

DHRUV SOJITRA
(20270106160) Page 69
OOP(1030106301) COMPUTER ENGINEERING.

13 6 Develop programs using pointer to derived classes 4

14 6 Develop programs using ‘this’ keyword. 2

UNIT-6

PRACTICAL-1
AIM:- Develop programs using pointer to derived classes
include<iostream.h>

#include <conio.h>

DHRUV SOJITRA
(20270106160) Page 70
OOP(1030106301) COMPUTER ENGINEERING.

class dhruv

protected:

char d[10];

public:

void getdata()

cout<<"enter your name:";

cin>>d;

void show()

cout<<"name:"<<d;

};

class display:public dhruv

protected:

char n[13],dep[30];

public:

void getdata1()

cout<<"\n \n enter your enr_no:";

cin>>n;

cout<<"enter your department:";

cin>>dep;

void show1()

cout<<"\n er_no are:"<<n;

cout<<"\n department is:"<<dep;

DHRUV SOJITRA
(20270106160) Page 71
OOP(1030106301) COMPUTER ENGINEERING.

};

void main()

clrscr();

dhruv b1;

display d1;

dhruv *bptr;

bptr=&b1;

bptr->getdata();

bptr->show();

cout<<"\n \n call der.. class's function.";

display *dptr;

dptr=&d1;

dptr->getdata1();

dptr->show1();

getch();

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 72
OOP(1030106301) COMPUTER ENGINEERING.

PRACTICAL-2

DHRUV SOJITRA
(20270106160) Page 73
OOP(1030106301) COMPUTER ENGINEERING.

AIM:- Develop programs using ‘this’ keyword.


#include<iostream.h>
#include<conio.h>

class dhruv
{
private:
int num;
char ch;
public:
void value(int nu,char ch)
{
this->num=nu;
this->ch=ch;
}
void show()
{
cout<<num<<"\n"<<ch;
}
};

void main()
{
dhruv d;
clrscr();

d.value(60,'d');
d.show();

DHRUV SOJITRA
(20270106160) Page 74
OOP(1030106301) COMPUTER ENGINEERING.

getch();
}

 OUTPUT

PRACTICAL-3

DHRUV SOJITRA
(20270106160) Page 75
OOP(1030106301) COMPUTER ENGINEERING.

AIM:- Develop program for a pure virtual function.


#include<iostream.h>
#include<conio.h>
class Base
{
int x;
public:
virtual void fun() = 0;
};

class Derived:public Base


{
public:

void fun()
{
cout<<"*************************************"<<endl;
cout<< "Hello My Name is Dhruv sojitra"<<endl;
cout<<"*************************************";
}
};

int main(void)
{
clrscr();
Derived d;
d.fun();
getch();

DHRUV SOJITRA
(20270106160) Page 76
OOP(1030106301) COMPUTER ENGINEERING.

return 0;
}

 OUTPUT

DHRUV SOJITRA
(20270106160) Page 77
OOP(1030106301) COMPUTER ENGINEERING.

DHRUV SOJITRA
(20270106160) Page 78

You might also like