I'm working on a project for my first use of classes and OOP. I've read all our slides (only provided examples though) and two tutorials on classes, but I confused about a few things. I'll show first the assignment then I'll post my specific questions after.
You will need to implement a class called Polynomial10 and use it in the main function of
your solution. This class represent a set of all polynomial of a degree not higher than 10. Note,
that such a set is closed with respect to addition, subtraction and scaling by constant. Private
members coef and degree store the array of polynomial coe!cients and the degree. Public
methods are responsible for interaction between the objects of this class and the program.
Member functions print() and read() provide console output and input. Member
functions add() and subtract() update a polynomial object by performing an appropriate
arithmetic operation with another object. Member function multc() scales the polynomial by
a constant. You are welcome to update the code you created for previous projects.
This class has the following prototype:
class Polynomial10
{
private:
double coef[MAX_DEGREE+1];
int degree;
public:
Polynomial10(); //Constructor for a new Polynomial10
int getDegree(){return degree;};
void print(); //Print the polynomial in standard form
void read(); //Read a polynomial from the user
void add(const Polynomial10& pol); //Add a polynomial
void multc(double factor); //Multiply the poly by scalar
void subtract(const Polynomial10& pol); //Subtract polynom
};
1. I'm confused about the constructor. What would it's purpose be here? I read the tutorial http://www.cplusplus.com/doc/tutorial/classes/ and it designated the purpose of the constructor as to " initialize variables or assign dynamic memory". If I use the read() function to input the polynomial, then where does the constructor come into play?
2. "const Polynomial10& pol"
I am confused mainly about the &. I assume it is in association with as a pointer, but a little clarification would help a lot. I want to start writing but I'm limited to what I can do now when I don't know what some of the assigned functions mean. I appreciate any help.