Blank (!)
Blank (!)
PRACTICAL FILE OF
OBJECT ORIENTED PROGRAMMING
(PCC-CSE-208G)
1 Write a program that uses a Class where the member functions are 3
defined inside a class
2 Write a program that uses a Class where the member functions are 4
defined outside a class
19 adding one object of class DM with another object of class DB: 22-23
20 Class Master derive from classes account and admin which turn derive 24-25
from class person
OUTPUT
PROGRAM.2
Write a program that uses a Class where the member functions are defined outside a class
[Classes and Objects]
OUTPUT
PROGRAM.3
Write a program to demonstrate the use of static data members
[Classes & Objects]
OUTPUT
.
PROGRAM .4
Write a program to demonstrate the use of const data members.
[Classes & Objects]
OUTPUT
PROGRAM.5
Write a program to demonstrate the use of parameterized constructor
[Constructors & Destructors]
OUTPUT
PROGRAM.6
Write a program to demonstrate the use of dynamic constructor.
[Constructors & Destructors]
OUTPUT
PROGRAM.7
Write a program to demonstrate the use of explicit constructor.
[Constructors & Destructors]
OUTPUT
PROGRAM.8
Write a program to demonstrate the use of Initializer List.
[Initializer Lists]
OUTPUT
PROGRAM.9
Write a program to demonstrate the overloading of increment and decrement operators.
[Operator Overloading]
OUTPUT
PROGRAM.10
Write a program to demonstrate the overloading of binary arithmetic operators.
[Operator Overloading]
OUTPUT
PROGRAM.11
Write a program to demonstrate the overloading of Memory management operators.
[Operator Overloading]
OUTPUT
PROGRAM.12
Write a program to demonstrate the multilevel inheritance
[Inheritance]
OUTPUT
PROGRAM.13
Write a program to demonstrate the multiple inheritance.
[Inheritance]
OUTPUT
PROGRAM.14
Write a program to demonstrate virtual derivation of a Class
[Inheritance]
OUTPUT
PROGRAM.15
Write a program to demonstrate the runtime polymorphism.
[Polymorphism]
OUTPUT
PROGRAM.16
Write a program to demonstrate the exception handling
[Exception Handling]
OUTPUT
PROGRAM.17
Write a program to demonstrate the use of function templates
[ Templates and Generic Programming]
OUTPUT
PROGRAM.18
Write a program to demonstrate the use of class templates
[Templates and Generic Programming]
OUTPUT
Program 19 :
Write a program that read values for class objects and add one
object of class DM with another object of class DB:
#include<iostream>
using namespace std;
class DB;
class DM{
int value1,value2;
public:
DM(int v1,int v2){
value1 = v1;
value2 = v2;
}
void display(){
cout<<value1<<"m "<< value2<<"cm"<<endl;
}
friend DM addition(DM,DB);
};
class DB{
int value3,value4;
public:
DB(int v3,int v4){
value3 = v3;
value4 = v4;
}
void show(){
cout<<value3<<"feet "<<value4<<"inch "<<endl;
}
friend DM addition(DM,DB);
};
DM addition(DM obj1, DB obj2){
int add;
add = (obj1.value1*100+obj1.value2)+(obj2.value3*12+obj2.value4)*2.54;
int value1,value2;
#include<iostream>
using namespace std;
class person{
protected:
string name;
int code;
public:
void getdata(string n,int c){
name = n;
code = c;
}
};
class Account:public person{
protected:
int pay;
public:
void getvalue(int p){
pay = p;
}
};
class Admin{
protected:
int experience;
public:
void input(){
cout<<"\nenter real and imaginary part of complex number: ";
cin>>real;
cin>>img;
}
complex operator -(complex c2){
complex temp;
temp.real = real-c2.real;
temp.img = img - c2.img;
return temp;
}
complex operator +(complex c2){
complex temp;
temp.real = real+c2.real;
temp.img = img + c2.img;
return temp;
}
void output(){
if(img < 0){
cout<<"The resulted complex number is "<<real<<img<<"i"<<endl;
}
else{
cout<<"The resulted complex number is: "<<real<<"+"<<img<<"i"<<endl;
}
}
};
int main(){
complex c1,c2,result, sumofcomp;
cout<<"Enter first complex number ";
c1.input();
cout<<"Enter second complex number ";
c2.input();
sumofcomp =c1+c2;//added
sumofcomp.output();
result = c1-c2;
result.output();
}
Program 22: Program for zeneric class:
#include<iostream>
using namespace std;
#include <iostream>
#include <string>
using namespace std;
template <class T>
class Stack
{
public:
Stack();
void push(T i);
T pop();
private:
int top;
T st[2];
};