Answer to Question #224229 in C++ for Shank

Question #224229
Write a program to define an abstract class person that will contain the essential information like name, age and sex of a person. Now derive two classes student and Employee both from the class person. The class Student will contain the academic information such as roll number; school etc. and the class Employee will contain information such as department and salary. In the main function declare and array of Person pointers that can hold the address of either Student or Employee object. The program will ask the user to enter the details of students/Employees, create dynamic objects of these classes using new operator and store them in the array. The program will then display the contents of these objects.
1
Expert's answer
2021-08-10T04:28:32-0400
#include<iostream>
using namespace std;
class person
{
private:
char name[20];
long int rollno;
char sex;
public:
void getdata();
void display();
}; 
class student {
private:
char course[20];
char semester[10];
int rank;
public:
void getdata();
void display();
};
class Employee : private person,private student
{
private:
float amount;
public:
void getdata();
void display();
}; 
void person :: getdata()
{
cout<<"enter a name?\n";
cin>>name;
cout<<"enter roll no \n";
cin>>rollno;
cout<<"sex?\n";
cin >>sex;
}
void person::display()
{
cout<<name<<" ";
cout<<rollno<<" ";
cout<<sex<<" ";
}
void student ::getdata()
{
cout<<"course name\n";
cin>>course;
cout<<"semester\n";


cin>>semester;
cout<<"rank of the student\n";
cin>>rank;
}
void student :: display()
{
cout <<course<<" ";
cout <<semester<<" ";
cout <<rank<< " ";
}
void Employee :: getdata()
{
person:: getdata();
student :: getdata();
cout<<"amount in rupees?\n";
cin>>amount;
}
void Employee :: display()
{
person :: display();
student::display();


cout<<amount<<" ";
}
int main()
{
Employee f;
cout<<"enter the following information for";
cout<<"financial assistance\n";
f.getdata();
cout<<endl;


cout<<"____________________________________________\n";
f.display();
cout<<endl;
cout<<"_____________________________________________\n";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS