DCO-312 Practical File10
DCO-312 Practical File10
(DCO-312)
Submitted to:
Dr. Sunil & Ms. Farah Jamal Ansari
Assistant Professor
Submitted by
Student Name SHAYAN AHSAN
Roll No.:20DCS048
Semester: III SEMESTER
PRACTICAL DETAILS
Practical Practical Name Date of Date of Marks/ Teacher’s
No. Performance Checking Grades Signature
1. 9th Sept,2021
WRITE PROGRAMS IN
C++ TO IMPLEMENT
VARIOUS CONTROL
STATEMENTS
2. Write the C++ programs to 23rdSept,202
understand Structure 1
3. Write the C++ program to 23rd
understand functions Sept,2021
4. Write a program in C++ to 23rd Oct,2021
Understand Pointer
Arithmetic
5. Write Programs in C++ to 29th
Understand different
Sept,2021
function call mechanism.
a. Call by Value b. Call
by reference
6. Write a program in C++ to 29th
understand classes and Sept,2021
objects
7. Write a program in C++ to 20th Oct,2021
understand inline function.
8. Write a program in C++ to 20th Oct,2021
understand Constructors &
Destructors.
9. Write a program in C++ 20th Oct,2021
using classes to
demonstrate the Use of
“this” Pointer.
10. Write Programs in C++ to 14thNov,202
Implement all types of 1
Inheritance.
11.
12.
15.
PROGRAM 13: To Understand TYPES of INHERITANCE
A.Single Inheritance
INPUT
//Single inheritance
#include<iostream>
using namespace std;
class A{ //base class
int a;
int b;
public:
int mul()
{
cout<<"\n Enter value of a & b: ";
cin>>a>>b;
int c= a*b;
return c;}
};
class B: public A //derived class
{public:
void display()
{int result = mul();
cout <<"\n Multiplication of a and b is : "<<result;
}
};
int main()
{
B b;
b.display();
return 0;
}
OUTPUT
b.Multilevel Inheritance
INPUT
#include<iostream>
#include<conio.h>
using namespace std;
class base //single base class
{ public:
int x;
void getdata()
{cout << "Enter value of x= ";
cin >> x;
}
};
OUTPUT
Enter value of x and y:
4
6
Product=24
Enter value of x and y:
4
6
Sum=10
D.MULTIPLE INHERITANCE
INPUT
//Multiple Inheritance
#include<iostream>
#include<conio.h>
using namespace std;
class A
{ public:
int x;
void getx(){ cout << "enter value of x: ";
cin >> x;
}
};
class B
{ public:
int y;
void gety()
{cout << "enter value of y: ";
cin >> y;
}
};
class C: public A, public B //C is derived from class A and class B
{ public:
void sum()
{cout << "Sum = " << x + y;
}
};
int main(){
C obj; //object of derived class C
obj.getx();
obj.gety();
obj.sum();
getch();
return 0;
}
OUTPUT
enter value of x: 4
enter value of y: 5
Sum = 9
E.HYBRID/VIRTUAL INHERITANCE
INPUT
#include<iostream>
#include<conio.h>
using namespace std;
public:
int length;
void Ab(){
cout<<"Enter the value of the length ="<<endl;
cin>>length;
}
};
class B{ //base class
public:
int breadth;
void Ba(){
cout<<"Enter the value of breadth = "<<endl;
cin>>breadth;
}
};
class C:public A,public B{
public:
int Sum=length+breadth;
void S(){
cout<<"Sum of length and breadth is "<<Sum;
}
};
class D:public C{
public:
int height;
void lateralSurfaceAreaofCuboid(){
int lateraArea=2*(Sum)*height;
}
};
int main(){
A EnterLENGTH;
EnterLENGTH.Ab();
B EnterBREADTH;
EnterBREADTH.Ba();
C obj3;
obj3.S();
D lateralArea;
lateralArea.lateralSurfaceAreaofCuboid();
getch();
return 0;
}
OUTPUT