Page 1 of 1

Read a double as the number of Engine objects. Assign myEngines with an array of that many Engine objects. For each obje

Posted: Thu Jul 14, 2022 2:06 pm
by answerhappygod
Read A Double As The Number Of Engine Objects Assign Myengines With An Array Of That Many Engine Objects For Each Obje 1
Read A Double As The Number Of Engine Objects Assign Myengines With An Array Of That Many Engine Objects For Each Obje 1 (90.58 KiB) Viewed 5835 times
#include <iostream>#include <iomanip>using namespace std;
class Engine { public: Engine(); void Read(); void Print(); ~Engine(); private: double power; double duration;};Engine::Engine() { power = 0.0; duration = 0.0;}void Engine::Read() { cin >> power; cin >> duration;}void Engine::Print() { cout << "Engine's power: " << fixed<< setprecision(1) << power << endl; cout << "Engine's duration: " << fixed<< setprecision(1) << duration << endl;}Engine::~Engine() { // Covered in section on Destructors. cout << "Engine with power " << power<< " and duration " << duration << " isdeallocated." << endl;}
int main() { Engine* myEngines = nullptr; int count; int i; /* Your code goes here */ delete[] myEngines; return 0;}
Read a double as the number of Engine objects. Assign myEngines with an array of that many Engine objects. For each object, call object's Read() followed by the object's Print(). Ex: If the input is 25.58.08.57.0, then the output is: Engine's power: 5.5 Engine's duration: 8.0 Engine's power: 8.5 Engine's duration: 7.0 Engine with power 8.5 and duration 7.0 is deallocated. Engine with power 5.5 and duration 8.0 is deallocated. 1 #include 2 #include 3 using namespace std; 5 class Engine \{ 6 public: 7 Engine(); 8 void Read(); 9 void Print(); 10 Engine(); 11 private: double power; double duration; \}; 15 Engine: :Engine() \{