Question: Write the InputCities() function in the SmallCities class. Within InputCities(), use cin to read each line number until -1 is read from input. If the

Write the InputCities() function in the SmallCities class. Within InputCities(), use cin to read each line number until -1 is read from input. If the line number is not equal to -1, use the City object's ReadDetails() to read the city's name and population from input and append the City object to vector cityList.

Ex: If the input is:

1 Opal 1628 2 Davids 1950 3 Glendo 4460 -1

then the output is:

City: Opal, Population: 1628 City: Davids, Population: 1950 City: Glendo, Population: 4460

#include #include using namespace std;

class City { public: void ReadDetails(); void Print() const; private: string name; int population; };

void City::ReadDetails() { cin >> name; cin >> population; }

void City::Print() const { cout << "City: " << name << ", Population: " << population << endl; }

class SmallCities { public: void InputCities(); void PrintCities(); private: vector cityList; };

/* Your code goes here */

void SmallCities::PrintCities() { unsigned int i; City currCity;

for (i = 0; i < cityList.size(); ++i) { currCity = cityList.at(i); currCity.Print(); } }

int main() { SmallCities smallCities;

smallCities.InputCities(); smallCities.PrintCities(); return 0; }

c++ and please please make it correct

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!