Am trying to create a vector of objects, called Person that consists of a name and an age. Both the name and age are inputed from the user and are being stored in local variables n and a.
n is declared string and a is declared int.
In main
declared vector as
vector< Person> people;
In Person class
public:
// constructor
Person(string, int )
sets and gets for name and age
private:
int age;
string name;
also have set and get functions.
How do i assign the name and age to the vector.
I was using people.push_back(string n, int a) but does not accept it.
Unable to see how to create this as an object of vectors only double, int etc.
this is currently in main after my while loop which is promting the user for information.
My first question is should the push_back statement be in the loop with the input.
The second thing I was trying to do was create a function that read the vector and increased the age by 1.
This is the function I created:
void Person::incrementAge(vector<Person> & person)
{
for (int i = 0; i < person.size(); i++)
{
cout << person[i];
person[];
}
}
I wanted to display each element of the vector and increase the age by one, should that be done in the setAge instead or can it be done in this function?