Question
Objectives to write this c program Creation and use of arrays Creation and use of structs Passing arguments into parameters Splitting your code into modular
Objectives to write this c program
Creation and use of arrays Creation and use of structs Passing arguments into parameters Splitting your code into modular functions Making appropriate design decisions Using best practices for magic numbers Command-line arguments File I/O, binary and text Following stated requirements Overview of Requirements
Use arrays to write a program to tell you how long it will take you to fly between any two cities on an extremely unusual airline. The times are:
Home City Destination City
Flying Time
Layover Time
(1) Toronto
(2) Atlanta
4:15
1:20
(2) Atlanta
(3) Austin
3:58
0:46
(3) Austin
(4) Denver
3:55
11:29
(4) Denver
(5) Kansas City
2:14
0:53
(5) Kansas City
(6) New York
3:27
none
Functional Requirements
The user must provide the starting and ending cities as a number. The numbers corresponding to each city are shown in the table above (e.g. Toronto is city 1, Kansas City is city 5). Do not change the numbers for the cities. Your program must loop until the user selects city 0 for the starting city. In the loop, display the city list (with city number and city name on the same line, one line per city) and then ask the user for the starting city and then for the ending city. Once you get the ending city, calculate and display the elapsed time to travel between the cities if they are valid OR display an error message if either of the cities are not valid. The result must be calculated. It must then be displayed in correct hh:mm format, not hours only or minutes only. The result should include all layovers between cities but not the layover once you get into the ending city. If the number of hours is less than 10, you must not have a leading 0 (i.e. "9:43" is OK, "09:43" is not). If the number of minutes is less than 10, you must have a leading 0 (i.e. "9:03" is OK, "9:3" is not). If the cities are valid, the output line must be exactly of the format "[city1name] to [city2name] will take [hh:mm]." Make sure that this is exact, even down to the punctuation and spacing. The error message is described below. This output line must also be written to a text file called "results.txt", stored in the current directory. Only these specific lines should be written to the file. I'm serious about not changing the city numbers. Do not have extra user input (including "Press any key to continue") beyond getting the starting and ending cities repeatedly. I am very serious about this. Don't clear the screen when doing output. Spelling and consistency in your output is important. Also, make good use of blank lines to separate unrelated parts of your output. The program must not produce incorrect output or crash or hang if invalid input is used. You must use either cin or the getNum() function from Assignment 2 for getting input. You are not responsible for handling excessively long input lines or numbers out of the range of an int variable. Programming Requirements
It must use at least one non-trivial (i.e. more than one or two lines long) user-created function other than main() and the function you use for getting user input. Parameters must be passed and/or return values used. It must not use global variables or goto. Any use of scanf() will be handled as described in class. The city names and flying and layover times for a city must be stored in a struct called CityInfo. All of this data must be stored as an array of structs stored in main(). This array must be passed to a function that does the time calculations (so that I can see that you know how to do it). The addition of the times must be done using a loop of some type. The flying and layover times must be loaded in from a binary file. Each time is a pair of two bytes. The first byte is the hours portion. The second byte is the minutes portion. For example, the time "4:15" is stored as one byte with the ASCII value 4 and a second byte with the ASCII value 15. It is your job to figure out how to convert this to minutes (which is easiest to work with). The name of the flying and layover times file must be obtained as the first command-line argument. For your internal testing, I will provide this binary file for you. I will test using this provided file but will use whatever filename I want. Loading this binary file into a text editor likely won't work very well for you. The city names must be loaded in from a text file. Each city name is stored in the file as a string on one line (so there should be 6 lines in the file). The name of the city name file must be obtained as the second command-line argument. You must create this file yourself and submit it, although I will use my own version. The city names must be read in from the file as C-style null-terminated strings using fgets() but they can be stored in the struct as either a C-style null-terminated string or a C++ string. The "results.txt" filename must be stored as a const char * variable called resultsFilename (i.e. const char *resultsFilename = "results.txt";) that you would then use in your fopen() call and error messages. This constant can be global. Do not hardcode the "results.txt" filename in your fopen() call. It would also be a good idea to not hardcode the "results.txt" filename in your error messages but I won't be checking that when marking. Use best practices with respect to Magic Numbers. Assume that the user will always enter less than 80 characters. The program must be commented adequately and indented correctly. Errors
If there is not exactly two command-line arguments, display an error message that states exactly "Usage: cA3
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