C++代写:COMP104 Road Trip Fuel and Cost Calculator

该项目要求开发一个C++程序,实现多次道路旅行Road trip统计,支持公制和英制单位输入,具备严格输入验证,计算并输出多项详细里程与燃油费用指标,确保结果精确且符合规范要求。

Road trip

Project Overview

Develop a C++ program that accepts user input about a road trip, calculates various trip statistics in both Metric and English units, and outputs a detailed report. The program should repeatedly process multiple trips until the user opts to quit.

Input Data Description

  1. Unit Selection: Enter 'M' for Metric units, 'E' for English units, or 'Q'/'q' to quit the program. The program processes any number of trips until 'Q' or 'q' is entered.
  2. Fuel Volume Consumed: Input volume of fuel used during the trip. Units depend on the selection: liters for Metric, gallons for English. Must be greater than 0. The program will repeatedly prompt until valid input is given.
  3. Fuel Price per Unit Volume: Price per liter or gallon depending on unit system. Must be between 0.75 and 5.00. Input will be validated and re-prompted if invalid.
  4. Trip Distance: Distance traveled during the trip in kilometers or miles depending on the unit choice. Must be between 16.00 and 2800.00. Invalid inputs will cause re-prompting.

Output Report Specifications

The program should output the following trip statistics with specified decimal precision:

  • Trip distance in miles (3 decimal places)
  • Trip distance in kilometers (3 decimal places)
  • Fuel price per gallon (2 decimal places)
  • Fuel price per liter (2 decimal places)
  • Mileage in miles per gallon (3 decimal places)
  • Mileage in kilometers per liter (3 decimal places)
  • Total trip fuel cost (2 decimal places)

Conversion Constants

  • 1 gallon = 3.79 liters
  • 1 mile = 1.61 kilometers

Use these exact constants to ensure output matches grading requirements.

Program Requirements

  • Define constants for menu options and valid input ranges to avoid magic numbers.
  • Use at least one sentinel-controlled loop to allow multiple trip calculations until user quits.
  • Include at least one nested loop for input validation.
  • Functions are optional but encouraged for better code structure.
  • The assignment must be completed individually.
  • All input prompts must use the defined constants rather than hardcoded literals.

Example Input Sequence

1
2
3
4
5
6
7
8
9
10
11
12
13
M
10.9
1.54
502.1
E
10.9
1.54
502.1
E
15.9
2.54
402.1
Q

Sample Output for the Above Input

1
2
3
4
5
6
7
8
 MILES  KMETERS $/Gal $/Lit ML/Gal  KM/Liter Trip Cost
311.863 502.100 5.84 1.54 108.437 46.064 16.79

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

MILES KMETERS $/Gal $/Lit ML/Gal KM/Liter Trip Cost
402.100 647.381 2.54 0.67 25.289 10.743 40.39

Input Validation Examples

The program will prompt the user again if invalid data is entered, for example:

1
2
3
4
5
6
7
8
9
10
11
Enter unit type ('M' for Metric, 'E' for English, 'Q' to quit): m
Invalid input. Please enter 'M', 'E', or 'Q': M

Enter fuel volume consumed (must be > 0): -10.9
Invalid input. Please re-enter fuel volume consumed (> 0): 10.9

Enter fuel price per unit volume (0.75 - 5.00): -1.54
Invalid input. Please re-enter fuel price (0.75 - 5.00): 1.54

Enter trip distance (16.00 - 2800.00): -502.1
Invalid input. Please re-enter trip distance (16.00 - 2800.00): 502.1

Program Termination Message

Upon quitting, display:

1
2
Thank you for using the program!
Program terminated.