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

Code in Visual Studio C++, use intermediate/beginner code Diesel engine specific

ID: 3605041 • Letter: C

Question

Code in Visual Studio C++, use intermediate/beginner code

Diesel engine specifications include its weight w), maximum horsepowerhp. and maximum torque (t). The performance of such engines can be compared using a performance index. In one study the performance index (pi) is defined as the ratio of maximum horsepower per unit of weight (ie. pi = hp /w ) of engine, write a program to calculate the performance index of several engines based on the following guidelines a) Define a class (called engine) containing the specifications of a typical engine (i.e w, hp, and t) and member function(s) to read these specifications b) Write a program to make use of an object of class engine type to calculate the performance index of six different engines listed below and print the index and the specifications of each engine to an output file having a format exactly like that shown below Maximum hp Maximum torque Weight Performance Index (hp/lb) (lb 68 72 168 725 220 130 225 281 664 2840 560 393 0.01431 4750 5012 7240 9680 7540 6180

Explanation / Answer

The engine class is created as with int hp,t,w; as data members and:
int readhp()
      {
          return hp;
      }
      int readw()
      {
          return w;
      }
      int readt()
      {
          return t;
      }
      Member functions to access the data.

      6 engine objects are created as:
      Engine engine1(68,225,4750);
      Engine engine2(72,281,5012);
      Engine engine3(168,664,7240);
      Engine engine4(725,2840,9680);
      Engine engine5(220,560,7540);
      Engine engine6(130,393,6180);
      and calculatepi() is called to calcuate pi.

      The output file is output.txt and the screenhot is given below.


The output screens have been provided.

If you have any doubts kindly you can comment. I'll reply as soon as possible.
Kindly rate the answer.All the best. :)
*********************************************************************
Code:

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

class Engine {
   public:
      int hp,t,w;
      //Parameterized Constructor definition
      Engine(int hp1,int t1,int w1) {
         hp=hp1;
         t=t1;
         w=w1;
      }
      int readhp()
      {
          return hp;
      }
      int readw()
      {
          return w;
      }
      int readt()
      {
          return t;
      }
      double calculatepi()
      {
          double pi = (double)hp/w;
          return pi;
      }
};
int main ()
{
ofstream myfile ("output.txt");
Engine engine1(68,225,4750);
Engine engine2(72,281,5012);
Engine engine3(168,664,7240);
Engine engine4(725,2840,9680);
Engine engine5(220,560,7540);
Engine engine6(130,393,6180);
if (myfile.is_open())
{
    myfile << "Maximum hp Maximum torque Weight Performance ";
    myfile << "(hp) (lb-ft) (lb) Index (hp/lb) ";
    myfile << "________ ________ _______ ________ ";
    myfile << std::fixed << std::setprecision(5) << engine1.readhp() << " " << engine1.readt() << " " <<engine1.readw() << " " <<engine1.calculatepi() << " ";
    myfile << std::fixed << std::setprecision(5) << engine2.readhp() << " " << engine2.readt() << " " <<engine2.readw() << " " <<engine2.calculatepi() << " ";
    myfile << std::fixed << std::setprecision(5) << engine3.readhp() << " " << engine3.readt() << " " <<engine3.readw() << " " <<engine3.calculatepi() << " ";
    myfile << std::fixed << std::setprecision(5) << engine4.readhp() << " " << engine4.readt() << " " <<engine4.readw() << " " <<engine4.calculatepi() << " ";
    myfile << std::fixed << std::setprecision(5) << engine5.readhp() << " " << engine5.readt() << " " <<engine5.readw() << " " <<engine5.calculatepi() << " ";
    myfile << std::fixed << std::setprecision(5) << engine6.readhp() << " " << engine6.readt() << " " <<engine6.readw() << " " <<engine6.calculatepi() << " ";
    myfile.close();
}
else cout << "Unable to open file";
return 0;
}

*********************************************************************
Sample output:

output.txt

***********************************************************************

I hope this helps you.
If you find my answer helpful,
Kindly rate the answer.
All the best :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote