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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 5834 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() \{
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply