Code a valid copy constructor for the GrabBag class below:
class GrabBag {
private:
int* values;
int size;
public:
GrabBag();
};
#include "GrabBag.h"
GrabBag::GrabBag() {
size = rand() % 100 + 1;
values = new int[size]; //random array size
for (int i = 0; i < size; i++)
values[i] = rand()% 10 + 1 ;// random array contents
}
class GrabBag { private: int* values; int size; public: GrabBag(); GrabBag(GrabBag &bag); }; #include "GrabBag.h" GrabBag::GrabBag() { size = rand() % 100 + 1; values = new int[size]; //random array size for (int i = 0; i < size; i++) values[i] = rand()% 10 + 1 ;// random array contents } GrabBag::GrabBag(GrabBag &bag) { size = bag.size; values = new int[size]; for (int i = 0; i < size; i++) values[i] = bag.values[i]; }
Get Answers For Free
Most questions answered within 1 hours.