Question: Using derived classes, implement the following hierarchy (from Commentary Notes): person employee dependent manager worker Maintain the following information for each object: person: name, date
Using derived classes, implement the following hierarchy (from Commentary Notes):
person
employee
dependent
manager
worker
Maintain the following information for each object:
person: name, date of birth, gender, SSN, address, phone number
employee: hire date, salary location, phone number
dependent: SSN of employee of which this person is a dependent, address (if different from associated employee's)
manager: title
worker: project on which the worker works
Provide the ability to input and output all the information about each type of object. Also provide public member functions to 1) inquire the value of all the above items, and 2) change the ones that are reasonably changeable.
Below is my code, but I am able to get and display the value of the parent only. Please correct my code..
My code:
#includeusing namespace std; class person { char name[100],gender[10],SSN[20],Address[200]; int dob,Phone; public: void getdata() { cout<<"Name: "; fflush(stdin); /*clears input stream*/ gets(name); cout<<"Date of Birth: "; cin>>dob; cout<<"Gender: "; cin>>gender; cout<<"SSN: "; cin>>SSN; cout<<"Address: "; cin>>Address; cout<<"Phone: "; cin>>Phone; } void display() { cout<<"Name: "< class employee: public person { char location[100]; int hiredate, phonenumber; float salary; public: void getdata() { person::getdata(); cout<<"Hire date: "; cin>>hiredate; cout<<"Salary: "; cin>>salary; cout<<"Location: "; fflush(stdin); gets(location); cout<<"Phone Number: "; cin>>phonenumber; } void display() { person::display(); cout<<"Hired Date "< class dependent: public person { char Address[200]; int SSN; public: void getdata() { person::getdata(); cout<<"SSN of the employee: "; cin>>SSN; cout<<"Address:"; cin>>Address; } void display() { person::display(); cout<<"SSN of the employee: "< class manager: public person { char title[100]; public: void getdata() { person::getdata(); cout<<"Title: "; cin>>title; } void display() { person::display(); cout<<"Title of the manager "< class project: public person { char project[100]; public: void getdata() { person::getdata(); cout<<"Project: "; cin>>project; } void display() { person::display(); cout<<"Project Name: "< int main() { person s; employee e; dependent d; manager m; project p; cout<<"Student"< return 0; }
Result which I get:
/Users/nandinirajeswaran/CLionProjects/Module6/cmake-build-debug/Module6 warning: this program uses gets(), which is unsafe. Student Enter data Name: Nanindi Date of Birth: 240890 Gender: f SSN: 23432435 Address: 34jhkjhk Phone: 749202744
Displaying data Name: Nanindi Date of Birth(mmddyyyy): 240890 Gender: f SSN: 23432435 Address: 34jhkjhk Phone Number: 749202744
Employee Enter data Name: Date of Birth: nandini Gender: SSN: Address: Phone: Hire date: Salary: Location: Phone Number: Displaying data Name: Date of Birth(mmddyyyy): 0 Gender: SSN: Address: Phone Number: 0 Hired Date 0 Salary: 0 Location: nandini Phone Number: 0
Dependent Enter data Name:
Please help me..
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
