Write a C++ Program constructors invoked in derived class.
AIM:
Write a C++ Program constructors invoked in derived class.
THEORY:
For each colour a separate class with constructor is
declared. The classes red, blue, yellow are base classes. The class orange is
derived from red and yellow, green from blue and yellow , violet from red and
blue.
The classes
reddish brown derived from orange and violet, bluish brown from violet and
green and finally yellowish brown from green and orange. In function main()
objects of the classes reddish brown , bluish brown , yellowish brown are declared
.
When objects
are declared constructors are executed from base to derived class.
SOURCE
CODE:
#include<iostream>
using namespace std;
class red
{
public:
red()
{
cout<<"\n
red";
}
};
class yellow
{
public:
yellow()
{
cout<<"\n
yellow";
}
};
class blue
{
public:
blue()
{
cout<<"\n
blue";
}
};
class orange: public red,yellow
{
public:
orange()
{
cout<<"\n
orange";
}
};
class green:public blue,yellow
{
public:
green()
{
cout<<"\n
green";
}
};
class violet:public red,blue
{
public:
violet()
{
cout<<"\n
violet";
}
};
class reddish_brown:public orange,violet
{
public:
reddish_brown()
{
cout<<"\n
reddish_brown";
}
};
class yellowish_brown:public green,orange
{
public:
yellowish_brown()
{
cout<<"\n
yellowish brown";
}
};
class bluish_brown:public violet,green
{
public:
bluish_brown()
{
cout<<"\n
bluish brown";
}
};
int main(){
reddish_brown
r;
cout<<endl;
bluish_brown
b;
cout<<endl;
yellowish_brown
y;
cout<<endl;
}
Labels: oop through c++ lab
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home