By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,190 Members | 2,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,190 IT Pros & Developers. It's quick & easy.

Define a base class person that will contain universal information, including name

P: 4
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...
Apr 15 '10 #1
Share this Question
Share on Google+
1 Reply


jkmyoung
Expert 100+
P: 2,057
Please use code tags,
1. Select your code.
2. Click the # sign.
3. Code Tags!

Well you're missing this part:
"Write a program that asks user to input information (student, worker etc) and creates a list of persons. "

Is this part of the options? eg Option 4, Enter a student,. Option 5 Enter a worker?

The way you have it now, you can only ever hold 6 people. person *p[6];
Do you really want a student worker as a 3rd type? The question seems to indicate an either/or relationship, although I could be wrong. Eg, you're either a student, or you're a worker, or you don't belong in this database.
Apr 15 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.