Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use arrays to write a c program to tell you how long it will take you to fly between any two cities on an extremely

Use arrays to write a c program to tell you how long it will take you to fly between any two cities on an extremely unusual airline. The times are: the cities, flying times and layovers are listed below.

Home City|destination city|flying time|layover

(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 chicago. |2:14.| 0:53

(5) Chicago. |6 Buffalo. |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, Chicago 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, 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 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.

do not change the city numbers.

Do not have extra user input (including "Press any key to continue") beyond getting the starting and ending cities repeatedly.

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 the getNum() function below for getting input.

You are not responsible for handling excessively long input lines or numbers out of the range of an int variable.

Other 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 flying and layover times must be stored as one multi-dimensional array (you might not know how to do this yet) or two one-dimensional arrays in main().

The arrays must be const. These arrays 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. Assume that the user will always enter less than 80 characters. The program must be commented adequately and indented correctly.

NOTES: It is vitally important that you follow the above requirements. -Do not support going backwards (e.g. from Denver to Toronto). If they try to do so, display an error message and continue with the program. Do not support going from one city to the same city (e.g. from Denver to Denver). If they try to do so, display an error message and continue with the program. Make sure that the user never has to guess about what the city numbers are. Be aware that Visual Studio will NOT allow the use of const-declared values as array sizes. You must use #define instead if you want to avoid using a magic number in the size of an array. A "layover" is an amount of time that you have to wait in the airport between flights. Make sure that you don't include the layover at the end of the trip! As an example, your program should be able to calculate how long it takes to fly from Austin to Chicago or Toronto to Denver but not Chicago to Austin (that's backwards). To fly from Austin to Chicago, it would take 3:55 (Austin to Denver) + 11:29 (layover in Denver) + 2:14 (Denver to Chicago) use getNum to get the values int getNum(void) { char record[121] = {0}; int number = 0; fgets(record, 121, stdin); if( sscanf(record, "%d", &number) != 1 ) { number = -1; } return number; }

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

Compare the current team to the ideal team.

Answered: 1 week ago

Question

How to find if any no. is divisble by 4 or not ?

Answered: 1 week ago

Question

Explain the Pascals Law ?

Answered: 1 week ago

Question

What are the objectives of performance appraisal ?

Answered: 1 week ago