473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
1 2862
jkmyoung
2,057 Expert 2GB
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

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

Similar topics

50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
3
by: Helen | last post by:
I have a person class with a name object. The name object has several fields including one called "title". The two classes look something like this: public class name { public string title {...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
5
by: eiji | last post by:
Hi folks, I hope this is not "off topic"! :-) Consider the next code: /* Declarations of types that could become platform-dependent */ #define MyChar char #define MyInt int
5
by: Chris Szabo | last post by:
Good afternoon everyone. I'm running into a problem deserializing a stream using the XmlSerializer. A stored procedure returns the following from SQL Server: <Student StudentId="1" Status="1"...
5
by: EqDev | last post by:
I have a class that is a control derived from UserControl. I want to use serialization and deserialization with this calss but I get an exception "Cannot serialize member...
1
by: Peter Nofelt | last post by:
Hey All, I am having issue with serializing a class and its base class using ..net 2.0. I am using IXmlSerializable I've provided code displaying my at the bottom of this post. Thanks ahead...
3
by: Smithers | last post by:
I'm designing a Windows Forms application for a medical clinic that keeps complete and comprehensive histories on its patients: histories of medical conditions and facts, financial facts,...
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
5
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.