0% found this document useful (0 votes)
12 views51 pages

Oops Code

The document contains various C++ class discussion programs that illustrate concepts such as class creation, object instantiation, member functions, and access modifiers. It includes examples of constructors, destructors, friend functions, inheritance, and static data members, along with sample code for each concept. Additionally, there are class activities and assignment questions designed to reinforce understanding of these topics.

Uploaded by

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

Oops Code

The document contains various C++ class discussion programs that illustrate concepts such as class creation, object instantiation, member functions, and access modifiers. It includes examples of constructors, destructors, friend functions, inheritance, and static data members, along with sample code for each concept. Additionally, there are class activities and assignment questions designed to reinforce understanding of these topics.

Uploaded by

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

Classes and objects :class discussion programs

1. Program on Creation of 2. Initialize and Display data


simple class structure(Single through methods.
student) #include <iostream>
#include <iostream> using namespace std;
using namespace std;
class Student
class Student {
{ public:
public: int id;//data member (also instance
int id;//data member (also variable)
instance variable) string name;//data member(also
string name;//data instance variable)
member(also instance variable)
}; void insert(int i, string n)
int main() {
{ id = i;
Student s1; //creating an name = n;
object of Student }
s1.id = 201;
s1.name = "Lahari"; void display()
cout<<s1.id<<endl; {
cout<<s1.name<<endl; cout<<id<<"
return 0; "<<name<<endl;
} }
};

int main()
{
Student s1; //creating an object of
Student
Student s2; //creating an object of
Student
s1.insert(201, "Sonoo");
s2.insert(202, "Nakul");
s1.display();
s2.display();
return 0;
}
Class Activity1:
1. Nihal is trying to calculate the area
and volume of the rectangular room
help Nihal to write a cpp program to
calculate the roomarea and volume
with the help of valid data members
and member functions.

Program:
// Program to illustrate the working of
// objects and class in C++ Programming

#include <iostream>
using namespace std;

// create a class
class Room {

public:
double length;
double breadth;
double height;

double calculateArea() {
return length * breadth;
}

double calculateVolume() {
return length * breadth * height;
}
};

int main() {

// create object of Room class


Room room1;

// assign values to data members


room1.length = 42.5;
room1.breadth = 30.8;
room1.height = 19.2;

// calculate and display the area and


volume of the room
cout << "Area of Room = " <<
room1.calculateArea() << endl;
cout << "Volume of Room = " <<
room1.calculateVolume() << endl;

return 0;
}
Assignment questions
1. 1. C++ program to read time in 2. Define a class to represent a bank account.
HH:MM:SS format and convert into Include the following members:
total seconds using class. Data members
1. Name of the depositor
2. Account number
3. Type of account
4. Balance amount in the
account
Member functions
1. To assign initial values
2. To deposit an amount
3. To withdraw an amount
after checking the balance
4. To display name and
balance
Write a main program to test the
program.

3. Modify the program 2 for handling 10 4. Write a class to represent a vector (a


customers. series of float values).Include
member functions to perform the
following tasks.
a) To create the vector
b) To modify the value of a
given element
c) To multiply by a scalar
value
d) To display the vector in the
form (10, 20, 30,…)
Write a program to test your class.

Chapter2:class discussion programs


1. Scope resolution operator in 2. Scope resolution operator in
C++ C++
#include <iostream> #include <iostream>
using namespace std; using namespace std;
class Game
char c = 'a'; // global variable {
(accessible to all functions) public:
void play(); // Function
int main() declaration
{ };
char c = 'b'; // local variable
(accessible only in main function) // function definition outside the class

cout << "Local variable: " << c << "\ void Game::play()
n"; {
cout << "Global variable: " << ::c << cout << "Function defined outside the
"\n"; // Using scope resolution operator class.\n";
}
return 0;
} int main()
{
Game g;
g.play();

return 0;
}
3. // C++ program to 4. C++ program to demonstrate
demonstrate public private
// access modifier // access modifier

#include<iostream> #include<iostream>
using namespace std; using namespace std;

// class definition class Circle


