Question: C++ i want Lab#3 done can u make clear code so I could understand it. Lab#2The objective of this lab is compare the populations of

C++ i want Lab#3 done can u make clear code so I could understand it.

Lab#2The objective of this lab is compare the populations of various cities that lie in between Toledo and Dayton on I-75. Write a program that produces a bar illustrating the populations. The program should read the name of the city and its population from a file. Have the program continue this process until the end of file is reached. For each city, your program should display the name of the city and a bar consisting of one asterisk for every 2,000people. For example, if a citys population is between 18,000 and 19,999, 9 asterisks should appear in the bar. The data can be found in the pop.txt file located on Canvas.

For a hint on how to read data until the end of file is reached, look at the notes on repetition structures that we covered in class. Also look at the same class notes to review how to print out a certain number of asterisks to the screen.

The output should be formatted similar to the following:

City Populations

-----------------------------------------

Perrysburg **********

Bowling Green***************

Findlay ********************

.

.

.

Huber Heights******************

-----------------------------------------

KEY: (*) -> 2000 people

Once finished with the above task, modify your program to allow the user to type in how many people each asterisk represents (for example, typing 5000 would make the bar for Findlay 8 asterisks long instead of 20).

Finally, add code to your program to track the two cities in the file with the highest populations and list the results after the previously computed results. You can assume that no two cities have the same population.

Lab#3

The premise of this lab is the same as Lab #2, and you will be mainly refactoring code in that lab to meet the following objectives. Show me your work after each objective is met.

1) All of the requirements for Lab #2 must still be met.

2) Refactor the code so that you use a struct (call it City) to store and access the name and population for each city.

3) Refactor the code so that as the city names and populations are read in, they are stored into an array of City records.

4) Refactor the code so that it contains the following two functions:

a. readCities This function will take as parameters your array of City records, a numCities variable (which will keep track of the number of cities read, and a file object. The job of this function is to read in all of the city names and populations from the file, storing them into your array of City records

b. printPopulations This function will take as parameters your array of City records, a numCities variable, and the number of people that each asterisk should represent. It will then print the city populations in the same format as before (i.e. with asterisks representing the number of people in each city).

5) Change your readCities function so that the cities are stored in alphabetical order by city name as they are read in (i.e. dont read them all in and then sort them after they are all stored. Reflect back to the strategy and code we implemented in the Array Practice in-class lab (problem #9) to help accomplish this.

6) (Optional 2 point bonus if you show both solutions) What would need to be changed in step 5) so that they were sorted by population instead of city name?

data

Perrysburg 21482 Bowling Green 31820 Findlay 41321 Bluffton 4144 Lima 37149 Wapakoneta 9782 Sidney 20614 Piqua 20987 Troy 25865 Tipp City 9721 Huber Heights 37986

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!