Define a base class person that will contain universal information, including name, address, birth date, gender and identification (student, worker etc). Derive from this class the following classes:
Student
Worker
Student_worker
Write a program that asks user to input information (student, worker etc) and creates a list of persons. Give user choice to view list by gender and by identification( list of people who are students, list of people who are workers etc).
#include <iostream>
#include <string>
using namespace std;
class person {
protected:
string name;
string address;
string birth_date;
string gender;
string identification;
public:
person()//class constructor for person
{
cout << "Please enter the following information:" << endl;
cout << "Name: ";
cin >> name;
cout << "Address: ";
cin >> address;
cout << "Birth date: ";
cin >> birth_date;
cout << "Gender: ";
cin >> gender;
cout << "Identification: ";
cin >> identification;
cout << endl;
}
};
class student:public person {
protected:
string school;
public:
student()//class constructor for student
{
cout << "Please enter the name of the school you attend: ";
cin >> school;
}
};
class worker:public person {
protected:
string job;
public:
worker()//class constructor for worker
{
cout << "Please enter the title of your job: ";
cin >> job;
}
};
class student_worker:public student, public worker {
};
int main()
{
int x;
cout << "Please enter the information for a student: " << endl;
student s1;
cout << "Please enter the information for a worker: " << endl;
worker w1;
cout << "Please enter the information for a student worker: " << endl;
student_worker sw1;
}