class Circle {
{ // private data member
public: private:
double radius; double radius;

double compute_area() // public member function


{ public:
return double compute_area()
3.14*radius*radius; { // member function can
} access private
// data member
}; radius
return
// main function 3.14*radius*radius;
int main() }
{
Circle obj; };

// accessing public datamember // main function


outside class int main()
obj.radius = 5.5; {
// creating object of the class
cout << "Radius is: " << Circle obj;
obj.radius << "\n";
cout << "Area is: " << // trying to access private data
obj.compute_area(); member
return 0; // directly outside the class
} obj.radius = 1.5;

cout << "Area is:" <<


obj.compute_area();
return 0;
}

5. C++ program to demonstrate 7. C++ program to demonstrate


private access modifier protected access modifier
#include <bits/stdc++.h>
#include<iostream> using namespace std;
using namespace std;
// base class
class Circle class Parent
{ {
// private data member // protected data members
private: protected:
double radius; int id_protected;

// public member function };


public:
void compute_area(double // sub class or derived class
r) class Child : public Parent
{ // member function can {
access private
// data member
radius public:
radius = r; void setId(int id)
{
double area =
3.14*radius*radius; // Child class is able to
access the inherited
cout << "Radius is: // protected data
" << radius << endl; members of base class
cout << "Area is: "
<< area; id_protected = id;
}
}
};
void displayId()
// main function {
int main() cout << "id_protected is: "
{ << id_protected << endl;
// creating object of the class }
Circle obj; };

// trying to access private data // main function


member int main() {
// directly outside the class
obj.compute_area(1.5); Child obj1;
return 0;
} // member function of the
derived class can
// access the protected data
members of the base class

obj1.setId(81);
obj1.displayId();
return 0;
}

Class Activity
1. Wrt a cpp program to create a class KLETECH employee with private data member
as a salary and public member functions as getsalary and setsalary. Read the salary at
compile time and print.
#include <iostream>
using namespace std;

class Employee {
private:
// Private attribute
int salary;
public:
// Setter
void setSalary(int s) {
salary = s;
}
// Getter
int getSalary() {
return salary;
}
};

int main() {
Employee myObj;
myObj.setSalary(50000);
cout << myObj.getSalary();
return 0;
}

Class Conduction programs


1. Default Constructor 2.Parameterised
1. #include <iostream> constructor
2. using namespace std; #include <iostream>
3. class Employee using namespace std;
4. { class Employee {
5. public: public:
6. Employee() int id;//data member (also
instance variable)
7. {
string name;//data
8. cout<<"Default Constructor Invoke
member(also instance variable)
d"<<endl;
float salary;
9. } Employee(int i, string n, float s)
}; {
10.int main(void) id = i;
{ name = n;
11. Employee e1; //creating an object of Em salary = s;
ployee }
12. Employee e2; void display()
13. return 0; {
14.} cout<<id<<"
"<<name<<" "<<salary<<endl;
}
};
int main(void) {
Employee e1 =Employee(101,
"Sonoo", 890000); //creating an
object of Employee
Employee e2=Employee(102,
"Nakul", 59000);
e1.display();
e2.display();
return 0;
}
Output:
101 Sonoo 890000
102 Nakul 59000

3.copy 4. Destructors
#include <iostream> #include <iostream>
using namespace std; using namespace std;
class A class Employee
{ {
public: public:
int x; Employee()
A(int a) // parameterized const {
ructor. cout<<"Constructor Invoked
{ "<<endl;
x=a; }
} ~Employee()
A(A &i) // copy constructor {
{ cout<<"Destructor Invoked"
x = i.x; <<endl;
} }
}; };
int main() int main(void)
{ {
A a1(20); // Calling the paramete Employee e1; //creating an object
rized constructor. of Employee
A a2(a1); // Calling the copy con Employee e2; //creating an object
structor. of Employee
cout<<a2.x; return 0;
return 0; }
}

4. Nested classes: nesting of member


functions

using namespace std;


class set
{
int m,n;
public:
void input();
void display();
int largest();
};
int set :: largest()
{
if(m >= n)
return(m);
else
return(n);
}
void set :: input()
{
cout << "Input value of m and n"<<"\n";
cin >> m>>n;
}
void set :: display()
{
cout << "largest value=" << largest() <<"\
n";
}

int main()
{
set A;
A.input();
A.display();

return 0;
}

Class Activity
Static data members
#include <iostream>
#include<string.h>

using namespace std;


class Student {
private:
int rollNo;
char name[10];
int marks;
public:
static int objectCount;
Student() {
objectCount++;
}

void getdata() {
cout << "Enter roll number: "<<endl;
cin >> rollNo;
cout << "Enter name: "<<endl;
cin >> name;
cout << "Enter marks: "<<endl;
cin >> marks;
}

void putdata() {
cout<<"Roll Number = "<< rollNo <<endl;
cout<<"Name = "<< name <<endl;
cout<<"Marks = "<< marks <<endl;
cout<<endl;
}
};
int Student::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;
return 0;

Enter roll number: 1


Enter name: Mark
Enter marks: 78
Roll Number = 1
Name = Mark
Marks = 78

Enter roll number: 2


Enter name: Nancy
Enter marks: 55
Roll Number = 2
Name = Nancy
Marks = 55

Enter roll number: 3


Enter name: Susan
Enter marks: 90
Roll Number = 3
Name = Susan
Marks = 90
Total objects created = 3

Class discussion programs


Output:
// C++ program to demonstrate the
working of friend function Distance: 5

#include <iostream>
using namespace std;

class Distance {
private:
int meter;

// friend function
friend int addFive(Distance);

public:
Distance() : meter(0) {}

};

// friend function definition


int addFive(Distance d) {

//accessing private members from


the friend function
d.meter += 5;
return d.meter;
}

int main() {
Distance D;
cout << "Distance: " <<
addFive(D);
return 0;
}

Output:
// C++ program to demonstrate the A::a=0
working of friend class

#include <iostream>
class A {
private:
int a;

public:
A() { a = 0; }
friend class B; // Friend Class
};

class B {
private:
int b;

public:
void showA(A& x)
{
// Since B is friend of
A, it can access
// private members of
A
std::cout << "A::a="
<< x.a;
}
};

int main()
{
A a;
B b;
b.showA(a);
return 0;
}
// single inheritance Output

#include <iostream> Enter the value of x = 3

using namespace std; Enter the value of y = 4

class base //single base class Product = 12

public:

int x;

void getdata()

cout << "Enter the value of x = "; cin >>


x;

};

class derive : public base //single derived


class

private:

int y;

public:

void readdata()

cout << "Enter the value of y = "; cin >>


y;

void product()

cout << "Product = " << x * y;

};

int main()

derive a; //object of derived class

a.getdata();

a.readdata();

a.product();

return 0;

} //end of program

2.C++ Program to Inherit a Student class Output:


from Person Class printing the properties
of the Student Input data

#include <iostream> First Name: Harry

#include <conio.h> Last Name: Potter

Gender: Male
using namespace std; Age: 23

class person /*Parent class*/ College: Abc International College

{ Level: Bachelors

private:
Display data
char fname[100],lname[100],gender[10];
First Name : Harry
protected:
Last Name : Potter
int age;
Gender : Male
public:
Age : 23
void input_person();
College : Abc International College

void display_person(); Level : Bachelors

};

class student: public person /*Child class*/

private:

char college_name[100];

char level[20];

public:

void input_student();

void display_student();

};
void person::input_person()

cout<<"First Name: ";

cin>>fname;

cout<<"Last Name: ";

cin>>lname;

cout<<"Gender: ";

cin>>gender;

cout<<"Age: ";

cin>>age;

void person::display_person()

cout<<"First Name : "<<fname<<endl;

cout<<"Last Name : "<<lname<<endl;

cout<<"Gender : "<<gender<<endl;

cout<<"Age : "<<age<<endl;

void student::input_student()

person::input_person();
cout<<"College: ";

fflush(stdin);

gets(college_name);

cout<<"Level: ";

cin>>level;

void student::display_student()

person::display_person();

cout<<"College :
"<<college_name<<endl;

cout<<"Level : "<<level<<endl;

int main()

student s;

cout<<"Input data"<<endl;

s.input_student();

cout<<endl<<"Display data"<<endl;

s.display_student();

getch();
return 0;

3. C++ program to create and display properties of Output


a typist from a staff using Single Inheritance. Enter data

#include<iostream> Name:Roger Taylor

#include<conio.h> Code:13

