该项目要求开发一个C++程序,实现多次道路旅行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
- 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. - 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.
- 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.
- 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 | M |
Sample Output for the Above Input
1 | MILES KMETERS $/Gal $/Lit ML/Gal KM/Liter Trip Cost |
Input Validation Examples
The program will prompt the user again if invalid data is entered, for example:
1 | Enter unit type ('M' for Metric, 'E' for English, 'Q' to quit): m |
Program Termination Message
Upon quitting, display:
1 | Thank you for using the program! |