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).
hey guys this is what i have done so far please let me know if i am doing it right or what do i need to change. or if u can please do the correction. thank you so much
#include
<iostream>
#include
<string>
using
namespace std;
class
person
{
public
:
person()
{}
person(string n,string g, string a,string b)
{
name=n;
gender=g;
address=a;
birthday=b;
}
string get_name()
{
return name;
}
string get_gender()
{
return gender;
}
string get_address()
{
return address;
}
string get_birthday()
{
return birthday;
}
string get_id()
{
return id;
}
void print()
{
cout<<get_name()<<
" "<<get_id()<<" "<<get_gender()<<" "<<get_address()<<" "<<get_birthday()<<endl;
}
protected
:
string name;
string gender;
string address;
string birthday;
string id;
};
class
student: public virtual person
{
public
:
student(string n,string g,string a,string b):person(n,g,a,b)
{
id=
"student";
}
};
class
worker: public virtual person
{
public
:
worker(string n,string g,string a,string b):person(n,g,a,b)
{
id=
"worker";
}
};
class
student_worker: public person
{
public
:
student_worker(string n,string g,string a,string b): person(n,g,a,b)
{
id=
"student worker";
}
};
void
main()
{
person *p[6];
p[0]=
new worker("Tom", "male", "Walnut", "May 1st");
p[1]=
new student("Lucy", "female","Rowland Heights", "July 3rd");
p[2]=
new worker("Ann", "female", "Rowland Heights", "December 22th");
p[3]=
new student("Steven", "male", "Rowland Heights", "June 15th");
p[4]=
new student("Michale", "male", "Rowland Heights", "February 27th");
p[5]=
new student_worker("Alicia","female","Diamond Bar", "May 16th");
int choice=0;
while(choice!=3)
{
cout<<
"1.list by id"<<endl;
cout<<
"2.list by gender"<<endl;
cout<<
"3.exit"<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<
"list of students"<<endl;
for(int i=0; i<6; i++)
{
if(p[i]->get_id()=="student")
p[i]->print();
}
cout<<endl;
cout<<
"list of workers"<<endl;
for(int i=0; i<6; i++)
{
if(p[i]->get_id()=="worker")
p[i]->print();
}
cout<<endl;
cout<<
"list of student workers"<<endl;
for(int i=0; i<6; i++)
{
if(p[i]->get_id()=="student worker")
p[i]->print();
}
cout<<endl;
break;
case 2:
cout<<
"list of males"<<endl;
for(int i=0; i<6; i++)
{
if(p[i]->get_gender()=="male")
p[i]->print();
}
cout<<endl;
cout<<
"list of females"<<endl;
for(int i=0; i<6; i++)
{
if(p[i]->get_gender()=="female")
p[i]->print();
}
cout<<endl;
break;
}
}
}
I have to do documentation for this project but i don't know how to start it if some can started for me n show me how done i'll do the rest thank you so much guys god bless you...