HW HELP PLEASE!

I am stuck on this assignment. Any help is greatly appreciated. Thanks in advance
//////////////////////////////////////////////////////////////////////

class Homework {
public:
Homework() { // constructor
nHW = 0;
}

void addScore(int score) {
hw[nHW] = score;
nHW++;
}
private:
int hw[12];
int nHW; // number of homework scores stored
};
////////////////////////////////////////////////////////////////

1. The hw member variable can store at most 12 scores. Change the code so that hw can store as many scores as needed when a Homework object is created. (Hint: use dynamic memory). Change/add constructor and destructors as needed.
2. Add a copy constructor for the above case.
Probably not what is expected, but:

1
2
3
4
5
6
7
8
9
10
#include <vector>

class Homework {
public:
    void addScore(int score) {
        hw.push_back(score);
    }
private:
    std::vector<int> hw;
};


And you don't need a default constructor or to implement a copy constructor or destructor.
The teacher neglects to mention the copy assignment operator. A modern teacher would remind of the move-versions too ...

There is https://en.wikipedia.org/wiki/Rule_of_three_%28C%2B%2B_programming%29
Topic archived. No new replies allowed.