Question
The program will read a file (cityInfo.txt) containing city information. This information includes city id, group, location (x, y) and city name. The cityInfo.txt has
The program will read a file (cityInfo.txt) containing city information. This information includes city id, group, location (x, y) and city name.
The cityInfo.txt has the following format: int char double double string
For example: 1
07 S 18.30 66.10 San Juan, P.R.
45 H 21.18 157.50 Honolulu, Hawaii
54 K 24.33 81.48 Key West, Fla.
67 M 25.46 80.12 Miami, Fla.
119 T 27.57 82.27 Tampa, Fla.
103 S 29.23 98.33 San Antonio, Tex.
47 H 29.45 95.21 Houston, Tex.
- Column 1 is the ID A unique integer value. It may not be continuous,
- Column 2 is the group an upper-case character [A-Z]
- Column 3 is X coordinate,
- Column 4 is Y coordinate,
- Column 5 is city name. It may include spaces, commas, dots, to indicate state/province and country.
After reading the file the program will display a menu. Using the menu, the user can select to display the cities with ID within a range (e.g., display the city info for all the cities with ID >=6 and ID<= 15), or by group (e.g., display the city info for all the cities with group = A), choose two cities (by id), namely city1 and city2, and compute the linear (Euclidean) distance between the two chosen cities, and an option to exit the program.
The assignment: write a program to
1) Read the data from the input file, a. Store the information using parallel arrays: one array of integers for ID, an array of char for group, an array of doubles for X coordinates, one array of doubles for Y coordinates and one for the city names. Assume that the maximum number of entries (i.e., cities) is 1000, considering that the input file may contain N entries, where 0=0, 0<= max_id. <=minimum(N,1000). N is the number of cities in the input file. (10 points) 4) When option b) is selected, the program asks the user to enter a character. This character (e.g., group_char) must be in the range [A, Z]. (5 points) Notice: for options a and b, display the city info as in table 1. All the columns are left aligned. Use 6 positions for ID, 8 positions for group, 10 positions with precision 2 for X and Y coordinated, and 30 for the city name. 5) When option c) or d) are selected, the program asks for an integer. If the integers entered for city 1 and city 2 are the same (same id is entered), a message should warn the user and ask to try again. (10 points) 6) If option e) is chosen: a. Determine if city 1 and 2 have been entered. If not, warn the user and display the menu again. This is, if only city 1, or only city 2 are defined, the program cannot compute the distance. (10 points) b. Compute the linear distance and display it on the screen (8-byte fields, with precision
2). You can reuse any of your functions from previous homework assignment or any function written in class or available in your textbook/slides. Avoid copy and paste from google search or anywhere else. (5 points) 7) After any of the options a to e is chosen, the menu should be displayed again (5 points). 8) The program will finish only when option f is chosen (5 points). 9) If any other option is selected (i.e., any option different of a-f), display a message indicating that the option is invalid. (5 points)
When option a) is selected, the program asks the user for the min_id and max_id values. Input validation is required: min_id=0, 0<= max_id. <=minimum(N,1000). N is the number of cities in the input file. (10 points) 4) When option b) is selected, the program asks the user to enter a character. This character (e.g., group_char) must be in the range [A, Z]. (5 points)
Notice: for options a and b, display the city info as in table 1. All the columns are left aligned. Use 6 positions for ID, 8 positions for group, 10 positions with precision 2 for X and Y coordinated, and 30 for the city name. 5) When option c) or d) are selected, the program asks for an integer. If the integers entered for city 1 and city 2 are the same (same id is entered), a message should warn the user and ask to try again. (10 points) 6) If option e) is chosen: a. Determine if city 1 and 2 have been entered. If not, warn the user and display the menu again. This is, if only city 1, or only city 2 are defined, the program cannot compute the distance. (10 points) b. Compute the linear distance and display it on the screen (8-byte fields, with precision 2). You can reuse any of your functions from previous homework assignment or any function written in class or available in your textbook/slides. Avoid copy and paste from google search or anywhere else. (5 points) 7) After any of the options a to e is chosen, the menu should be displayed again (5 points). 8) The program will finish only when option f is chosen (5 points). 9) If any other option is selected (i.e., any option different of a-f), display a message indicating that the option is invalid. (5 points)
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