Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Written Assignment: Class Person Implement a class Person with two fields name a

ID: 3640518 • Letter: W

Question

Written Assignment: Class Person


Implement a class Person with two fields name and age, and a class Car with three fields:


•The model
•A pointer to the owner (a Person*)

•A pointer to the driver (also a Person*)

Write a program that prompts the user to specify people and cars. Store them in a vector<Person*> and a vector<Car*>. Traverse the vector of Person objects and increment their ages by one year. Traverse the vector of cars and print out the car model, owner’s name and age, and driver’s name and age.

Explanation / Answer

#include #include using namespace std; class person { public: char name[50]; int age; }; class car { public: char model[50]; person * owner; person * driver; }; int main() { person * o; person * d; vector pv; vector::iterator pi; car * c; vector cv; vector::iterator ci; char ans; do { c = new car(); o = new person(); d = new person(); coutc->model; couto->name; couto->age; pv.push_back(o); c->owner = o; coutd->name; coutd->age; pv.push_back(d); c->driver = d; cv.push_back(c); coutans; }while(ans == 'y'); pi = pv.begin(); while(pi != pv.end()) { ((*pi)->age)++; pi++; } cout