Read an integer as the number of BallObject objects. Assign myBallObjects with an array of that many BallObject objects.
Posted: Sun Jul 03, 2022 12:00 pm
Read an integer as the number of BallObject objects. AssignmyBallObjects with an array of that many BallObject objects. Foreach object, call object's Read() followed by the object'sPrint().
Ex: If the input is 1 14 43, then the output is:
#include <iostream>using namespace std;
class BallObject { public: BallObject(); void Read(); void Print(); ~BallObject(); private: int forceApplied; int contactArea;};BallObject::BallObject() { forceApplied = 0; contactArea = 0;}void BallObject::Read() { cin >> forceApplied; cin >> contactArea;}void BallObject::Print() { cout << "BallObject's forceApplied: " <<forceApplied << endl; cout << "BallObject's contactArea: " <<contactArea << endl;}BallObject::~BallObject() { // Covered in section onDestructors. cout << "BallObject with forceApplied " <<forceApplied << " and contactArea " << contactArea<< " is deallocated." << endl;}
int main() { BallObject* myBallObjects = nullptr; int count; int i; /* Your code goes here */ delete[] myBallObjects; return 0;}
Ex: If the input is 1 14 43, then the output is:
#include <iostream>using namespace std;
class BallObject { public: BallObject(); void Read(); void Print(); ~BallObject(); private: int forceApplied; int contactArea;};BallObject::BallObject() { forceApplied = 0; contactArea = 0;}void BallObject::Read() { cin >> forceApplied; cin >> contactArea;}void BallObject::Print() { cout << "BallObject's forceApplied: " <<forceApplied << endl; cout << "BallObject's contactArea: " <<contactArea << endl;}BallObject::~BallObject() { // Covered in section onDestructors. cout << "BallObject with forceApplied " <<forceApplied << " and contactArea " << contactArea<< " is deallocated." << endl;}
int main() { BallObject* myBallObjects = nullptr; int count; int i; /* Your code goes here */ delete[] myBallObjects; return 0;}