Dec 6, 2014 at 1:49am UTC
I am trying to find the largest exponent in this vector, but I am getting an error message. The whole program is very long, so I will just post the relevant pieces.
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
class Term
{
private:
int coeff;
int exp;
public:
void setCoeff(const int coefficient);
void setExp(const int exponent);
int getCoeff() const;
int getExp() const;
Term derivative() const;
double eval(const double x) const;
void displayFirst() const;
void display() const;
};
class Poly
{
private:
vector<Term> terms;
public:
void addTerm(const int coeff, const int exp);
void scale(const int fact);
Term getTerm(const int index) const;
int degree() const;
int termCount() const;
double eval(const double x) const;
Poly derivative() const;
Poly add(const Poly & poly) const;
Poly subtract(const Poly & poly) const;
void display(const string & label) const;
};
//This function should return the highest degree polynomial
int Poly::degree() const
{
Poly terms;
for(int i = 0; i < terms.size(); i++) //Error; No member named size in poly
{
}
}
Dec 6, 2014 at 2:31am UTC
Yes I think so. How would I go about doing that?
Dec 6, 2014 at 2:47am UTC
Can you just post the whole code please? That would be much easier
Dec 6, 2014 at 2:49am UTC
Remove line 3 Poly terms;
or change line 5 to this ->terms.size();
You could do both if you wish but I would just suggest removing the unnecessary line 3.