class Polynomial {
friend ostream& operator<<(ostream& os, const Polynomial& p);
friend istream& operator>>(istream& is, Polynomial &p);
// ...
istream& operator>>(istream& is, Polynomial &p){
// paste your input function here, and replace all "cin" with "is".
// assign newterm(coef, exp) to "p".
// for example
is >> coef >> exp;
p.NewTerm(coef, exp);
return is;
}
int main(){
polynomial poly1, poly2;
cout << "輸入第一個多項式:" << endl;
// poly1.input();
cin>>poly1;
//...
}
ostream& operator<<(ostream& os, const Polynomial& p){
// paste your display function here, and replace all "cout" with "os".
// assign data member to "p".
// for example
os << p.termArray[i].coef;
return os;
}
int main(){
//...
cout << "多項式相加結果: ";
// sum.display();
cout<<sum;
//...
}
You are missing the following things:
operator>>
operator<<
You can refer to 2024-11-20 資料結構教材.pdf.