Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ok I am stuck once again, the following is what I have so far and he requirement are as stated; my program should read from

ok I am stuck once again, the following is what I have so far and he requirement are as stated;

my program should read from a file, "FleetInput.txt" which I have in the correct directory, I have defined the fields note: my "cout" i want to generate a report to list vehicle id, miles travel, gallons used, and miles per gallon MPH. then to summarize total miles travel, average MPG, then parse out the best MPG and worst MPG

#include  #include  // Reserve for Constants #include  #include  using namespace std; // Declarations Section - Reserved for Constants int main() { ifstream inputFile; string filename = "FleetInput.txt"; // Declare required variables here int Miles; int Gallons; int MPG; string vehicleID; int count; int Total_Miles; int Average_MPG; // Open the file FleetInput.txt inputFile.open(filename); //if the file successfully opened, process it. if (inputFile) { // Insert loop here to read and process the next file. // loop until there is no more data in the file while (!(inputFile.eof())) { //read three values for each line // vehicleID stores the Vehicle ID number, Total_Miles this is the second field // MPG it the third field Miles per gallon inputFile >> vehicleID >> Total_Miles >> MPG; } // Before loop, display report header // In the loop accumulate total miles, calculate average mpg } //end while //close the file inputFile.close(); } else { // Display error message cout << "Error opening the file. "; // Also display the vehicleID, miles, gallons and mpg cout << " AMSCo FLEET Report"; cout << " Vehicle ID Miles Gallons MPG"; cout << " ----------------------------------------------------------------------------------"; cout << " "<< vehicleID << Miles << Gallons << MPG <<; // And determine the best and worst mpg and the vehicle that produced them. cout << " ----------------------------------------------------------------------------------"; cout << " count:'" << count; // After loop, display count, average, etc. cout << " Total Miles:" << Total_Miles << ; cout << " Average MPG:" << Average_MPG << ; cout << " Vehicle ID with Best MPG:" << vehicleID << MPG <<; cout << " Vehicle ID with worst MPG:" << vehicleID << MPG <<; return o; }//End of main() 

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions