複數可以分為實數部分與虛數部分,在進行複數的四則運算時,
需要注意把實數與虛數部分分開運算!
請依照題目指示,對所得到的複數進行運算。
請建立名為Complex的類別,並利用依照以下main格式撰寫。
每筆測資會有4個數字,分別為n1 n2 n3 n4,
n1與n2分別為C1的實數與虛數部分,
n3與n4分別為C2的實數與虛數部分。
請依照main的提示,對C1與C2做運算。
1 2 3 4 2 3 4 5
C1 = 1+2i C2 = 3+4i C1+C2 = 4+6i C1-C2 = -2-2i C1*C2 = -5+10i C1/C2 = 0.44+0.08i 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 = 2+3i C2 = 4+5i C1+C2 = 6+8i C1-C2 = -2-2i C1*C2 = -7+22i C1/C2 = 0.560976+0.0487805i C1++ = 2+3i C1++ = 3+4i ++C1 = 5+6i ++C1 = 6+7i C2-- = 4+5i C2-- = 3+4i --C2 = 1+2i --C2 = 0+1i ==========
int main()
{
Complex C1,C2;
while(cin>>C1>>C2){
cout<<"C1 = "<<C1<<endl;
cout<<"C2 = "<<C2<<endl;
cout<<"C1+C2 = "<<C1+C2<<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;
cout<<"=========="<<endl;
}
return 0;
}
編號 | 身分 | 題目 | 主題 | 人氣 | 發表日期 |
沒有發現任何「解題報告」 |