标题:复数计算器 在编译时没有错误,可是答案错了
只看楼主
winnie96
Rank: 2
等 级:论坛游民
帖 子:51
专家分:86
注 册:2015-12-14
结帖率:53.85%
已结贴  问题点数:10 回复次数:3 
复数计算器 在编译时没有错误,可是答案错了
#include<iostream>
using namespace std;

class Complex
{
private:
    int a,b;
public:
    Complex(int a1,int b1=0):a(a1),b(b1){};
    ~Complex(){};
    void jiaf(const Complex &copy)
    {
        a+=copy.a;
        b+=copy.b;
    }
    void jianf(const Complex &copy)
    {
        a-=copy.a;
        b-=copy.b;
    }
    void chengf(const Complex &copy)
    {
        int c=a;
        a=a*copy.a-b*copy.b;
        b=c*copy.b+b*copy.a;
    }
    void chuf(const Complex &copy)
    {
        int d;
        b=-b;
        d=-copy.b;
        int c=a;
        a=a*copy.a-b*d;
        b=c*d+b*copy.a;
    }
    void Show()
    {
        if(b>0)
            cout<<a<<"+"<<b<<endl;
        else if(b==0)
        {
            cout<<a<<endl;
        }
        else
            cout<<a<<b<<endl;
    }
};
int main()
{
    void Show1();
    char c;
   
    do
    {
        cout<<"输入一个复数:"<<endl;
        int a1,b1;
        cin>>a1>>b1;
        Complex p1(a1,b1);

        cout<<"输入一个复数:"<<endl;
        int a2,b2;
        cin>>a2>>b2;
        Complex p2(a2,b2);

        Show1();
        int a;
        cin>>a;
        if(a==5)
        {
            
            exit(1);
        }
        while(a!=1&&a!=2&&a!=3&&a!=4&&a!=4)
        {
            Show1();
            cout<<"重新输入a"<<endl;
            cin>>a;
        }
        switch(a)
        {
        case 1:
            p1.jiaf(p2);
        case 2:
            p1.jianf(p2);
        case 3:
            p1.chengf(p2);
        case 4:
            p1.chuf(p2);
        }
        cout<<"结果是:"<<endl;
        p1.Show();
        cout<<"是否继续?(Y/N)"<<endl;
   
        cin>>c;
    }while(c=='y'||c=='Y');
}
void Show1()
{
    cout<<"进行复数的运算  "<<endl;
    cout<<"1  +  "<<endl;
    cout<<"2  -"<<endl;
    cout<<"3  * "<<endl;
    cout<<"4  /"<<endl;
    cout<<"5  退出"<<endl;
    cout<<"输入数字编码"<<endl;
}
搜索更多相关主题的帖子: 计算器 Complex private include public 
2016-04-07 21:28
aiyulunhui
Rank: 2
等 级:论坛游民
帖 子:19
专家分:24
注 册:2015-9-9
得分:0 
a+=copy.a; copy 是什么
2016-04-08 11:16
aiyulunhui
Rank: 2
等 级:论坛游民
帖 子:19
专家分:24
注 册:2015-9-9
得分:10 
看错了,case后面忘了break;
2016-04-08 11:40
winnie96
Rank: 2
等 级:论坛游民
帖 子:51
专家分:86
注 册:2015-12-14
得分:0 
谢谢了,虽然我已经找到错误
2016-04-08 20:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-463386-1-1.html




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

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