| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 287 人关注过本帖
标题:C++实验,实现复数的四则运算
只看楼主 加入收藏
YUkoni
Rank: 2
等 级:论坛游民
帖 子:17
专家分:22
注 册:2018-11-25
结帖率:50%
  已结贴   问题点数:20  回复次数:1   
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;}
    }
}
搜索更多相关主题的帖子: Complex printf the Please input 
【推荐】大型监控、工控、组态VC++./C#源码组件库2019下载!
【推荐】超50万数控、建模仿真、电力VC++/.NET图形源码库下载!
【推荐】专业CAD\GIS\业务流程VC++/C#可视化图形软件源码库下载!
2019-04-19 10:12
word123
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:13
帖 子:333
专家分:1622
注 册:2014-4-5
  得分:20 
scanf("%f%f",&a,&b);
2019-04-19 14:44
快速回复:C++实验,实现复数的四则运算
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.094346 second(s), 8 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved