Question: Write in C++ Use an array of size 6 to store the names. Present the following menu to the user: City Clickers Menu 1 Add
Write in C++
Use an array of size 6 to store the names. Present the following menu to the user:
City Clickers Menu
1 Add city
2 Change city name
3 Delete city
4 List cities
9 Exit
Enter an option:
Create function menuOption that presents the menu and returns the option selected as an integer. Continue to read an option, process it, and display the menu until the user enters the sentinel value of 9. Start the array with three values already in it: Detroit, Dearborn, and Windsor. Here are the option descriptions:
Add city test if the array is full. If so, print an error message. If not, prompt for and get a city name. If the city is already in the list, dont add it and tell the user. If the city is not in the list, add it to the end of the array, and print a city-added message.
Change city name prompt for a city (array) index. If the index is invalid, print an error message. If the index is valid, prompt for the new city name. If the new city name is already in the list, dont add it and tell the user. If the new city name is not in the list, add it and print a city-name-changed message.
Delete city prompt for a city (array) index. If the index is invalid, print an error message. If the index is valid, delete the city by moving all the cities after the index up one in the array to remove the gap, and print a city-deleted message.
List cities print column headers to the screen per the following specification:
| Field | Width | Justification |
|---|---|---|
| Index | 6 | left |
| City | 20 | left |
Loop though the array and print an index and name for each city stored in the array. Also, show the city count after the list.
Exit logic for this option is placed after the sentinel loop. Attempt to open output file CitiesOut.txt. If the file doesnt open, show an error message and end the application. If the file opens, write column headers and data per the above specification. The start of your CitiesOut.txt file should look like this:
Use these inputs for your last run:
| Option | Value(s) |
|---|---|
| 4 |
|
| 1 | Jackson |
| 4 |
|
| 2 | 6 |
| 2 | 3, Dearborn |
| 2 | 3, Dexter |
| 4 |
|
| 3 | 6 |
| 3 | 0 |
| 4 |
|
| 9 |
|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
