/* Copyright (C) 2007 Ankur Banerjee. This program is free software: you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. For a copy of the GNU General Public License see http://www.gnu.org/licenses/gpl.html /
/ Inheritance – Multiple Inheritance /
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
class person
{
protected:
char name[42], add[100];
int age;
public:
void getdata()
{
cout<<endl<<“Enter name : “;
gets(name);
cout<<“Enter address : “;
gets(add);
cout<<“Enter age : “;
cin>>age;
}
void showdata()
{
cout<<endl<<“Displaying details”
<<endl<<“Name : “<<name
<<endl<<“Address : “<<add
<<endl<<“Age : “<<age<<endl;
}
};
class employee : protected person
{
protected:
int emp_no;
float basic, gross;
public:
void getempdata()
{
getdata();
cout<<“Enter employee number : “;
cin>>emp_no;
cout<<“Enter employee basic salary : “;
cin>>basic;
cout<<“Enter employee gross salary : “;
cin>>gross;
}
void showempdata()
{
showdata();
cout<<“Employee number : “<<emp_no
<<endl<<“Basic salary : “<<basic
<<endl<<“Gross salary : “<<gross<<endl;
}
};
class manager : public employee
{
protected:
char dept[42], des[42];
int numemp;
public:
void getmgrdata()
{
getempdata();
cout<<“Enter department : “;
gets(dept);
cout<<“Enter number of employees : “;
cin>>numemp;
cout<<“Enter designation : “;
gets(des);
}
void showmgrdata()
{
showempdata();
cout<<“Department : “<<dept
<<endl<<“Number of employees : “<<numemp
<<endl<<“Designation : “<<des<<endl;
}
} obj;
void main()
{
clrscr();
cout<<“Enter details for one person”;
obj.getmgrdata();
cout<<endl<<“Displaying details for person”;
obj.showmgrdata();
cout<<endl;
getch();
}
/ Output /
Enter details for one person
Enter name : Arthur Dent
Enter address : 42, Quiz Complex, New Delhi
Enter age : 17
Enter employee number : 42
Enter employee basic salary : 15000
Enter employee gross salary : 42000
Enter department : Research
Enter number of employees : 12
Enter designation : Chief Researcher
Displaying details for person
Displaying details
Name : Arthur Dent
Address : 42, Quiz Complex, New Delhi
Age : 17
Employee number : 42
Basic salary : 15000
Gross salary : 42000
Department : Research
Number of employees : 12
Designation : Chief Researcher
/ Note – According to the teachers, this question was only designed to test whether the students would be able to declare the class properly, rather than testing actual programming skills. */