#include #include #include #include using namespace std; // Start Person Class class Person { public: Person(string n, int a); string getName(); int getAge(); void incrementAge(); void print(); private: string name; int age; }; Person::Person(string n, int a) { name = n; age = a; } string Person::getName() { return name; } int Person::getAge() { return age; } void Person::incrementAge(){ age += 1; } void Person::print() { cout << name << endl; cout << age << endl; } // Person Class END // Car Class Begin class Car { public: Car() : model(), owner(), driver(){} Car(string s, Person*o, Person*d) : model(s), owner(o), driver(d){} void print(); private: string model; Person *owner; Person *driver; }; void Car::print() { cout << model << endl; cout << "Driver: "; driver->print(); cout << "Owner: "; owner->print(); } //End of Car Class Person*find(string n, vector&people) { for (int i = 0; i < people.size(); i++) { if (n == people[i].getName()) return &(people[i]); else return 0; } }; // Begin Main Function int main() { vectorpeople; vector cars; string name = ""; Car * d; Car * o; string person_owner; string person_driver; int age = 0; string model; int testValue = 0; while (testValue != -1) { //Start Input for People cout << "Enter Driver Name: "; cin >> name; cout << "Enter Age: "; cin >> age; people.push_back(new Person(name, age)); // Start Input for Cars cout << "Enter car model, owner name, driver name: "; cin >> model >> person_owner >> person_driver; d = find(person_owner, people); //find doesn't work o = find(person_driver, people); //same here cars.push_back(new Car(model, o, d)); cin >> model >> person_owner >> person_driver; cout << "Press -1 to stop, or 1 to enter info for others: "; cin >> testValue; } //Output info for (int i = 0; i < people.size(); i++) { people[i]->incrementAge(); cout << "Name: " << (*people[i]).getName() << endl; cout << "Age: " << (*people[i]).getAge() << endl; } system("PAUSE"); return 0; }