Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are many problems with the program below. Describe 5 of these problems in detail. For each, also explain how you could fix or avoid

There are many problems with the program below. Describe 5 of these problems in detail. For each, also explain how you could fix or avoid the issue.
Program:
#include
using namespace std;
class Duck {
public:
virtual void quack() {
cout << "Quack" << endl;
}
};
class RubberDuck : public Duck {
public:
RubberDuck() {
array = NULL;
}
RubberDuck(int size) {
array = new int[size];
array[0] = 1;
array[1] = 2;
array[2] = 3;
}
~RubberDuck() {
delete array;
}
void quack() {
cout << "Squeak! ";
for (int i = 0; i < arraySize; i++) {
cout << array[0] << " ";
}
cout << endl;
}
private:
int* array;
int arraySize;
};
int main() {
Duck* rubberDuck;
Duck& duck = *rubberDuck;
duck.quack();
delete[] rubberDuck;
return 0;
}
Example Output (when all goes well):
Squeak! 1 2 3
Analysis and potential solutions:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago