Professional Documents
Culture Documents
OOPS Manual
OOPS Manual
OOPS Manual
1
Vision of the Institute ..................................................................................................................... 3
Mission of the Institute ................................................................................................................... 3
Vision of the Department: .............................................................................................................. 4
Mission of the Department: ............................................................................................................ 4
1. Introduction to Object Oriented Programming ........................................................................... 5
Objective ............................................................................................................................... 6
Course outcomes ................................................................................................................... 6
2. LIST OF EXPERIMENTS ......................................................................................................... 7
(as per GGSIPU Syllabus) .............................................................................................................. 7
3. LIST OF EXPERIMENTS ......................................................................................................... 8
(Beyond Curricula) ......................................................................................................................... 8
4. How to Compile & Run a C++ Program .................................................................................... 9
5. FORMAT OF THE LAB RECORD TO BE PREPARED BY THE STUDENTS .................. 10
6. Experiments according to the Lab Syllabus ........................................................................... 11
7. Experiment No 1 ..................................................................................................................... 12
8. Experiment No 2 ..................................................................................................................... 15
9. Experiment No.3 ..................................................................................................................... 17
10. Experiment No.4 ..................................................................................................................... 20
11. Experiment No. 5 .................................................................................................................... 23
12. Experiment No. 6 .................................................................................................................... 32
13. Experiment No. 7 .................................................................................................................... 34
14. Experiment No. 8 .................................................................................................................... 36
15. Experiment No. 9 .................................................................................................................... 38
16. Experiment No. 10 .................................................................................................................. 40
17. Experiment No. 11 .................................................................................................................. 43
18. Experiment No. 12 .................................................................................................................. 45
19. Experiment No. 13 .................................................................................................................. 47
20. Experiment No. 14 .................................................................................................................. 49
21. Experiment No. 15 .................................................................................................................. 51
22. Experiment No. 16 .................................................................................................................. 54
23. Experiment No. 17 .................................................................................................................. 55
24. Experiment No. 18 .................................................................................................................. 59
2
Dr. Akhilesh Das Gupta Institute of Technology & Management
3
Vision of the Department:
To provide managerial and professional skills among the students through value-
added programs.
PEO5To produce graduates having willingness to learn new things and work as a
part of team for the attainment of individual and organizations
4
1. INTRODUCTION TO OBJECT ORIENTED
PROGRAMMING
Introduction
C++ is a general-purpose programming language that was developed as an enhancement of the
C language to include object-oriented paradigm. It is an imperative and a compiled language.
5
Large-scale applications can be built. Procedural code becomes difficult to maintain as
code-size grows.
Compiled Language: C++ is a compiled language, contributing to its speed.
Objective :
The prime purpose of C++ programming was to add object orientation to the C programming
language, which is in itself one of the most powerful programming languages.
The core of the pure object-oriented programming is to create an object, in code, that has certain
properties and methods.
Course Outcomes :
1. Recall all the data types and header files in C++.
2. Illustrate Function overloading, Inline function with Default argument.
3. Apply the Object Oriented Paradigm into the C++ Programming Language.
4. Test C++ codes, into various Programs.
5. Explain Class & Function for generic data.
6. Create programs using File handling.
6
2. LIST OF EXPERIMENTS
(As prescribed by G.G.S.I.P.U)
List of Experiments:
NOTE: - At least 8 Experiments out of the list must be done in the semester.
7
3. LIST OF EXPERIMENTS
(Beyond the syllabus prescribed by G.G.S.I.P.U)
List of Experiments:
1. Write a program to calculate the area of circle, rectangle, triangle & square using the
function overloading.
2. Write a program to implement the new & delete operators.
3. Write a program to implement the static data member & static member function.
4. Write a program to compute the time using passing the object as argument.
5. Write a program to sum of two complex numbers using a returning object by friend
function.
8
4. How to Compile and Run a Program on Turbo C++
There are 2 ways to compile and run the C++ program, by menu and by shortcut.
By menu
Now click on the compile menu then compile sub menu to compile the C++ program.
Then click on the run menu then run sub menu to run the C++ program.
By shortcut
Or, press ctrl+f9 keys compile and run the program directly.
You will see the following output on user screen.
You can view the user screen any time by pressing the alt+f5 keys.
Now press Esc to return to the turbo C++ console.
9
5. FORMAT OF THE LAB RECORD TO BE PREPARED BY THE STUDENTS
The front page of the lab record prepared by the students should have a cover page as displayed
below.
Roll No.
Sem.
10
6. Experiments according to the lab syllabus
11
EXPERIMENT: 1
AIM: Write a program for multiplication of two matrices using OOP.
Program:
#include <iostream.h>
intmain()
{
inta[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k;
cout<<endl
<<"Enter elements of matrix 1:"<<endl;
for (i = 0; i< r1; ++i)
for (j = 0; j < c1; ++j)
{
cout<<"Enter element a"<<i + 1<< j + 1<<" : ";
cin>> a[i][j];
}
cout<<endl
<<"Enter elements of matrix 2:"<<endl;
for (i = 0; i< r2; ++i)
12
for (j = 0; j < c2; ++j)
{
cout<<"Enter element b"<<i + 1<< j + 1<<" : ";
cin>> b[i][j];
}
cout<<endl
<<"Output Matrix: "<<endl;
for (i= 0; i< r1; ++i)
for (j = 0; j < c2; ++j)
{
cout<<" "<<mult[i][j];
if (j == c2 - 1)
cout<<endl;
}
return0;
}
13
Output:
14
EXPERIMENT: 2
AIM: Write a program to perform addition of two complex numbers using constructor overloading. The
first constructor which takes no argument is used to create objects which are not initialized, second which
takes one argument is used to initialize real and imag parts to equal values and third which takes two
argument is used to initialized real and imag to two different values.
Program:
#include<iostream.h>
class Complex {
public:
int real, imaginary;
Complex()
{
}
Complex(inttempReal, inttempImaginary)
{
real = tempReal;
imaginary = tempImaginary;
}
Complex addComp(Complex C1, Complex C2)
{
Complex temp;
returntemp;
}
};
intmain()
{
15
cout<<"Complex number 1 : "<< C1.real
<<" + i"<< C1.imaginary<<endl;
Complex C3;
C3 = C3.addComp(C1, C2);
cout<<"Sum of complex number : "
<< C3.real<<" + i"
<< C3.imaginary;
}
Output:
16
EXPERIMENT: 3
AIM: Write a program to find the greatest of two given numbers in two different classes using friend
function.
Program:
#include <iostream.h>
class second;
class first
intx;
public:
voidgetx()
cin>>x;
}
friendvoidmax(first, second);
};
class second
inty;
public:
voidgety()
17
cout<<"\nEnter the value of y:";
cin>>y;
}
friendvoidmax(first, second);
};
voidmax(first a, second b)
if (a.x>b.y)
else
intmain()
first a;
second b;
a.getx();
b.gety();
max(a, b);
18
}
Output:
19
EXPERIMENT: 4
Program:
#include <iostream.h>
#include <string.h>
class strings
{
public:
string s;
strings()
{
}
strings(string v)
{
s = v;
}
strings operator+(strings s1)
{
strings m;
m.s = s + s1.s;
returnm;
}
strings operator=(strings s1)
{
strings o;
s = s1.s;
returno;
}
string operator<=(strings s1)
{
if (s.length() > s1.s.length())
{
20
return s + ">" + s1.s;
}
if (s.length() < s1.s.length())
{
return s + "<" + s1.s;
}
else
{
return s + "=" + s1.s;
}
}
intlen()
{
returns.length();
}
chartolower(char c)
{
return c + 32;
}
chartoupper(char c)
{
return c - 32;
}
};
intmain()
{
strings s("Iron"), g("Man"), n;
cout<<"Concatenated string: "<< (s + g).s<<endl;
n = s;
cout<<"Copied string: "<<n.s<<endl;
cout<<"Comparison strings: "<< (s <= g) <<endl;
cout<<"Length of string \""<<n.s<<"\": "<<n.len() <<endl;
cout<<"Uppercase to lowercase: "<<s.tolower('I') <<endl;
cout<<"Lowercase to uppercase: "<<s.toupper('m') <<endl
<<endl;
return0;
}
21
Output:
22
EXPERIMENT: 5
AIM: Create a class called LIST with two pure virtual function store() and retrieve().To store a value call
store and to retrieve call retrieve function. Derive two classes stack and queue from it and override store
and retrieve.
Program:
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
using namespace std;
struct node
{
int data;
node *next;
};
node *head=NULL,*tail=NULL;
class List
{
public:
void view()
{
node *n = head;
if(head==NULL)
{
cout<<"\n No elements found...";
}
else
{
cout<<" ";
while(n!=NULL)
{
if(n->next==NULL)
{
cout<<n->data;
}
else
{
cout<<n->data<<"->";
}
n = n->next;
}
}
}
virtual void store(int n)=0;
virtual int retrive()=0;
};
23
class Stack :public List
{
public:
void store(int n)
{
node *n1 = new node();
n1->data = n;
n1->next=NULL;
if((head==NULL)&&(tail==NULL))
{
head = n1;
tail = n1;
}
else
{
tail->next = n1;
tail = n1;
}
}
int retrive()
{
if((tail==NULL)&&(head==NULL))
{
return -1;
}
else
{
int n = tail->data;
node *n1 = head;
while((n1->next!=tail)&&(head!=tail))
{
n1 = n1->next;
}
n1->next = NULL;
free(tail);
if(head!=tail)
{
tail = n1;
}
else
{
tail=NULL;
head=NULL;
}
return n;
}
}
};
24
node *n1 = new node();
n1->data = n;
n1->next=NULL;
if((head==NULL)&&(tail==NULL))
{
head = n1;
tail = n1;
}
else
{
tail->next = n1;
tail = n1;
}
}
int retrive()
{
if((tail==NULL)&&(head==NULL))
{
return -1;
}
else
{
int n = head->data;
if(head==tail)
{
head = tail = NULL;
}
else
{
head = head->next;
}
return n;
}
}
};
int main()
{
Stack s1;
int ch;
while(1)
{
system("cls");
cout<<"\n\n Program to implement stack and queue using pure virtual functions
store and retrieve";
cout<<"\n ^^^^^^^ ^^ ^^^^^^^^^ ^^^^^ ^^^ ^^^^^ ^^^^^ ^^^^ ^^^^^^^ ^^^^^^^^^ ^^
^^^ ^^^ ^^^^^^^^";
cout<<"\n\n Menu";
cout<<"\n ^^^^";
cout<<"\n\n 1. Stack";
cout<<"\n 2. Queue";
cout<<"\n 3. Exit";
cout<<"\n\n Enter your choice - ";
cin>>ch;
if(ch==1)
25
{
Stack s1;
int ch1;
while(1)
{
system("cls");
cout<<"\n\n Stack Menu";
cout<<"\n ^^^^^ ^^^^";
cout<<"\n 1. Push Element";
cout<<"\n 2. Pop Element";
cout<<"\n 3. View Stack";
cout<<"\n 4. Exit";
cout<<"\n\n Enter your choice - ";
cin>>ch1;
if(ch1==1)
{
int element;
cout<<"\n Enter the element you want to push - ";
cin>>element;
s1.store(element);
cout<<"\n Element Pushed";
}
else if(ch1==2)
{
int element=0;
element = s1.retrive();
if(element==-1)
{
cout<<"\n Stack is Empty";
}
else
{
cout<<"\n Element Popped = "<<element;
}
}
else if(ch1==3)
{
cout<<"\n Elements in stack from bottom to top:- ";
s1.view();
}
else if(ch1==4)
{
break;
}
else
{
cout<<"\n\n Wrong choice";
}
getch();
}
}
else if(ch==2)
{
Queue q1;
int ch1;
26
while(1)
{
system("cls");
cout<<"\n\n Queue Menu";
cout<<"\n ^^^^^ ^^^^";
cout<<"\n 1. Push Element";
cout<<"\n 2. Pop Element";
cout<<"\n 3. View Queue";
cout<<"\n 4. Exit";
cout<<"\n\n Enter your choice - ";
cin>>ch1;
if(ch1==1)
{
int element;
cout<<"\n Enter the element you want to push - ";
cin>>element;
q1.store(element);
cout<<"\n Element Pushed";
}
else if(ch1==2)
{
int element=0;
element = q1.retrive();
if(element==-1)
{
cout<<"\n Queue is Empty";
}
else
{
cout<<"\n Element Popped = "<<element;
}
}
else if(ch1==3)
{
cout<<"\n Elements in queue from front to rear:- ";
q1.view();
}
else if(ch1==4)
{
break;
}
else
{
cout<<"\n\n Wrong choice";
}
getch();
}
}
else if(ch==3)
{
exit(0);
}
else
{
cout<<"\n\n Wrong Choice";
27
}
getch();
}
return 0;
}
Output:
Program to implement stack and queue using pure virtual functions store
and retrieve
^^^^^^^ ^^ ^^^^^^^^^ ^^^^^ ^^^ ^^^^^ ^^^^^ ^^^^ ^^^^^^^ ^^^^^^^^^ ^^^^^
^^^ ^^^^^^^^
Menu
^^^^
1. Stack
2. Queue
3. Exit
Stack Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Stack
4. Exit
Element Pushed
Stack Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Stack
4. Exit
Element Pushed
Stack Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Stack
4. Exit
28
Enter the element you want to push - 3
Element Pushed
Stack Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Stack
4. Exit
Stack Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Stack
4. Exit
Program to implement stack and queue using pure virtual functions store
and retrieve
^^^^^^^ ^^ ^^^^^^^^^ ^^^^^ ^^^ ^^^^^ ^^^^^ ^^^^ ^^^^^^^ ^^^^^^^^^ ^^^^^
^^^ ^^^^^^^^
Menu
^^^^
1. Stack
2. Queue
3. Exit
Queue Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Queue
4. Exit
Queue Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Queue
29
4. Exit
Element Popped = 1
Queue Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Queue
4. Exit
Queue Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Queue
4. Exit
Program to implement stack and queue using pure virtual functions store
and retrieve
^^^^^^^ ^^ ^^^^^^^^^ ^^^^^ ^^^ ^^^^^ ^^^^^ ^^^^ ^^^^^^^ ^^^^^^^^^ ^^^^^
^^^ ^^^^^^^^
Menu
^^^^
1. Stack
2. Queue
3. Exit
Stack Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Stack
4. Exit
Stack Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
30
3. View Stack
4. Exit
Element Popped = 3
Stack Menu
^^^^^ ^^^^
1. Push Element
2. Pop Element
3. View Stack
4. Exit
31
EXPERIMENT: 6
AIM: Write a program to define the function template for calculating the square of given numbers with
different data types.
Tool Required : Turbo C++
Program:
#include <iostream.h>
template<class T>
inline T square(T x)
{
T result;
result = x * x;
returnresult;
};
intmain()
{
inti, ii;
float x, xx;
double y, yy;
i = 2;
x = 2.2;
y = 2.2;
ii = square<int>(i);
cout<<i<<": "<< ii <<endl;
xx = square<float>(x);
cout<< x <<": "<< xx <<endl;
yy = square<double>(y);
cout<< y <<": "<<yy<<endl;
yy = square(y);
cout<< y <<": "<<yy<<endl;
return0;
}
32
Output:
33
EXPERIMENT: 7
AIM: Write a program to demonstrate the use of special functions, constructor and destructor in the class
template. The program is used to find the bigger of two entered numbers.
Program:
#include <iostream.h>
template<class T>
inline T square(T x)
{
T result;
result = x * x;
returnresult;
};
intmain()
{
inti, ii;
float x, xx;
double y, yy;
i = 2;
x = 2.2;
y = 2.2;
ii = square<int>(i);
cout<<i<<": "<< ii <<endl;
xx = square<float>(x);
cout<< x <<": "<< xx <<endl;
yy = square<double>(y);
cout<< y <<": "<<yy<<endl;
yy = square(y);
cout<< y <<": "<<yy<<endl;
return0;
}
34
Output:
35
EXPERIMENT: 8
AIM: Write a program to perform the deletion of white spaces such as horizontal tab, vertical tab, space
,line feed ,new line and carriage return from a text file and store the contents of the file without the white
spaces on another file.
Program:
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void main()
{
clrscr();
fstream file1;
fstream file2;
char ch;
file1.open("data1.txt",ios::out);
do
{
cin.get(ch);
file1.put(ch);
}while(ch!=EOF);
file1.close();
cout<<"\nData written successfully...\n";
file1.open("data1.txt",ios::in);
file2.open("data2.txt",ios::out);
while(!file1.eof())
{
file1.get(ch);
if(ch!=' ')
file2.put(ch);
}
file1.close();
file2.close();
file2.open("data2.txt",ios::in);
while(!file2.eof())
{
file2.get(ch);
cout<<ch;
}
file2.close();
getch();
}
36
Output:
37
EXPERIMENT: 9
AIM: Write a program to read the class object of student info such as name , age ,sex ,height and weight
from the keyboard and to store them on a specified file using read() and write() functions. Again the same
file is opened for reading and displaying the contents of the file on the screen.
Program:
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
class student
{
private:
char name[30];
int age;
char sex[10];
float height;
float weight;
public:
void getData(void)
{ cout<<"Enter name:";
cin>>name;
cout<<"Enter age:";
cin>>age;
cout<<"Enter Sex (Male/Female):";
cin>>sex;
cout<<"Enter Height in cm.:";
cin>>height;
cout<<"Enter weight in Kg.:";
cin>>weight;
}
void showData(void)
{
cout<<"Name:"<<name<<endl;
cout<<"Age:"<<age<<endl;
cout<<"Sex:"<<sex<<endl;
cout<<"Height:"<<height<<endl;
cout<<"Weight:"<<weight<<endl;
}
};
void main()
{
clrscr();
student s;
ofstream file;
file.open("Data.txt",ios::out);
s.getData();
file.write((char*)&s,sizeof(s));
file.close();
cout<<"\nFile saved and closed succesfully."<<endl;
38
ifstream file1;
file1.open("Data.txt",ios::in);
file1.read((char*)&s,sizeof(s));
s.showData();
file1.close();
getch();
}
Output:
39
EXPERIMENT: 10
AIM: Write a program to calculate the area of circle, rectangle, triangle & square using the function
overloading.
Program:
#include<iostream.h>
#include<math.h>
#include<conio.h>
doubleconst pi=3.141592;
floatarea(float a)
{
return a*a;
}
floatarea(float l, float b)
{
return l*b;
}
intmain()
{
intop;
floatar, a,b,c;
40
cout<<"AREA CALCULATOR\n";
cout<<"1. SQUARE \t2. RECTANGLE \t3. TRIANGLE \t4. CIRCLE \n0. EXIT \n";
do
{
cout<<"\nMENU OPTION: ";
cin>>op;
switch(op)
{
case1: cout<<"Enter Side: ";
cin>>a;
ar=area(a);
break;
case2: cout<<"Enter Length & Breadth: ";
cin>>a>>b;
ar=area(a,b);
break;
case3: cout<<"Enter 3 sides: ";
cin>>a>>b>>c;
ar=area(a,b,c);
break;
case4: cout<<"Enter radius: ";
cin>>a;
ar=area(pi,a);
break;
case0: break;
default: cout<<"Invalid Entry. Try Again\n";
}
if((op>0)&&(op<5))
{ cout<<"Area : "<<ar<<endl;
getch();
}
}while(op>0);
return0;
}
41
Output:
42
EXPERIMENT: 11
Program:
#include <iostream.h>
#include <string.h>
int main()
{
int *ptr = NULL;
ptr = newint();
int *var = newint(12);
if(!ptr)
{
cout<<"bad memory allocation"<<endl;
}
else
{
cout<<"memory allocated successfully"<<endl;
*ptr = 10;
cout<<"*ptr = "<<*ptr<<endl;
cout<<"*var = "<<*var<<endl;
}
43
deletevar;
delete[]myarray;
return0;
Output:
44
EXPERIMENT: 12
AIM: Write a program to implement the static data member & static member function.
Program:
#include <iostream.h>
#include <string.h>
usingnamespacestd;
class Student
{
private:
introllNo;
charname[10];
intmarks;
public:
staticintobjectCount;
Student()
{
objectCount++;
}
voidgetdata()
{
cout<<"Enter roll number: "<<endl;
cin>>rollNo;
cout<<"Enter name: "<<endl;
cin>>name;
cout<<"Enter marks: "<<endl;
cin>>marks;
}
voidputdata()
{
cout<<"Roll Number = "<<rollNo<<endl;
cout<<"Name = "<< name <<endl;
cout<<"Marks = "<< marks <<endl;
45
cout<<endl;
}
};
intStudent::objectCount = 0;
int main(void)
{
Student s1;
s1.getdata();
s1.putdata();
Student s2;
s2.getdata();
s2.putdata();
Student s3;
s3.getdata();
s3.putdata();
cout<<"Total objects created = "<<Student::objectCount<<endl;
return0;
}
Output:
46
EXPERIMENT: 13
AIM: Write a program to compute the time using passing the object as argument.
Program:
#include<iostream.h>
#include<conio.h>
class time
{
int hour,min;
public:
void get()
{
cout<<"Enter Hour & Minute :\n";
cin>>hour>>min;
}
void put()
{
cout<<hour<<"Hour and "<<min<<" Minute\n";
}
void sum(time t1, time t2)
{
time t3;
min=t1.min+t2.min;
hour=min/60;
min=min%60;
hour=hour+t1.hour+t2.hour;
}
};
void main()
{
time s1,s2,s3;
clrscr();
s1.get();
s2.get();
47
s3.sum(s1,s2);
s1.put();
s2.put();
s3.put();
getch();
}
Output:
48
EXPERIMENT: 14
AIM: Write a program to sum of two complex numbers using a returning object by friend function.
Program:
#include <iostream.h>
class complex
public:
voidset()
{
cout<<"Enter real and imagpart : ";
voiddisplay();
};
voidcomplex::display()
49
complex t;
returnt;
}
intmain()
complex a, b, c;
a.set();
b.set();
c = sum(a, b);
c.display();
return (0);
}
Output:
50
EXPERIMENT: 15
Program:
#include <iostream.h>
#include <stdio.h>
#include <string.h>
usingnamespacestd;
class bank
{
intacno;
charnm[100], acctype[100];
floatbal;
public:
bank(intacc_no, char*name, char*acc_type, float balance)
{
acno = acc_no;
strcpy(nm, name);
strcpy(acctype, acc_type);
bal = balance;
}
voiddeposit();
voidwithdraw();
voiddisplay();
51
};
voidbank::deposit()
{
intdamt1;
cout<<"\n Enter Deposit Amount = ";
cin>>damt1;
bal += damt1;
}
voidbank::withdraw()
{
intwamt1;
cout<<"\n Enter Withdraw Amount = ";
cin>>wamt1;
if (wamt1 >bal)
cout<<"\n Cannot Withdraw Amount";
bal -= wamt1;
}
voidbank::display()
{
cout<<"\n ----------------------";
cout<<"\n AccoutNo. : "<<acno;
cout<<"\n Name : "<< nm;
cout<<"\n Account Type : "<<acctype;
cout<<"\n Balance : "<<bal;
}
intmain()
{
intacc_no;
charname[100], acc_type[100];
floatbalance;
cout<<"\n Enter Details: \n";
cout<<"-----------------------";
cout<<"\n Accout No. ";
cin>>acc_no;
cout<<"\n Name : ";
cin>>name;
cout<<"\n Account Type : ";
cin>>acc_type;
cout<<"\n Balance : ";
cin>>balance;
52
bank b1(acc_no, name, acc_type, balance);
b1.deposit();
b1.withdraw();
b1.display();
return0;
}
Output:
53
EXPERIMENT: 16
Program:
#include <iostream.h>
class BaseClass
{
public:
BaseClass()
{
cout<<"Constructor of the BaseClass : Object Created"<<endl;
}
~BaseClass()
{
cout<<"Destructor of the BaseClass : Object Destroyed"<<endl;
}
};
intmain()
{
BaseClassdes;
return0;
}
Output:
54
EXPERIMENT: 17
Program:
#include <iostream.h>
#include <process.h>
class person
{
protected:
charname[20];
intcode;
public:
voidgetcode()
{
cout<<"\n Enter the code ";
cin>>code;
}
voidgetname()
{
cout<<"\n Enter the name ";
cin>>name;
}
};
classaccount :virtualpublic person
{
protected:
intpay;
55
public:
voidgetpay()
{
cout<<"\n Enter the payment ";
cin>>pay;
}
};
classadmin :virtualpublic person
{
protected:
intexp;
public:
voidgetexp()
{
cout<<"\n Enter the experiance";
cin>>exp;
}
};
classmaster :public account, public admin
{
public:
voidgetdata()
{
getcode();
getname();
getpay();
getexp();
}
voidupdate()
{
intc;
cout<<"\n You want 2 update\n1.code\n2.name\n3.payment\n4.experiance";
cout<<"\nEnterur choice ";
cin>>c;
switch (c)
{
case1:
getcode();
break;
56
case2:
getname();
break;
case3:
getpay();
break;
case4:
getexp();
break;
default:
cout<<"\n Invalid choice";
}
}
voidputdata()
{
cout<<"\nDetails";
cout<<"\n Code "<< code <<"\n Name "<<name;
cout<<"\n Payment "<< pay <<"\n Experiance "<<exp;
cout<<"\nPress any key 2 continue ";
}
};
intmain()
{
intch;
master m;
while (1)
{
cout<<"\nMENU\n1.Create\n2.Update\n3.Display\n4.Exit";
cout<<"\nEnterur choice ";
cin>>ch;
switch (ch)
{
case1:
m.getdata();
break;
case2:
m.update();
break;
case3:
m.putdata();
break;
57
case4:
exit(0);
default:
cout<<"\n Invalid choice";
}
}
}
Output:
58
EXPERIMENT: 18
Program:
#include <iostream.h>
class Base
{
private:
intm_id;
public:
Base(int id = 0)
: m_id{id}
{
}
public:
Derived(double cost = 0.0, int id = 0)
: Base{id},
m_cost{cost}
{
}
intmain()
{
Derived derived{1.3, 5};
59
std::cout<<"Id: "<<derived.getId() <<'\n';
std::cout<<"Cost: "<<derived.getCost() <<'\n';
return0;
}
Output:
60