using namespace std; Speed:46

class staff Display data

{ Name:Roger Taylor

private: Code:13

char name[50]; Speed:46

int code;

public:

void getdata();

void display();

};

class typist: public staff

private:

int speed;
public:

void getdata();

void display();

};

void staff::getdata()

cout<<"Name:";

gets(name);

cout<<"Code:";

cin>>code;

void staff::display()

cout<<"Name:"<<name<<endl;

cout<<"Code:"<<code<<endl;

void typist::getdata()

cout<<"Speed:";
cin>>speed;

void typist::display()

cout<<"Speed:"<<speed<<endl;

int main()

typist t;

cout<<"Enter data"<<endl;

t.staff::getdata();

t.getdata();

cout<<endl<<"Display data"<<endl;

t.staff::display();

t.display();

getch();

return 0;

}
// multiple inheritance Output: enter value of x:10
enter value of y:10
using namespace std; Sum =20

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 obj1; //object of derived class C

obj1.getx();

obj1.gety();

obj1.sum();

return 0;

} //end of program

Ambiguity in Multiple Inheritance Do the changes

#include <iostream> sample.A::display();


#include <conio.h> sample.B::display();

using namespace std;

class A

public:

void display()

cout <<"This is method of A";

};

class B

public:

void display()

cout <<"This is method of B";

};
class C: public A, public B

public:

};

int main()

C sample;

sample.display(); /*causes ambiguity*/

getch();

return 0;

C++ program to display petrol's data using Enter data


Multiple Inheritance from fuel and liquid
Specific gravity: 0.7
#include <iostream>
Rate(per liter): $0.99
#include <conio.h>
using namespace std; Displaying data

Specific gravity: 0.7

class liquid Rate(per liter): $0.99

float specific_gravity;

public:

void input()

cout<<"Specific gravity: ";

cin>>specific_gravity;

void output()

cout<<"Specific gravity:
"<<specific_gravity<<endl;

};

class fuel
{

float rate;

public:

void input()

cout<<"Rate(per liter): $";

cin>>rate;

void output()

cout<<"Rate(per liter):
$"<<rate<<endl;

};

class petrol: public liquid, public fuel

public:

void input()
{

liquid::input();

fuel::input();

void output()

liquid::output();

fuel::output();

};

int main()

petrol p;

cout<<"Enter data"<<endl;

p.input();

cout<<endl<<"Displaying data"<<endl;

p.output();

getch();
return 0;

// hierarchial inheritance Output

#include <iostream> Enter value of x and y:

using namespace std; 2

class A //single base class Product= 6

{ Enter value of x and y:

public: 2

int x, y; 3

void getdata() Sum= 5

cout << "\nEnter value of x and


y:\n"; cin >> x >> y;

};

class B : public A //B is derived from class


base

{
public:

void product()

cout << "\nProduct= " << x * y;

};

class C : public A //C is also derived from


class base

public:

void sum()

cout << "\nSum= " << x + y;

};

int main()

B obj1; //object of derived class B

C obj2; //object of derived class C


obj1.getdata();

obj1.product();

obj2.getdata();

obj2.sum();

return 0;

} //end of program

C++ program to create Employee and


Output
Student inheriting from Person using Student
Hierarchical Inheritance

Enter data
#include <iostream>

Name: John Wright


#include <conio.h>

Age: 21

Gender: Male
using namespace std;
Name of College/School: Abc Academy

Level: Bachelor
class person

{
Displaying data
char name[100],gender[10];
Name: John Wright
int age;
Age: 21
public:
Gender: Male
void getdata()
{ Name of College/School: Abc Academy

cout<<"Name: "; Level: Bachelor

fflush(stdin); /*clears input stream*/ Employee

gets(name); Enter data

cout<<"Age: "; Name: Mary White

Age: 24
cin>>age;

Gender: Female
cout<<"Gender: ";

Name of Company: Xyz Consultant


cin>>gender;

Salary: $29000
}

void display()

Displaying data
{

Name: Mary White


cout<<"Name: "<<name<<endl;
Age: 24
cout<<"Age: "<<age<<endl;
Gender: Female
cout<<"Gender: "<<gender<<endl;
Name of Company: Xyz Consultant
}
Salary: $29000
};

