Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the program and I want the program as a c++ solution. Also, the text of the program is here :- Prius2.1 Camry4.1 Sebring4.2

Here is the program and I want the program as a c++ solution.

Also, the text of the program is here :-

Prius2.1

Camry4.1

Sebring4.2

Mustang5.3

Accord4.1

Camry3.8

Camry3.9

Mustang5.2

Accord4.3

Prius2.3

Camry4.2

Accord4.4

Problem: A fuel-economy study was carried out for five models of cars. Each car was driven 100 miles. Then the car model and number of gallons used were entered in the file pgm7.txt. Write a C++ program to analyze this data. Create a project using your last name, first initial and pgm7 for the project folder and .cpp file names (e.g., FordH_pgm7 and FordH_pgm7.cpp). Your output may be displayed on the screen.

Input: The model of each car tested and the gallons of gas used to go 100 miles is stored in the file pgm7.txt. Copy this file to your project folder. Your project should read in each model name and gallons used and store and store the data in parallel arrays. Then using the data stored in the arrays, perform the steps described below.

Program Design: Your program should define three arrays: a string array to hold the model names, a double array to hold the gallons used and another double array that will be used to store the miles per gallon for each vehicle. These arrays must be declared inside the main function and passed as arguments to the functions that need to use them. Your program should handle data for any number of vehicles up to a maximum of twenty.

Your main function should call the functions described below. Each function should begin with comments describing the purpose of the function.

1. Call a function to read the model names and gallons used from the filepgm7.txt, storing each model name in an element in an array of type string and the gallons in the same position in an array of type double. For example, the first model name and gallons read in should be stored in element 0 of the two arrays, the next model and gallons read in should be stored in element 1 of the two arrays, etc. Count the number of vehicles read in and pass this count back to the main function. It will be passed on to other functions and used to determine how many elements of the array actually contain data. Open and close the data file in this function. All further processing must be done using the data values stored in the arrays. The first few lines in the file look like this:

Prius

2.1

Camry

4.1

. . .

2. Call a function to find the miles per gallon for each vehicle and store the value in the corresponding element in the second array of type double. For example, Prius and 2.1 should be stored in element 0 of the string and first double arrays. Calculate the miles per gallon for this vehicle (100/2.1) and store the result in element 0 of the second array of type double. Do the same for each vehicle.

3. Call a function to display each vehicle's model, gallons used and miles per gallon. Include a heading with a title, your name and column headings (see sample on next page).

Vehicle Miles Per Gallon

Your Name

Model Gallons used/100 miles MPG

--------------------------------------

Prius 2.1 48

Camry 4.1 24

. . . . . . .

4. Call a function that prompts the user to enter a model name and displays the average number of gallons used by vehicles with that model name. For example, if the user enters "Prius", the function should display the message:

The average number of gallons used to travel 100 miles by Prius vehicles was 2.2 gallons.

If the user enters "Corolla", the function should display the message: No Corolla vehicles tested.

5. Call a function to sort the arrays in descending order by the miles per gallon. Be sure that whenever you switch two elements in the miles per gallons array to also switch the same pair of elements in the model name and gallons used arrays.

6. Call the function from step 3 again after the sort to display each vehicle, the gallons used and the miles per gallon. Include a heading with a title, your name and column headings.

Vehicles Sorted by MPG

Your Name

Model Gallons used/100 miles MPG

--------------------------------------

Prius 2.1 48

Prius 2.3 43

. . . . . . .

Turning in your program: When you are satisfied that your program is producing the correct output, turn your program in (.cpp file only) on Canvas.

Program Documentation & Style:

1. Declare all constants and variables that your program uses at the beginning of your program.

2. Your program should include three types of comments. BE SPECIFIC!

a. Header comments at the beginning of your program including lines with:

- Your name, course name, and class time

- Program assignment number, program file name and due date

- Purpose: a sentence or two explaining the purpose of the program

- Input: a description of the input data needed by the program when you run it

- Processing: a description of the processing (calculations) done by the program

- Output: a description of the results (output) produced by the program

b. In-line comments: There should be an in-line comment for each main step in your program. In general, this means at least one comment with each group of C++ statements that handles the input, the processing and the output steps of your program.

c. Function comments: Include a sentence or two before each function definition explaining the purpose of the function.

3. Use meaningful identifier names

4. Include clear prompts for the user about entering the data.

5. Include clear descriptions of the results when you display them.

Grade Sheet

CS2010 Program 7: Car Mileage

Due: 11:59 pm, Wednesday, April 27, 2016

_______ Project named correctly and .cpp file turned in on Canvas.

_______ (2) Header comments complete, including labeled sections identifying the Purpose, Input, Processing and Output

_______ (2) Function, in-line comments complete

_______ (1) Uses good program style (meaningful datanames, whitespace, indentation)

_______ (4) Function to read in model names and gallons used from file correct. Uses parameter passing correctly. Function prototype included. Input file opened/closed in this function.

_______ (3) Function to calculate miles per gallon and store values in third array correct. Uses parameter passing correctly. Function prototype included.

_______ (4) Function to display each vehicle's model, gallons used and miles per gallon correct. Includes heading as described. Uses parameter passing correctly. Function prototype included.

_______ (3) Function to find and display average miles per gallon for a particular model correct. Displays correct message if model not found. Uses parameter passing correctly. Function prototype included.

_______ (4) Function to sort arrays in descending order by miles per gallon correct. Uses parameter passing correctly. Function prototype included.

_______ (2) Calls function from step 3 again to display contents of arrays after sorting.

_______ (25) Total Points

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

Students also viewed these Databases questions