好吧。 。 。指針正在驅動我瘋狂!好吧,現在我已經從我的系統中取出了下面的代碼,但是它並沒有輸出正確的輸出。我究竟做錯了什麼?我的小程序編譯,但它打印出giberish?
#ifndef _TERM_H
#define _TERM_H
class Term {
public:
//constructors
Term(Rational &a, const int &b)
{
this->coefficient = a;
this->exponent = b;
}
~Term() {}
//coefficient
Rational getCoefficient()const{
return coefficient;
}
//exponent
int getExponent()const{
return exponent;
}
//print the Term
void print()const {
cout << &Term::coefficient << " x^" << &Term::exponent << endl;
}
private:
Rational coefficient, a;
int exponent, b;
};
#endif
#ifndef _RATIONAL_H
#define _RATIONAL_H
class Rational {
public:
//constructors
Rational(const int &a, const int &b){
if (a != 0)
if (b != 0)
this->numerator = a;
this->denominator = b;
}
Rational(){}
~Rational() {}
.....
private:
int a, b, numerator, denominator;
};
#endif
好了,所以當我的指數我的有理數和我輸入2 I輸入值(2/5)(我應該得到(2/5 X^2) )我得到1 X^1。咦?我頭髮快要拔出來了。 。 。
只是一個(可能)無關的註釋:在`Rational`的構造函數中,你需要圍繞這兩個賦值括號。事實上,第二項任務不在「if」陳述的範圍之內。 – suszterpatt 2010-11-28 13:04:52
由於一些奇怪的原因,我有一種感覺,這是一個學習C++的Python程序員。 – whatnick 2010-11-28 13:08:34