C++代写:COMP104 Road Trip

完成关于Road trip的价格和耗油量与公里数的计算。

Road trip

SHORT DESCRIPTION OF PROGRAM

Write a C++ program that inputs data about a road trip, computes statistics about the trip in both English and metric units, and prints a report with these statistics. This program loops to process any number of trips. See the SAMPLE RUNS section below.

INPUT DATA DESCRIPTION

  1. ‘M’ for Metric input, ‘E’ for English input units, ‘Q’ or ‘q’ to quit. This program processes any number of trips and terminates when a ‘Q’ or ‘q’ is read.
  2. Volume of gas consumed on the trip: The unit type of #1 is assumed - either liters for Metric or gallons for English units. This volume must be positive ( greater than 0.0). The program loops until a valid input is read for the volume of gas consumed.
  3. Price of gas per volume: Dollars per liter or per gallon is assumed based on the unit type entered in #1. Price per volume must be greater than 0.75 and less than 5.00. The program loops until a valid input is read for the price of gas.
  4. Trip distance: The distance of the road trip is assumed to be either kilometers or miles based on the unit type entered in #1. The trip distance must be greater than or equal to 16.00 and less than 2800.00. The program loops until a valid input is read for the trip distance .

OUTPUT REPORT DESCRIPTION

  1. Trip distance in miles with three decimal digits precision.
  2. Trip distance in kilometers with three decimal digits precision.
  3. Fuel price per gallon with two decimal digits precision.
  4. Fuel price per liter with two decimal digits precision.
  5. Mileage in miles per gallon with three decimal digits precision.
  6. Mileage in kilometers per liter with three decimal digits precision.
  7. Total trip fuel cost with two decimal digits precision.

CONVERSION FACTOR

Liters per gallon conversion factor = 3.79 and kilometers per mile = 1.61. Make sure that you use these conversion factors exactly, otherwise your results will differ from that of the Grader and your program will not be accepted.

REQUIREMENTS

  • You must define constants for the valid menu items and the ranges of input numbers. No magic numbers!
  • To get credit for the assignment, your solution must minimally work on the data in the first test case (see below).
  • As always, you must follow the programming standards.
  • You are not required to use functions in this assignment.
  • Programming assignments must be done individually
  • You must use at least one sentinel controlled loop.
  • You must use at least one nested loop.
  • When prompting for input, you must use the numeric constants rather than including their value inside of a literal string. If you do use any of the values of numeric constants inside a literal string, you will lose some credit.

EXAMPLE INPUT

Notes in italic font are not entered, but are descriptions of the input. The run using this input data (test1.txt) is listed in the next section below.

M       Trip 1: Metric Units
10.9    Volume of fuel consumed on the road trip, in this case liters
1.54    Price of fuel per unit volume
502.1   Distance of the road trip
E       Trip 2: English Units
10.9    Volume of fuel consumed on the road trip, in this case gallons
1.54    Price of fuel per unit volume
502.1   Distance of the road trip e Non-valid input, must be a 'E', 'M', 'Q', or 'q'
E       Trip 3: English Units
15.9    Volume of fuel consumed on the road trip
2.54    Price of fuel per unit volume
402.1   Distance of the road trip
Q       Quit execution of the program

Sample Run (test2.txt as input)

m       Non-valid input, must be a 'E', 'M', 'Q', or 'q'
M       Trip 1: Metric Units
-10.9   Non-valid input for fuel consumed, reenter
10.9    Volume of fuel consumed on the road trip
-1.54   Non-valid input for price of fuel, reenter
1.54    Price of fuel per unit volume
-502.1  Non-valid input for trip distance, reenter
502.1   Distance of the road trip
E       Trip 2: English Units
-11.9   Non-valid input for fuel consumed, reenter
11.9    Volume of fuel consumed on the road trip
1.45    Price of fuel per unit volume
502.1   Distance of the road trip e Non-valid input, must be a 'E', 'M', 'Q', or 'q'
E       Trip 3: English Units
15.9    Volume of fuel consumed on the road trip
-2.54   Non-valid input for price of fuel, reenter
2.54    Price of fuel per unit volume
402.1   Distance of the road trip q Quit execution of the program

