Question: The revised program still can't read the data from the text file and can't get the highest horsepower and lowest displacement. When I run the
The revised program still can't read the data from the text file and can't get the highest horsepower and lowest displacement.
When I run the program,
the output below:
Welcome to the Data Analysis Program!
This program will read from a file and find out which car has the highest horsepower and lowest displacement.
Please enter the input file name: data.txt
Car with the highest horsepower is names with hp
Car with lowest displacement is names with cc
But the result should be read from a text file and get the highest car horsepower and lowest displacement how can I do that, thanks
Welcome to the data analysis program:
This program will read from a file called automobile.csv gather the data and find out which car has the highest horsepower and lowest displacement.
Please enter the input file name: data.txt
names displacement horsepower
chevrolet chevelle malibu
buick skylark
plymouth satellite
amc rebel sst
ford torino
ford galaxie
Car with highest horsepower is ford galaxie with hp
Car with lowest displacement is ford torino with cc
Thanks for using the data analysis program.
#include
#include
#include
#include
using namespace std;
Constants for number of items and maximum characters
const int ITEMS ;
const int MAXCHAR ;
Function prototypes
void welcome;
void openFileifstream& inFile, const char fileName;
void openFileofstream& outFile, const char fileName;
int readDataifstream& inFile, char namesMAXCHAR double displacement double
horsepower;
void printDatachar namesMAXCHAR double displacement double horsepower int count;
void printDatachar namesMAXCHAR double displacement double horsepower int count,
ofstream& outFile;
int main
ifstream inFile;
ofstream outFile;
char fileNameMAXCHAR;
double displacementITEMS;
double horsepowerITEMS;
char namesITEMSMAXCHAR;
welcome;
cout "Please enter the input file name: ;
cingetlinefileName MAXCHAR;
openFileinFile fileName;
strcpyfileName "output.txt;
openFileoutFile fileName;
int count readDatainFile names, displacement, horsepower;
int maxHpIndex minDispIndex ;
for int i ; i count; i
if horsepoweri horsepowermaxHpIndex
maxHpIndex i;
if displacementi displacementminDispIndex
minDispIndex i;
cout "Car with highest horsepower is namesmaxHpIndex with
horsepowermaxHpIndex hp endl;
cout "Car with lowest displacement is namesminDispIndex with
displacementminDispIndex cc endl;
printDatanames displacement, horsepower, count;
printDatanames displacement, horsepower, count, outFile;
return ;
void welcome
cout "Welcome to the Data Analysis Program!
;
cout "This program will read from a file and find out which car has the highest horsepower and lowest displacement.
;
void openFileifstream& inFile, const char fileName
inFileopenfileName;
if inFile
cout "File did not open! Program terminating!" endl;
exit
;
void openFileofstream& outFile, const char fileName
outFileopenfileName;
if outFile
cout "File did not open! Program terminating!" endl;
exit
;
int readDataifstream& inFile, char namesMAXCHAR double displacement double
horsepower
int count ;
while inFile namescount displacementcount horsepowercount
count;
inFileclose;
return count;
void printDatachar namesMAXCHAR double displacement double horsepower int count
cout fixed showpoint setprecision
;
for int i ; i count; i
cout namesi displacementi horsepoweri endl;
cout endl;
void printDatachar namesMAXCHAR double displacement double horsepower int count,
ofstream& outFile
outFile fixed showpoint setprecision;
for int i ; i count; i
outFile namesi displacementi horsepoweri endl;
outFileclose;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
