Write a class student that contains the attribute teacher name, age and address. It also contains member function to input and display its attribute. Write another class teacher Write another class Writer that contains the attributes writer name, address and number of books written by him. It also contains member function to input and display its attributes. Write a third class Scholar that inherits both student and teacher classes.
#include<iostream>
#include<string>
using namespace std;
class Student
{
string teachName;
int age;
string address;
public:
Student():teachName(""),age(0),address(""){}
void SetAtr()
{
cout<<"Please, enter a teacher name: ";
cin>>teachName;
cout<<"Please, enter an age: ";
cin>>age;
cout<<"Please, enter an address: ";
cin.ignore(256,'\n');
getline(cin,address);
}
void Display()
{
cout<<"\nTeacher name is\t\t"<<teachName
<<"\nAge is\t\t\t"<<age
<<"\nAddress is\t\t"<<address;
}
};
class Writer
{
string writerName;
int bookNum;
string address;
public:
Writer():writerName(""),bookNum(0),address(""){}
void SetAtr()
{
cout<<"Please, enter a writer name: ";
cin>>writerName;
cout<<"Please, enter number of books: ";
cin>>bookNum;
cout<<"Please, enter an address: ";
cin.ignore(256,'\n');
getline(cin,address);
}
void Display()
{
cout<<"\nWriter name is\t\t"<<writerName
<<"\nNumber of books is\t"<<bookNum
<<"\nAddress is\t\t"<<address;
}
};
class Scholar:public Student, public Writer{};
int main()
{
Scholar s;
s.Student::SetAtr();
s.Writer::SetAtr();
s.Student::Display();
s.Writer::Display();
}
Comments
Leave a comment