Inheritance Beyond Single Level
Write a C++ Program for Inheritance Beyond Single Level. Here’s a Simple C++ Program for Inheritance Beyond Single Level in C++ Programming Language.
What are Inheritance in C++ ?
- Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.
- When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.
- The idea of inheritance implements the is a relationship. For example, mammal IS-A animal, dog IS-A mammal hence dog IS-A animal as well and so on.
Types of Inheritance : :
There are different types of inheritance : :
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid (Virtual) Inheritance
Below is the source code for C++ Program for Inheritance Beyond Single Level which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* C++ Program for Inheritance Beyond Single Level */ #include <iostream> using namespace std; class industry { protected: char name[25]; public: void insert() { cout<<"Enter Your Name : "; cin>>name; } void output() { cout<<"\nName : "<<name<<"\n"; } }; class computer: public industry { protected : char education[10]; float salary; public: void insert() { industry:: insert(); cout<<"Enter Your Highest Qualification : "; cin>>education; cout<<"\nEnter Your Salary : "; cin>>salary; } void output() { industry::output(); cout<<"Highest Qualification is : "<<education<<"\n"; cout<<"Salary Drawn is : "<<salary<<"\n"; } }; class manager : public industry { protected : int experience; char grade; public: void insert() { industry::insert(); cout<<"Your Previous Experience : "; cin>>experience; cout<<"\nYour Grade : "; cin>>grade; } void output() { industry::output(); cout<<"Total Previous Experience : "<<experience<<"\n"; cout<<"Your Grade : "<<grade<<"\n"; } }; class admin: public industry { protected : char type[10]; public: void insert() { industry::insert(); cout<<"Type : "; cin>>type; } void output() { industry::output(); cout<<"Type : "<<type<<"\n"; } }; class soft: public computer { protected : char expert[10]; public: void insert() { computer::insert(); cout<<"Enter Your Expertise Field : "; cin>>expert; } void output() { computer::output(); cout<<"Expertise Field is : "<<expert<<"\n"; } }; class hard: public computer { protected: int experience; public: void insert() { computer::insert(); cout<<"Enter Previous Experience : "; cin>>experience; } void output() { computer::output(); cout<<"Previous Experience in Hardware : "<<experience<<"\n"; } }; int main( ) { soft sl; hard h1; manager m1; admin a1; cout<<"Enter the Data for Software Personnel : "<<endl; sl.insert(); cout<<"\nInformation of Software Personnel : "; sl.output(); cout<<"\nEnter the Data for Hardware Personnel : \n"; h1.insert(); cout<<"\nInformation of Hardware Personnel : "; h1.output(); cout<<"\nEnter Data for Manager : \n"; m1.insert(); cout<<"\nManager Information : "; m1.output(); cout<<"\nEnter Data for Administrative Staft : \n"; a1.insert(); cout<<"\nOutput of the Administrative Staff : "; a1.output(); return 0; }
OUTPUT : :
/* C++ Program for Inheritance Beyond Single Level */ Enter the Data for Software Personnel : Enter Your Name : codez Enter Your Highest Qualification : b.tech Enter Your Salary : 50000 Enter Your Expertise Field : c++ Information of Software Personnel : Name : codez Highest Qualification is : b.tech Salary Drawn is : 50000 Expertise Field is : c++ Enter the Data for Hardware Personnel : Enter Your Name : club Enter Your Highest Qualification : m.tech Enter Your Salary : 100000 Enter Previous Experience : employee Information of Hardware Personnel : Name : club Highest Qualification is : m.tech Salary Drawn is : 100000 Previous Experience in Hardware : 0 Enter Data for Manager : Enter Your Name : Your Previous Experience : Your Grade : Manager Information : Name : � ` Total Previous Experience : 32611 Your Grade : Enter Data for Administrative Staft : Enter Your Name : Type : Output of the Administrative Staff : Name : Type : ��~c
Above is the source code and output for C++ Program for Inheritance Beyond Single Level which is successfully compiled and run on Windows System to produce desired output.
If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.
Thanks for reading the post….
Hate C++ But Its part of Sullabus….
….
Not so helpful! but ok
It’s helpful.
Thanks