Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem: Write a program to analyze data about the gas mileage of cars. A fuel- economy study was carried out for various models of cars.

image text in transcribed
image text in transcribed
image text in transcribed
Problem: Write a program to analyze data about the gas mileage of cars. A fuel- economy study was carried out for various models of cars. Each car was driven 100 miles and the number of gallons used were recorded. The car model names and gallons used are stored in the file pgm7xt. 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., ChevyC_pgm7 and ChevyC_pgm7 xpp). Display the output on the screen. Program Design: Your program should define three arrays. Two of the arrays will hold the data read from the psm7 rxt file the car model names and the gallons used to go 100 miles. The third array will store the miles per gallon for each vehicle as calculated by your program. These three parallel 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. Choose a meaningful name for each function based on what it does. Each function should begin with comments describing the purpose of the function 1. The model of each car tested and the gallons of gas used to go 100 miles are stored in the file pgm7sxt. Copy this file to your project folder. Write a function to open the file, read in the data and store it in two parallel arrays and close the file. Store 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 I of the two arrays, etc As the data for each car model is read, this function should count it and pass the final count back to the main function. The count of the number of cars read will be passed on to other functions and used to determine how many elements of the array actually contain data (Gi.e., you will be working with partially-filled arrays). Close the file at the end of 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 Camry 3.5 Accord 4.4 etc. Write 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, Camry and 35 should be stored in element 0 of the string and first double arrays. Calculate the miles per gallon for this vehicle (100/3 5) and store the result in element 0 of the second array of type double. Do the same for each vehicle. 2. Write a function to display each vehicle's model, gallons used and miles per gallon (displayed as a whole number). Include a heading with a titdle, your name and column headings (see sample on next page). 3

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

More Books

Students also viewed these Databases questions

Question

12. What are their values? (ethical stance in society)

Answered: 1 week ago