class student: public person

char institute[100], level[20];


public:

void getdata()

person::getdata();

cout<<"Name of College/School: ";

fflush(stdin);

gets(institute);

cout<<"Level: ";

cin>>level;

void display()

person::display();

cout<<"Name of College/School:
"<<institute<<endl;

cout<<"Level: "<<level<<endl;

};

class employee: public person


{

char company[100];

float salary;

public:

void getdata()

person::getdata();

cout<<"Name of Company: ";

fflush(stdin);

gets(company);

cout<<"Salary: Rs.";

cin>>salary;

void display()

person::display();

cout<<"Name of Company:
"<<company<<endl;

cout<<"Salary: Rs."<<salary<<endl;
}

};

int main()

student s;

employee e;

cout<<"Student"<<endl;

cout<<"Enter data"<<endl;

s.getdata();

cout<<endl<<"Displaying data"<<endl;

s.display();

cout<<endl<<"Employee"<<endl;

cout<<"Enter data"<<endl;

e.getdata();

cout<<endl<<"Displaying data"<<endl;

e.display();

getch();

return 0;
// multilevel inheritance Output

#include <iostream> Enter value of x= 2

using namespace std;

Enter value of y= 3
class base //single base class

{
Enter value of z= 3
public:

int x;
Product= 18

void getdata()

cout << "Enter value of x= "; cin >>


x;

};

class derive1 : public base // derived class


from base class

public:

int y;

void readdata()

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


cin >> y;

};

class derive2 : public derive1 // derived


from class derive1

private:

int z;

public:

void indata()

cout << "\nEnter value of z= "; cin


>> z;

void product()

cout << "\nProduct= " << x * y *


z;

};

int main()
{

derive2 a; //object of derived class

a.getdata();

a.readdata();

a.indata();

a.product();

return 0;

} //end of program

2. C++ program to create a programmer Output:


derived from employee which is himself
derived from person using Multilevel
Inheritance Enter data

#include <iostream> Name: Karl Lens

#include <conio.h> Age: 31

using namespace std; Gender: Male

Name of Company: Dynamic Info

class person Salary: $21000

{ Number of programming language known: 4

char name[100],gender[10]; Displaying data

int age; Name: Karl Lens


public: Age: 31

void getdata() Gender: Male

{ Name of Company: Dynamic Info

cout<<"Name: "; Salary: $21000

fflush(stdin); /*clears input stream*/ Number of programming language known: 4

gets(name);

cout<<"Age: ";

cin>>age;

cout<<"Gender: ";

cin>>gender;

void display()

cout<<"Name: "<<name<<endl;

cout<<"Age: "<<age<<endl;

cout<<"Gender: "<<gender<<endl;

};

class employee: public person


{

char company[100];

float salary;

public:

void getdata()

person::getdata();

cout<<"Name of Company: ";

fflush(stdin);

gets(company);

cout<<"Salary: Rs.";

cin>>salary;

void display()

person::display();

cout<<"Name of Company:
"<<company<<endl;

cout<<"Salary: Rs."<<salary<<endl;
}

};

class programmer: public employee

int number;

public:

void getdata()

employee::getdata();

cout<<"Number of programming
language known: ";

cin>>number;

void display()

employee::display();

cout<<"Number of programming
language known: "<<number;

};
int main()

programmer p;

cout<<"Enter data"<<endl;

p.getdata();

cout<<endl<<"Displaying data"<<endl;

p.display();

getch();

return 0;

// hybrid inheritance Output

#include <iostream> Sum= 14

using namespace std;

class A

public:

int x;

};

class B : public A
{

public:

B() //constructor to initialize x in


base class A

x = 10;

};

class C

public:

int y;

C() //constructor to initialize y

y = 4;

};

class D : public B, public C //D is derived


from class B and class C

{
public:

void sum()

cout << "Sum= " << x + y;

};

int main()

D obj1; //object of derived class D

obj1.sum();

return 0;

} //end of program

Hybrid inheritance

A new scheme for evaluation of student’s


performance is formulated that gives
weightage for sports. Extend the inheritance
relation depicted in the figure below such that
the result, class also inherits properties of
sports class. Write an interactive program to
model this relationship. Which type of
inheritance this model belongs to?
include<iostream.h>

