Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I hope to modify the program to use while loops so that it can keep reading inpu

ID: 3630678 • Letter: I

Question

I hope to modify the program to use while loops so that it can keep reading inputs.

//Header files
#include<iostream>

#include<fstream>

#include<iomanip>

using namespace std;

//global variable
const int SIZE=6;

//Engine class defintion
class Engine
{
//class variables
int hp[SIZE];
int t[SIZE];
int lb[SIZE];
float index[SIZE];
//class funtions
public:
void readInput();
void calculate();
void header();
void outputFile();
};

//For reading the data
void Engine::readInput()

{ cout<<"Enter Data: "<<endl;

cout<<setw(10)<<"HP"<<setw(10)<<"Torque"<<setw(10)<<"lb"<<endl;

for(int i=0;i<SIZE;i++)

{ cin>>hp[i]>>t[i]>>lb[i]; }

}

//For calculating performance index
void Engine::calculate()
{
for(int i=0;i<SIZE;i++)
index[i]=(float)hp[i]/lb[i];
}
}

//For outputting the text file
void Engine::outputFile()
{
fstream fout;
fout.open("output.txt",ios::out);
fout<<setw(15)<<"Maximum hp"<<setw(15)<<"Maximum torque" <<setw(15)<<"weight"<<setw(15)<<"Perfomance index"<<endl;
for(int i=0;i<SIZE;i++)

fout<<setw(8)<<" "<<setw(25)<<left<<hp[i]<<setw(25)<<left<<t[i] <<setw(25)<<left<<lb[i]<<setw(25)<<left<<index[i]<<endl;

fout.close();

}

//for Header file defintion
void Engine::header()
{

cout<<setw(10)<<left<<"hp"<<setw(10)<<left<<"Torque"<<setw(10)<<left<<"lb"<< setw(10)<<left<<"Performance Index"<<endl;
cout< setw(10)< cout<<"------------------------------------------------------------ ";
for(int i=0;i<SIZE;i++)

cout<<setw(10)<<left<<hp[i]<<setw(10)<<left<<t[i]<<setw(10)<<left<<lb[i]<<setw(10)<<left<<index[i]<<endl;

}


//Main function defintion
int main()
{
//calling funtions through objects
Engine e;
e.readInput();
e.calculate();
e.header();
e.outputFile();
//To pause the output
system("pause");
return 0;
}

Explanation / Answer

#include #include #include using namespace std; //global variable const int SIZE=6; //Engine class defintion class Engine { //class variables int hp[SIZE]; int t[SIZE]; int lb[SIZE]; float index[SIZE]; //class funtions public: void readInput(); void calculate(); void header(); void outputFile(); }; //For reading the data void Engine::readInput() { cout