Hello,
I unfortunately failed my advanced c++ class last semester so I need to retake it. Our first assignment is to "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)."
I'm stuck on how I can create a list to display gender or identification. I'm utterly stuck right now.. I was thinking of using a vector container but I don't know how I would go about doing that. Any help would be appreciated. In the meantime I'll get back to trying to figure this out
Code is as follows:
#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;
}
The code runs as is, but it isn't the entire assignment (obviously). Thanks for any future help.
Regards,
Don Panda