Write a class Teacher that contains the attribute teacher name, age and address. It
also contains member function to input and display its attributes. Write another class
Author that contains the attributes author name, address and number of books written
by him. It also contains member functions to input and display its attributes. Write a
third class Scholar that inherits both Teacher and Author classes. Test these classes
from main() by creating objects of derived classes and testing functions in a way that
clear concept of multiple Inheritance.
#include<iostream>
using namespace std;
class Teacher{
private:
string name, address;
int age;
public:
Teacher(){
}
Teacher(string n, int a, string add ){
name = n;
age =a;
address = add;
}
void display(string n, int a, string add){
cout<<"Enter the teacher's name"<<endl;
cin>>n;
cout<<"Enter the teacher's age"<<endl;
cin>>a;
cout<<"Enter the teacher's address"<<endl;
cin>>add;
cout<<"The teacher's attributes are:\n";
cout<<"Name\t"<<n<<"\nAge\t"<<a<<"\nAddress\t"<<add<<endl;
}
};
class Author{
private:
string name, address;
int number_of_books;
public:
Writer(){
}
Writer(string n, int a, string add ){
name = n;
number_of_books=a;
address = add;
}
void output(string n, int a, string add){
cout<<"Enter the Authors name"<<endl;
cin>>n;
cout<<"Enter the Author's book numbers"<<endl;
cin>>a;
cout<<"Enter the Author's address"<<endl;
cin>>add;
cout<<"The Author's attributes are:\n";
cout<<"Name\t"<<n<<"\nBookno\t"<<a<<"\nAddress\t"<<add<<endl;
}
};
class Scholar: public Teacher, public Author{
public:
Scholar (){
}
Scholar(string n, int a, string add){
}
};
int main(){
Scholar s;
//To demostrate inheritance from the Teacher class using display function of the class
string n;
int a;
string add;
s.display(n,a,add);
cout<<"\n"<<endl;
// Teacher t()
// s.Teacher();
//To demostrate inheritance from the Author class using output function of the class
s.output(n,a,add);
}
Comments
Leave a comment