請各位高手幫我一下,我的問題是:我要如何把兩個欲相加的多項式A與多項式 B輸入進去或宣告它 *我是用dev C++寫的* 以下是程式碼(可是compile之後有錯): #include
#include
#define Maxterms 32
class Polynomial; //forward declaration class term
{
friend Polynomial;
private:
int coef; //單項係數
int exp; //單項次方數
};
class Polynomial
{
private:
static int termArray[Maxterms];
static int free; //剩餘空間的位置
int Start; //本多項式在termArray[]的起始位置
int Finish; //本多項式在termArray[]的終了位置
public:
Polynomial(); //在termArray[]加入本多項式
Polynomial Add(Polynomial B);
void NewTerm(float c, int e);
};
Polynomial::Polynomial() {
free= 0;
Start= free;
Finish= free - 1;
} int main()
{
void Polynomial::NewTerm(float c, int e)
{
// Add a new term to C(x)
if (free >= MaxTerms) {
cerr << "Too many terms in polynomials" << endl;
exit();
}
termArray[free].coef = c;
termArray[free].exp = e;
free ;
} // end of NewTerm Polynomial Polynomial::Add(Polynomial B)
{
// return the sum of A(x) ( in *this) and B(x)
Polynomial C;
int a = Start;
int b = B.Start;
C.Start = free;
float c;
while ((a <= Finish) && (b <= B.Finish)) {
switch (compare(termArray[a].exp, termArray[b].exp)) {
case '=':
c = termArray[a].coef termArray[b].coef;
if (c) NewTerm(c, termArray[a].exp);
a ; b ;
break;
case '<':
NewTerm(termArray[b].coef, termArray[b].exp);
b ;
case '>':
NewTerm(termArray[a].coef, termArray[a].exp);
a ;
} } // end of switch and while // add in remaining terms of A(x)
for (; a<= Finish; a ) {
NewTerm(termArray[a].coef, termArray[a].exp);
}
// add in remaining terms of B(x)
for (; b<= B.Finish; b ) {
NewTerm(termArray[b].coef, termArray[b].exp);
}
C.Finish= free- 1;
return C;
} // end of Add
system("PAUSE");
return 0;
}