#include<conio.h

class stu

{ //First base Class//

int id;

char name[20];

public: //If not declared, data


members are by default defined as private//

void getstu(){

cout << "Enter stuid,


name";

cin >> id >> name;

};

class marks: public stu{//derived class//

protected: //without this command,


data members will not be available next//

int m, p, c;// without ‘protected:’


command, m1, m2, & m3 are private
members//

public:

void getmarks(){

cout << "Enter 3 subject


marks:";

cin >> m >> p >> c;

};

class sports{//Second base class//

protected:

int spmarks;

public:

void getsports(){

cout << "Enter sports


marks:";

cin >> spmarks;

};

class result : public marks, public


sports{//Derived class by hybrid inheritance//

int tot;

float avg;

public :

void show(){}

tot=m+p+c;

avg=tot/3.0;

cout << "Total=" << tot


<< endl;

cout << "Average=" <<


avg << endl;

cout << "Average +


Sports marks =" << avg+spmarks;

};

void main(){

result r;//object//

r.getstu();

r.getmarks();

r.getsports();

r.show();

getch();
};

1. Constructor in Derived class


#include <iostream>
using namespace std;
class alpha
{
int x;
public:
alpha(int i)
{
x=i;
cout<<"alpha initialized";
}
void show_x(void)
{
cout<<"x="<<x;
}
};
class beta
{
float y;
public:
beta(float j)
{
y=j;
cout<<"beta initialized";

}
void show_y(void)
{
cout<<"y="<<y;
}
};

class gamma:public beta,public alpha


{
int m,n;
public:
gamma(int a,float b,int c,int d):
alpha(a),beta(b)
{
m=c;
n=d;
cout<<"gamma initialized";
}
void show_mn(void)
{

cout<<"m="<<m;
cout<<"n="<<n;
}
};
int main()
{
gamma g(5,10.75,20,30);
g.show_x();
g.show_y();
g.show_mn();
return 0;
}
Base and derived class constrctors OUTPUT:
Base default constructor
Base default constructor
2. Base class Default Constructor in Derived default constructor
Derived class Constructors Base default constructor
Derived parameterized constructor
class Base

int x;

public:

// default constructor

Base()

cout << "Base default constructor\n";

};

class Derived : public Base

int y;

public:
// default constructor

Derived()

cout << "Derived default constructor\n";

// parameterized constructor

Derived(int i)

cout << "Derived parameterized constructor\


n";

};

int main()

Base b;

Derived d1;

Derived d2(10);

3. Base class Parameterized OUTPUT:


Constructor in
Derived class Constructor. Base Parameterized Constructor

class Base Derived Parameterized Constructor


{

int x;

public:

// parameterized constructor

Base(int i)

x = i;

cout << "Base Parameterized Constructor\


n";

};

class Derived : public Base

int y;

public:

// parameterized constructor

Derived(int j):Base(j)

y = j;

cout << "Derived Parameterized


Constructor\n";

}
};

int main()

Derived d(10) ;

Virtual base calss


#include<iostream>
#include<conio.h>
using namespace std;
class ClassA
{
public:
int a;
ClassA()
{
cout<<"class A"<<endl;
}
void getfun()
{
cout<<"inside A"<<endl;
}
};

class ClassB : virtual public ClassA


{
public:
int b;
ClassB()
{
cout<<"class B"<<endl;
}
void getfun()
{
cout<<"inside B"<<endl;
}
};
class ClassC : virtual public ClassA
{
public:
int c;
ClassC()
{
cout<<"class C"<<endl;
}
void getfun()
{
cout<<"inside C"<<endl;
}
};

class ClassD : public ClassB, public


ClassC
{
public:
int d;
ClassD()
{
cout<<"class D"<<endl;
}
void getfun()
{
cout<<"INSIDE D"<<endl;
}
};

int main()
{

ClassD obj;
//Statement 1
obj.a = 100;
//Statement 2

obj.b = 20;
obj.c = 30;
obj.d = 40;
obj.getfun();
cout<< "\n A : "<< obj.a;
cout<< "\n B : "<<
obj.b;
cout<< "\n C : "<< obj.c;
cout<< "\n D : "<<
obj.d;

You might also like