In a given polynomial, enter the coefficient 'cf' as a parameter and create the member function 'numofCoeff', which returns the number of terms with the same coefficient as 'cf'.
class Polynomial; // 전방 선언
class Term {
friend Polynomial; // Polynomial 클래스에서 접근 가능
private:
float coef;
int exp;
};
class Polynomial {
private:
Term *termArray;
int capacity;
int terms;
public:
....
}
int Polynomial:numofCoeff(float cf)
CODE:
int Polynomial:numofCoeff(float cf)
{
int count = 0;
//Iterate through all the terms
for(int i = 0;i < terms;++i)
{
//For each term check the coefficient against the param
if(termArray[i].coef == cf)
{
++count;
}
}
return count;
}
Get Answers For Free
Most questions answered within 1 hours.