Question: Write a C++ program that uses functions. The program will be used to calculate the amount of money spent on a car per month. Overall,

Write a C++ program that uses functions. The program will be used to calculate the amount of money spent on a car per month. Overall, the program will read in the necessary data from a file and then print out the total cost on the screen. You must use functions to perform the necessary calculations (see below for a description of each required function). All the required data should be read in from a file. You need to create that file yourself (use Notepad or Visual Studio). Your program should open the file that you created and read in the data from it. The following data should be stored in the file:

Miles driven for the year

Car miles per gallon (amount of miles the car travels on 1 gallon of gas)

Cost of gas per gallon

Amount spent on maintenance for the year

Car insurance premium for the year

You are required to write the following functions:

Function Name

Return Type

Parameter List

(double milesPerYear, double carMilesPerGallon, double gasCostPerGallon)

This function should calculate and return the cost of gas per month. All parameters should be passed in by value.

Hint: First calculate how many gallons of gas the car used for the year (milesPerYear / carMilesPerGallon). Store that result in a local temporary variable and go from there.

(double mainYearAmt)

The maintenance amount for the year is passed into this function. The cost of maintenance per month should be returned. The parameter is passed in by value.

(double yearPremium)

The premium amount for the year is passed into this function. The premium cost per month should be returned. The parameter is passed in by value.

(double gasCostPerMonth, double insCostPerMonth, double mainCostPerMonth, double& totalCost)

Add the three monthly amounts together to calculate the total monthly cost. The total amount should be passed back to the calling function through the reference parameter instead of as a return value. The first three parameters should be passed in by value. The last parameter is passed by reference.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!