Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

Students also viewed these Databases questions