how to begin the programme

i need to create a class that represents a polynom of the fourth degree with int coefficients.
Define suitable interface to the class as a constructor(s), set and get methods as functions, and funtion int calc(int x0) which gives the value to the polynom at the point x0. Redefine operation indexing[], that the given index returns the value of the respected coefficient of the polynom

i tried to translate as best as possible, so hope you understand.
I need tips on how to begin creating the program, if you have some spare time and help me out with the code it would be very appreciated. If you could start the basic code for me that would be great, any advice would be helpful.
Go through the problem sentence by sentence and see if you can sketch out the data or code for it:
i need to create a class that represents a polynom
1
2
class Poly {
};

a polynom of the fourth degree with int coefficients.

So class Poly should contain
int coeff[4];
or better yet:
1
2
3
constexpr unsigned NumCoefficients = 4;
...
int coeff[NumCoefficients];


Define suitable interface to the class as a constructor(s)
Poly();
set and get methods as functions

Hmm. I'm not sure what it will be setting and getting. So this is a question to answer.
and funtion int calc(int x0) which gives the value to the polynom at the point x0.

int calc(int x0);
Redefine operation indexing[], that the given index returns the value of the respected coefficient of the polynom
int operator[](unsigned idx) { return coeff[idx]; }

Putting that all together:
1
2
3
4
5
6
7
8
9
constexpr unsigned NumCoefficients = 4;
class Poly {
public:
    Poly();
    int calc(int x0);
    int operator[](unsigned idx) { return coeff[idx]; }
private:
    int coeff[NumCoefficients];
};

Ah. Now I see what the get/set methods are for. They get/set the coefficients. So maybe:
1
2
    void setCoeff(unsigned idx, int val);
    int getCoeff(unsigned idx);


Now it's a matter of writing the code.
Topic archived. No new replies allowed.