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.
Here is what I have so far I know this wrong, Im going through my textbook and working on this even after I post it. I was wondering if someone could take a look and least tell me if im heading in the right direction, Thank you for any help you can give.
#include <iostream>
#include <vector>
#include <conio.h>
#include <string>
usingnamespace std;
class Person
{
string name;
int age;
};
class Car
{
char16_t model;
Owner* name;
Driver* name;
}
int main()
{
vector<Person*>
cout<<"Enter a Driver name and age: \n";
cin>>Person*[i];
cout<<"Enter a Owner name and age:\n";
cin>>Person*[i];
age = age+1;
vector<Car*>
cout<<"Enter a model number \n";
cin>>Car*[i];
cout<<Person*[i], Car*[i];
system ("pause")
return 0;
}
Members of a class object are private by default so you cannot access them outside the class unless through a public method that allows you to do so.
vector is a type therefore it needs a name when you declare one (line 21 and 28)
where is i defined? (lines 23, 25, 30, 32)
where is age defined? (line 26) Don't say inside Person class
#include <iostream>
#include <vector>
#include <conio.h>
#include <string>
usingnamespace std;
class Person
{
string name;
}
class Car
{
char model;
Person *owner;
Person *driver;
}
int age;
int main()
{
vector<string>Person*
cout<<"Enter a Driver name and age: \n";
cin>>Person[i];
cout<<"Enter a Owner name and age:\n";
cin>>Person[i];
age = age+1;
vector<string>Car*
cout<<"Enter a model number \n";
cin>>Car[i];
cout<<Person[i], Car[i];
system ("pause");
return 0;
}