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....
-
Coil 1 is a fl at circular coil that has N1 turns and a radius R1. At its center is a much smaller flat, circular coil that has N2 turns and radius R2. The planes of the coils are parallel. Assume...
-
How does the valuation of trade receivables impact on the income statement of a business?
-
Discuss, with reasons, whether boats held by the dealers on consignment should appear as inventory in the balance sheet of Swann SpA or the dealer.
-
Serena Madison wishes to purchase a $820,000 house. She has accumulated a $180,000 down payment, but she wishes to borrow $640,000 on a 15-year mortgage. For simplicity, assume annual mortgage...
-
The steeple of a building is in the shape of a regular pyramid with a triangular base. Each of the 3 base sides is 4.6 meters long, and the steeple is 7 meters high. Compute the number of cubic...
-
Cyprus Citrus Cooperative ships a high volume of individual orders for oranges to northern Europe. The paperwork for the shipping notices is done in the accompanying layout. Revise the layout to...
-
D Question 18 Turnkey Company had the following total assets, liabilities, and Total Assets $55,000 Total Liabilities 24,750 Total Equity 30,250 What is the company's debt ratio as of December 31?...
-
An organisation with weak transport management suffers as it gives worse performance than more competent competitors and becomes uncompetitive; one with strong transport management may be diverting...
-
The essential qualities of the internal auditor do not include: a. Adaptability. b. Determination. c. Understanding. d. Education. e. Objectivity.
-
For most organisations road transport is the only realistic mode of transport. If this is true, why do so many people disapprove of heavy lorries? Are there any noticeable trends in the choice of...
-
There is a growing number of free trade areas. Why? Do they really allow free trade between members? If free trade is such a good idea, why do countries not simply remove all their duties and tariffs...
-
To build a superior staff, one must first know: a. The kinds of auditors available in the marketplace. b. The kinds of courses being taught in business administration schools. c. The standards for...
-
For part one, start by examining the financial impact of your rewards for an initiative or your strategic goals. Note the compensation elements you are considering and list your key stakeholders....
-
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)...
-
In 1969, William Kling, then age 26, was managing a radio station at St. John's Abbey and University in Minnesota. He hired a young man named Garrison Keillor to host a classical music program in the...
-
Founded in 1997 in Washington, DC, by social entrepreneurs Rajiv Vinnakota and Eric Adler, the SEED Foundation operates urban, college-preparatory, public boarding schools in Washington, DC,...
-
Go back and read the case of Aspire CoffeeWorks in Chapter
Study smarter with the SolutionInn App