Read an integer as the number of BallObject objects. Assign myBallObjects with an array of that many BallObject objects.

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: 899603
Joined: Mon Aug 02, 2021 8:13 am

Read an integer as the number of BallObject objects. Assign myBallObjects with an array of that many BallObject objects.

Post by answerhappygod »

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