複數可以分為實數部分與虛數部分,
在進行複數的比較/運算時,需要注意把實數與虛數部分分開比較
請依照題目指示,對所得到的複數進行比較運算。
請建立名為Complex的類別,並利用依照以下main格式撰寫。
請練習使用friend (未使用friend 僅採計原本成績80%)
(可參考ppt中提示的格式)
有n筆測資
每筆測資會有4個數字,分別為r1 i1 r2 i2,
r1與i1分別為C1的實數與虛數部分,
r2與i2分別為C2的實數與虛數部分。
請依照main的提示,對C1與C2做比較與運算。
2 2 2 2 1 2 3 4
C1 = 2+2i C2 = 2+2i C1==C2? true C1<C2? false C1>C2? false C1+C2 = 4+4i C1-C2 = 0+0i C1*C2 = 0+8i C1++ = 2+2i C1++ = 3+3i ++C1 = 5+5i ++C1 = 6+6i C2-- = 2+2i C2-- = 1+1i --C2 = -1-1i --C2 = -2-2i C1+=C2 4+4i ============== C1 = 1+2i C2 = 3+4i C1==C2? false C1<C2? true C1>C2? false C1+C2 = 4+6i C1-C2 = -2-2i C1*C2 = -5+10i C1++ = 1+2i C1++ = 2+3i ++C1 = 4+5i ++C1 = 5+6i C2-- = 3+4i C2-- = 2+3i --C2 = 0+1i --C2 = -1+0i C1+=C2 4+6i ==============
int main() {
Complex C1, C2;
while( cin >> C1 >> C2 ) {
cout << "C1 = " << C1 << endl;
cout << "C2 = " << C2 << endl;
cout << "C1==C2? " << ((C1==C2)?"true":"false") << endl;
cout << "C1<C2? " << ((C1<C2)?"true":"false") << endl;
cout << "C1>C2? " << ((C1>C2)?"true":"false") << endl;
cout << "C1+C2 = " << C1+C2 << endl;
cout << "C1-C2 = " << C1-C2 << endl;
cout << "C1*C2 = " << C1*C2 << endl;
cout << "C1++ = " << C1++ << endl;
cout << "C1++ = " << C1++ << endl;
cout << "++C1 = " << ++C1 << endl;
cout << "++C1 = " << ++C1 << endl;
cout << "C2-- = " << C2-- << endl;
cout << "C2-- = " << C2-- << endl;
cout << "--C2 = " << --C2 << endl;
cout << "--C2 = " << --C2 << endl;
C1+=C2;
cout << "C1+=C2 " << C1 << endl;
cout << "==============" << endl;
}
return 0;
}
編號 | 身分 | 題目 | 主題 | 人氣 | 發表日期 |
沒有發現任何「解題報告」 |