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
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started