C++实验,实现复数的四则运算
//可直接调用库函数,试运行的时候能输入choice,但是正确进入switch...//输入1后直接结束程序。
int main()
{
Complex z1,z2,z,sum,sub,mul,div,c;
float a,b;
char OPTR;
int choice;
printf("1.Achieve addition, subtraction, multiplication and division of complex numbers.\n");
printf("2.Separating the real part from the known complex number.\n");
printf("3.Separating the image part from the known complex number.\n");
printf("Please enter the functions you want to achieve:");
scanf("%d",&choice);
switch(choice)
{ case '1':
{printf("Please input z1:");
scanf("%f+%fi",&a,&b);
z1=CreatComplex(a,b);
printf("Please input z2:");
scanf("%f+%fi",&a,&b);
z2=CreatComplex(a,b);
printf("Please input the operator:%c",&OPTR);
if(OPTR=='+')
{sum=Complex_Add(z1,z2);PrintComplex(sum);}
else if(OPTR=='-')
{sub=Complex_Sub(z1,z2);PrintComplex(sub);}
else if(OPTR=='*')
{mul=Complex_Mul(z1,z2);PrintComplex(mul);}
else if(OPTR=='/')
{div=Complex_Div(z1,z2);PrintComplex(div);}
else
printf("The operator that you input is wrong!");
break;}
case '2':
{printf("Please input the Complex:");
scanf("%f+%fi",&a,&b);
z=CreatComplex(a,b);
printf("%f",GetReal(z));
break;}
case '3':break;
{printf("Please input the Complex:");
scanf("%f+%fi",&a,&b);
z=CreatComplex(a,b);
printf("%f",GetImage(z));
break;}
}
}