Question: The questions are given in the following code. #include class Ball { std::string colour; int radius; public: Ball(std::string clr, int r) { colour = clr;

The questions are given in the following code. #include

class Ball { std::string colour; int radius; public: Ball(std::string clr, int r) { colour = clr; radius = r; } //Question 1: Is this function used in this example? Ball& operator=(const Ball& b) { if (this != &b) { colour = b.colour; radius = b.radius; } } };

const int MAX = 5; class Child { const Ball* ball[MAX];//Question 2: What type of an array is this? //Question 3: Why is this a const? //Question 4: What is this an example of? std::string name; int num{ 0 }; public: Child(std::string _name) { name = _name; } Child& operator+=(const Ball& b) { if (num < MAX) { ball[num++] = &b;//Question 5: what is the type of the lhs? //Question 6: what is the type of the rhs? } return *this; } void PrintInfo() { std::cout << name << " has " << num << " balls." << std::endl; } };

int main() { Child child1("Billy Marsh"); Ball ball1("red", 10); Ball ball2("blue", 8); Ball ball3("green", 6); //Question 7: How many balls can be added to child1? child1 += ball1; child1 += ball2; child1 += ball3; child1.PrintInfo(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!