Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program to perform various calculations related to the fuel economy of a vehicle where the fuel economy is modeling using a polynomial

Write a C++ program to perform various calculations related to the fuel economy of a vehicle where the fuel economy is modeling using a polynomial of the form image text in transcribed , where

y = fuel economy in miles per gallon (mpg)

x = mph

Inputs: The user should be prompted to input the following information.

The values for coefficients A, B, and C used to model the fuel efficiency

The capacity of the fuel tank (in gallons).

The current amount of fuel in the tank (in gallons).

The current speed of the vehicle (in mpg)

The distance to be traveled on the current trip (in miles)

The cost per gallon for gasoline

The minimum speed, Smin, to be used in the table of Fuel Economy vs Speed

The maximum speed, Smax, to be used in the table of Fuel Economy vs Speed

The speed increment, Sinc, to be used in the table of Fuel Economy vs Speed

Functions: The program should use at least 4 user-defined functions (in addition to main) as described below.

* MPG(A, B, C, Speed) This function returns the fuel economy in mpg for a given speed in mph.

* PrintTable(Smin, Smax, Sinc A, B, C) This function will print a table of Speed (in mpg) and Fuel Economy (in mpg).

Use the range of speeds indicated with the speed increment indicated.

This function should call the function MPG above.

Fuel economy should be calculated using the coefficients A, B, and C provided.

Include a table heading with units.

Display speeds as integers and fuel economy with 2 digits after the decimal point (include trailing zeros).

MaxEconomy(Smin, Smax, Sinc A, B, C, MaxMPG, MaxMPH) This function will return the maximum mpg and the corresponding speed value using the speed range and increment specified. This function should call the function MPG above.

Use at least one more useful (user-defined) function to calculate one or more of the program outputs.

Outputs: The program output should include the following:

Neatly summarize the input values

A table of Speed and Fuel Economy values (created by the PrintTable function above).

The maximum fuel economy (in mpg) and the corresponding speed (determined by the MaxEconomy function above).

The fuel economy (in mpg) at the current speed

The minimum fuel economy (in mph) and the corresponding speed. Note: This does not always occur at the minimum speed.

For the current speed, trip distance, number of gallons currently in the tank, and cost per gallon for fuel (show the value of each), display the following:

The fuel economy (in mpg)

Speed for the trip (in mph)

The fuel cost for the trip.

The number of gallons that will be used for the trip.

The time to reach the destination.

State how many times you will need to stop for gas. Assume that the tank must be filled when it is 10% full.

State the number of gallons of gas will be left in the tank at the end of the trip.

State the number of miles until the next time the tank must be filled (after the trip).

Repeat the above if you drive at the speed for maximum fuel economy. Also state how many gallons of gas were saved and how much money was saved by driving at the speed for maximum fuel efficiency.

Use a suitable number of digits for all numeric outputs and include units when appropriate.

Error Checks: The program should check for appropriate ranges for inputs and allow the user to re-enter any incorrect inputs, including:

Fuel tank capacity: 0 to 20 gallons

Current amount of fuel in tank: 20% - 100% of fuel tank capacity

Current speed of vehicle: 20 to 80 mph

Distance to be travelled: Must be > 0

Cost per gasoline: Must be > 0

Minimum speed for table (Smin): Integer value where 20

Maximum speed for table (Smax): Integer value where (Smin + 10)

Speed increment for table (Sinc): Integer value where 0

Re-running the Program: Include a loop that will give the user the option of re-running the program.

{Note: I already have a running program but something seems off about it, and I would like to do a comparison to figure out what I'm doing wrong. Can someone please help me?}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions