Question: The program first reads integer cityCount from input, representing the number of pairs of inputs to be read. Each pair has a string and an

The program first reads integer cityCount from input, representing the number of pairs of inputs to be read. Each pair has a string and an integer. One City object is created for each pair and added to vector cityList. Output "Highest city size: " followed by the highest size of all the City objects.

Ex: If the input is:

4 Glendo 2614 Yonder 1122 Jackson 4126 Gillette 2730

then the output is:

Highest city size: 4126

Note: The vector has at least one element.

#include #include using namespace std;

class City { public: void SetNameAndSize(string newName, int newSize); int GetSize() const; private: string name; int size; };

void City::SetNameAndSize(string newName, int newSize) { name = newName; size = newSize; }

int City::GetSize() const { return size; }

int main() { int cityCount; unsigned int i; vector cityList; City currCity; string currName; int currSize; int highestSize;

cin >> cityCount; for (i = 0; i < cityCount; ++i) { cin >> currName; cin >> currSize; currCity.SetNameAndSize(currName, currSize); cityList.push_back(currCity); } highestSize = cityList.at(0).GetSize();

// Enter code here return 0; }

Need help with this code in c++. Thanks!

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!