SAMPLE RUNS

Sample Run (test1.txt as input)

The program calculates mileage and other statistics
for a road trip in both Metric and English units.

Enter the type of measurement units
'M' for Metric or 'E' for English or
'Q' or 'q' for Quit: M

Please enter the volume of gas consumed: 10.9

Please enter the price of gas per unit volume: 1.54

Please enter the trip distance: 502.1

 MILES  KMETERS $/Gal $/Lit ML/Gal  KM/Liter Trip Cost
311.863 502.100 5.84  1.54  108.437 46.064   16.79

Enter the type of measurement units
'M' for Metric or 'E' for English or
'Q' or 'q' for Quit: E

Please enter the volume of gas consumed: 10.9

Please enter the price of gas per unit volume: 1.54

Please enter the trip distance: 502.1

 MILES  KMETERS $/Gal $/Lit ML/Gal  KM/Liter Trip Cost
502.100 808.381 1.54  0.41  46.064  19.568   16.79

Enter the type of measurement units
'M' for Metric or 'E' for English or
'Q' or 'q' for Quit: e
Please reenter the type of measurement units
'M' for Metric or 'E' for English: E

Please enter the volume of gas consumed: 15.9

Please enter the price of gas per unit volume: 2.54

Please enter the trip distance: 402.1
 MILES  KMETERS $/Gal $/Lit ML/Gal  KM/Liter Trip Cost
402.100 647.381 2.54  0.67  25.289  10.743   40.39

Enter the type of measurement units
'M' for Metric or 'E' for English or
'Q' or 'q' for Quit: Q

Thanks for using the program!
End of First Example Run.

Sample Run (test2.txt as input)

The program calculates mileage and other statistics
for a road trip in both Metric and English units.

Enter the type of measurement units
'M' for Metric or 'E' for English or
'Q' or 'q' for Quit: m

Please reenter the type of measurement units
'M' for Metric or 'E' for English: M

Please enter the volume of gas consumed: -10.9
Please reenter the volume gas consumed (it must be greater than 0.00): 10.9

Please enter the price of gas per unit volume: -1.54
Please reenter Fuel Price (it must be higher than 0.75 and lower than 5.00) :1.54

Please enter the trip distance: -502.1
Please reenter a trip distance greater than or equal to 16.00 and less than 2800.00: 502.1

 MILES  KMETERS $/Gal $/Lit ML/Gal  KM/Liter Trip Cost
311.863 502.100 5.84  1.54  108.437 46.064   16.79

Enter the type of measurement units
'M' for Metric or 'E' for English or
'Q' or 'q' for Quit: E

Please enter the volume of gas consumed: -11.9
Please reenter the volume gas consumed (it must be greater than 0.00): 11.9

Please enter the price of gas per unit volume: 1.45
Please enter the trip distance: 502.1

 MILES  KMETERS $/Gal $/Lit ML/Gal  KM/Liter Trip Cost
502.100 808.381 1.45  0.38  42.193  17.924   17.26

Enter the type of measurement units
'M' for Metric or 'E' for English or
'Q' or 'q' for Quit: e

Please reenter the type of measurement units
'M' for Metric or 'E' for English: E

Please enter the volume of gas consumed: 15.9

Please enter the price of gas per unit volume: -2.54

Please reenter Fuel Price (it must be higher than 0.75 and lower than 5.00) :2.54

Please enter the trip distance: 402.1
 MILES  KMETERS $/Gal $/Lit ML/Gal  KM/Liter Trip Cost
402.100 647.381 2.54  0.67  25.289  10.743   40.39

Enter the type of measurement units
'M' for Metric or 'E' for English or
'Q' or 'q' for Quit: q

Thanks for using the program!

End of Second Example Run.