C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
Question
Book Icon
Chapter 8.2, Problem 8E

(a)

Program Plan Intro

To create a file named as car.dat and insert the given data without the headings.

(b)

Program Plan Intro

Program plan: -

  • Import header file and use namespace for standard I/O.
  • Define the main function.
  • Create the object of ifstream class and opening the file.
  • Declare the variables.
  • Use the while-loop to iterateover the file to read the content.
  • Display the header.
  • Calculate the mpg.
  • Increment the value of total cars after reading each line.
  • Calculate the total Miles Driven the total Gallons Used.
  • Display the total Miles Driven, total Gallons Used, and then calculate and display the average gallons used.

Program description: -

The main purpose of the program is to read the data of the file created in exercise 8a and display the car number, miles driven, gallons of gas used, and miles per gallon. Also, calculate and display the total miles driven, total gallons used and the average mpg for all cars.

Blurred answer
Students have asked these similar questions
For each of the following statements, state whether it is True or False.
1)Use c code to add the function in the program to provide for purchase amount of RM80.00 or more, the delivery charge is waived and for purchase amount of RM100 or more, a 15% discount is given.
C++ program chose the correct result for each of the following programming statements
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning