What to Do Download the file get-numbers.c. Read the code, then build an executable and run...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
What to Do Download the file get-numbers.c. Read the code, then build an executable and run it a few times to see if it behaves the way you expect. Then add a definition for get_double_or_exit, and add code to main that will allow you to test your definition. Note: A sequence of digits without a decimal point-such as 123-can be read into an int and also into a double. get_double_or_exit ahould accept that kind of input. Exercise B: Writing a complete program What to Do The program you will write here will be a simple utility for a long-distance runner. The input will be a distance and a time, and the output will be the average times taken per kilometre and per mile. Write a program that asks a user for a distance in kilometres, as a double, and a time interval, as an int and a double; a number of minutes, and a number of seconds. If the program succeeds in reading all three numbers, it should report the output specified above. Here is a sample of a successful dialogue with the program, with slanted typewriter font used to show what was typed by a user: Please enter a distance in km, using type double. 10.0 I read a double value of 10.000000. Please enter a number of minute, using type int. 39 I read an int value of 39. Please enter a number of seconds, using type double. 47.2 I read a double value of 47.200000. Distance run: 10.000000 km. Time of run: 39 minute(s), 47.200000 second(s). Average time for 1 km: 3 minute(s), 58.720000 seconds (s). Average time for 1 mile: 6 minute(s), 24.182600 seconds(s). And here is a sample of an unsuccessful dialogue: Please enter a distance in km, using type double. No! You can't make me! I could not read a double. I am quitting. For the most part, you may organize your program however you see fit, except for the following, which I insist on, so that you get practice with some of the key C features used in previous lab exercises: • The three input numbers should be collected by a function with exactly this prototype: void get input (double .km in, int minutes in, double seconds_in); The get_input function should make calls to get_double_or_exit and get_int_or_exit-you can copy and paste the prototypes and definitions from Exercise A. Note: 1 mile is exactly 1609.344 metres. What to Include in your PDF Submission Include a complete listing of your program source code, and a listing of terminal input/output showing a few tests, including: 42.195 km in 179 minutes, 33.6 seconds; 1.609344 km in 3 minutes, 59.2 seconds; • various kinds of inputs that the program can't read. 456789 18 19 20 21 22 23 24 25 26 10 11 // PROMISES: 12 // 13 // 14 // 15 // 16 17 27 28 29 30 31 32 33 34 35 36 37 38 #include <stdio.h> #include <stdlib.h> 39 40 41 int get_int_or_exit(void); // REQUIRES: // User has been prompted to enter an int. Function tries to read an int using scanf and "%d" On success, that int is echoed to the user, and the int is the function return value. On failure, and error message is printed and exit is called with an argument of 1. double get_double_or_exit(void); // Like get_int_or_exit, but tries to read a double using "%lf". int main(void) { int i; printf("Testing get_int_or_exit. Please enter a line of text i = get_int_or_exit(); printf("get int_or_exit returned a value of %d.\n", i); return 0; int get_int_or_exit (void) { int result; if (1 l = scanf("%d", &result)) { printf("I could not read an int. I am quitting. \n"); exit (1); } printf("I read an int value of %d.\n", result); return result; What to Do Download the file get-numbers.c. Read the code, then build an executable and run it a few times to see if it behaves the way you expect. Then add a definition for get_double_or_exit, and add code to main that will allow you to test your definition. Note: A sequence of digits without a decimal point-such as 123-can be read into an int and also into a double. get_double_or_exit ahould accept that kind of input. Exercise B: Writing a complete program What to Do The program you will write here will be a simple utility for a long-distance runner. The input will be a distance and a time, and the output will be the average times taken per kilometre and per mile. Write a program that asks a user for a distance in kilometres, as a double, and a time interval, as an int and a double; a number of minutes, and a number of seconds. If the program succeeds in reading all three numbers, it should report the output specified above. Here is a sample of a successful dialogue with the program, with slanted typewriter font used to show what was typed by a user: Please enter a distance in km, using type double. 10.0 I read a double value of 10.000000. Please enter a number of minute, using type int. 39 I read an int value of 39. Please enter a number of seconds, using type double. 47.2 I read a double value of 47.200000. Distance run: 10.000000 km. Time of run: 39 minute(s), 47.200000 second(s). Average time for 1 km: 3 minute(s), 58.720000 seconds (s). Average time for 1 mile: 6 minute(s), 24.182600 seconds(s). And here is a sample of an unsuccessful dialogue: Please enter a distance in km, using type double. No! You can't make me! I could not read a double. I am quitting. For the most part, you may organize your program however you see fit, except for the following, which I insist on, so that you get practice with some of the key C features used in previous lab exercises: • The three input numbers should be collected by a function with exactly this prototype: void get input (double .km in, int minutes in, double seconds_in); The get_input function should make calls to get_double_or_exit and get_int_or_exit-you can copy and paste the prototypes and definitions from Exercise A. Note: 1 mile is exactly 1609.344 metres. What to Include in your PDF Submission Include a complete listing of your program source code, and a listing of terminal input/output showing a few tests, including: 42.195 km in 179 minutes, 33.6 seconds; 1.609344 km in 3 minutes, 59.2 seconds; • various kinds of inputs that the program can't read. 456789 18 19 20 21 22 23 24 25 26 10 11 // PROMISES: 12 // 13 // 14 // 15 // 16 17 27 28 29 30 31 32 33 34 35 36 37 38 #include <stdio.h> #include <stdlib.h> 39 40 41 int get_int_or_exit(void); // REQUIRES: // User has been prompted to enter an int. Function tries to read an int using scanf and "%d" On success, that int is echoed to the user, and the int is the function return value. On failure, and error message is printed and exit is called with an argument of 1. double get_double_or_exit(void); // Like get_int_or_exit, but tries to read a double using "%lf". int main(void) { int i; printf("Testing get_int_or_exit. Please enter a line of text i = get_int_or_exit(); printf("get int_or_exit returned a value of %d.\n", i); return 0; int get_int_or_exit (void) { int result; if (1 l = scanf("%d", &result)) { printf("I could not read an int. I am quitting. \n"); exit (1); } printf("I read an int value of %d.\n", result); return result;
Expert Answer:
Answer rating: 100% (QA)
include include void getdoubleorexitconst char prompt double value printfs prompt if scanflf value 1 ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
From the results of the 2000 census, the population in Sukarame Village was 4,735 people, consisting of 1,941 people aged 0 - 14 years, 2,431 people aged 15 - 64 years and the rest over 64 years old....
-
Find the next node in the least cost path in the following network using Distance vector algorithm. 5 W LO 5 2 2 2 Z 3 5 X- 1 Source - y Destination- v
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
In Exercises 8486, use a graphing utility to graph f and g in the same [-8, 8, 1] by [-5, 5, 1] viewing rectangle. In addition, graph the line y = x and visually determine if f and g are inverses....
-
Using the following information, the estimation formula for which type of hypothesis test was computed? (a) The estimated standard error for the difference was computed. (b) The estimated standard...
-
Acceleration is generally defined as the time rate of change of velocity. When can it be defined as the time rate of change of speed?
-
Match each of the following roles of a cost management system, 1 through 6 , with the most appropriate example, a through \(f\). Cost Management System Role 1. Develop accurate product/ service costs...
-
Erte, Inc., manufactures two models of high-pressure steam valves, the XR7 model and the ZD5 model. Data regarding the two products follow: Additional information about the company follows: a....
-
John and Mary Hazlitt left the airport taxi and carried their bags into their high - rise apartment building. They admired the gifts they had brought back - an illustrated book for themselves; a...
-
The following balances were taken from the book of JACK Partnership as of July 1, 2015 when the partnership decided to liquidate: Accounts Receivable, net Furniture & Fixtures, net Sales Proceeds...
-
Suppose that there is a small country named A in the world. However, there is a king in the country A, who does not allow households in the country to trade in international financial markets....
-
1. What is liquidity a measure of?Discuss the potential merits of high liquidity verses low liquidity. 2. A firm is engaging in a large capital project. It requires 100 Million Dollars for this...
-
Write on autocratic crime, you need to address (1) what autocratic crime is, its main characteristics and symptoms; (2) what social factors and forces lie under autocratic crime; (3) how autocratic...
-
Provide two examples of companies that show an adverse budget variance over a period of time (2020). For one of the companies, comment on XPeng and how their variance in budget (estimates of...
-
Explain the principles behind NoSQL database design and its suitability for handling unstructured or semi-structured data.
-
In the context of NoSQL databases, what is consistency? why is it important? Provide references.
-
Jones Public Accountants has been hired to perform a financial audit for Wyoming Electric Cooperatives Corporation. Under the Sarbanes-Oxley Act of 2002 (SOX), once Jones has completed the audit, it...
-
From 1970 to 1990, Sri Lanka's population grew by approximately 2.2 million persons every five years. The population in 1970 was 12.2 million people.What is the best formula for P, Sri Lanka's...
-
Quince Interests is a partnership with a tax year that ends September 30, 2012. During that year, Potter, a partner, received $3,000 per month as a guaranteed payment, and his share of partnership...
-
Kent Pham, CPA, is a 45-year-old single taxpayer living at 169 Trendie Street, La Jolla, CA 92037. His Social Security number is 865-68-9635. In 2012, Kent's W-2 as the controller of a local...
-
Jerry made the following contributions during 2012: His synagogue (by check).....................................................$680 The Democratic Party (by check)...
-
Most economists believe that in the long run inflation is caused by printing too much _________.
-
Government policies called _________ policy use taxes and government spending to try to help stabilize the economy.
-
_________ is the number of goods and services a worker can produce per hour, and _________ economic growth occurs when workers productivity rises.
Study smarter with the SolutionInn App