欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

计算器改良系统

程序员文章站 2024-03-17 20:47:52
...

没看见重载输入输出流的要求,结果尴尬了。。。

修改后代码如下:

计算器改良系统

计算器改良系统

计算器改良系统

计算器改良系统

计算器改良系统

计算器改良系统

计算器改良系统

计算器改良系统

计算器改良系统

计算器改良系统

计算器改良系统

#include <iostream>
#include <iomanip>
using namespace std;
class fushu
{
public:
    fushu(){real=0,imag=0;}
    fushu(double r,double i){real=r,imag=i;}
    friend fushu operator +(fushu c1,fushu c2);
    friend fushu operator -(fushu c1,fushu c2);
    friend fushu operator *(fushu c1,fushu c2);
    friend fushu operator /(fushu c1,fushu c2);
    friend istream& operator >>(istream&,fushu&);
    friend ostream& operator <<(ostream&,fushu&);
    void jisuan();
private:
    double real;
    double imag;
};
fushu operator +(fushu c1,fushu c2)
{
    return fushu(c1.real+c2.real,c1.imag+c2.imag);
}
fushu operator -(fushu c1,fushu c2)
{
    return fushu(c1.real-c2.real,c1.imag-c2.imag);
}
fushu operator *(fushu c1,fushu c2)
{
    return fushu(c1.real*c2.real-c1.imag*c2.imag,c1.imag*c2.real+c1.real*c2.imag);
}
fushu operator /(fushu c1,fushu c2)
{
    return fushu((c1.real*c2.real+c1.imag*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag),(c1.imag*c2.real-c1.real*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag));
}
istream& operator >>(istream& input,fushu&c)
{
    input>>c.real>>c.imag;
    return input;
}
ostream& operator <<(ostream& output,fushu&c)
{
    output<<"("<<c.real<<","<<c.imag<<"i)"<<endl;
    return output;
}
void danzi1()
{
    cout<<"请选择您的操作:";
    cout<<endl<<endl;
    cout<<"                 "<<"1  标准类型计算"<<endl;
    cout<<"                 "<<"2  复数类型计算"<<endl;
    cout<<"                 "<<"0  退出"<<endl;
    cout<<"请选择按键 0-2:";
}
void danzi2()
{
    cout<<endl<<endl;
    cout<<"计算器选择菜单";
    cout<<endl<<endl;
    cout<<"                 "<<"1  加法"<<endl;
    cout<<"                 "<<"2  减法"<<endl;
    cout<<"                 "<<"3  乘法"<<endl;
    cout<<"                 "<<"4  除法"<<endl;
    cout<<"                 "<<"0  返回上级菜单"<<endl;
    cout<<"                 "<<"5  退出系统"<<endl;
    cout<<"请选择按键 0-5:";
}
void fushu::jisuan()
{
    int m;
    kaishi:{danzi1();cin>>m;}
    if(m==1)
    {
        int n;
        double x,y;
        shuru1:{danzi2();cin>>n;}
        if(n==1)
        {
            cout<<"请输入两个数"<<endl;
            cin>>x>>y;
            cout<<x+y<<endl;
            goto shuru1;
        }
        else if(n==2)
        {
            cout<<"请输入两个数"<<endl;
            cin>>x>>y;
            cout<<x-y<<endl;
            goto shuru1;
        }
        else if(n==3)
        {
            cout<<"请输入两个数"<<endl;
            cin>>x>>y;
            cout<<x*y<<endl;
            goto shuru1;
        }
        else if(n==4)
        {
            cout<<"请输入两个数"<<endl;
            cin>>x>>y;
            cout<<x/y<<endl;
            goto shuru1;
        }
        else if(n==0)
        {
            goto kaishi;
        }
        else if(n==5)
        {
            return ;
        }
        else
        {
            cout<<"输入错误请帅哥or靓女从新选择"<<endl;
            goto shuru1;
        }
    }
    else if(m==2)
    {
        int n;
        fushu c1,c2,c3;
        shuru2:{danzi2();cin>>n;}
        if(n==1)
        {
            cout<<"请输入两个复数的实部和虚部"<<endl;
            cin>>c1>>c2;
            cout<<"c1="<<"("<<c1.real<<","<<c1.imag<<"i)"<<endl;
            cout<<"c2="<<"("<<c2.real<<","<<c2.imag<<"i)"<<endl;
            c3=c1+c2;
            cout<<"c1+c2=";
            cout<<c3;
            goto shuru2;
        }
        else if(n==2)
        {
            cout<<"请输入两个复数的实部和虚部"<<endl;
            cin>>c1>>c2;
            cout<<"c1="<<"("<<c1.real<<","<<c1.imag<<"i)"<<endl;
            cout<<"c2="<<"("<<c2.real<<","<<c2.imag<<"i)"<<endl;
            c3=c1-c2;
            cout<<"c1-c2=";
            cout<<c3;
            goto shuru2;
        }
        else if(n==3)
        {
            cout<<"请输入两个复数的实部和虚部"<<endl;
            cin>>c1>>c2;
            cout<<"c1="<<"("<<c1.real<<","<<c1.imag<<"i)"<<endl;
            cout<<"c2="<<"("<<c2.real<<","<<c2.imag<<"i)"<<endl;
            c3=c1*c2;
            cout<<"c1*c2=";
            cout<<c3;
            goto shuru2;
        }
        else if(n==4)
        {
            cout<<"请输入两个复数的实部和虚部"<<endl;
            cin>>c1>>c2;
            cout<<"c1="<<"("<<c1.real<<","<<c1.imag<<"i)"<<endl;
            cout<<"c2="<<"("<<c2.real<<","<<c2.imag<<"i)"<<endl;
            c3=c1/c2;
            cout<<"c1/c2=";
            cout<<c3;
            goto shuru2;
        }
        else if(n==0)
        {
            goto kaishi;
        }
        else if(n==5)
        {
            return ;
        }
        else
        {
            cout<<"输入错误请帅哥or靓女从新选择"<<endl;
            goto shuru2;
        }
    }
    else if(m==0)
    {
        return ;
    }
    else
    {
        cout<<"输入错误请帅哥or靓女从新选择"<<endl;
        goto kaishi;
    }
}
int main()
{
    cout<<endl<<endl;
    cout<<"      $----------------------------------------$"<<endl;
    cout<<"      :                                        :"<<endl;
    cout<<"          :  **欢迎进入计算器加强版系统**      :"<<endl;
    cout<<"          :  **   zly制作必属精品  **          :"<<endl;
    cout<<"      :                                        :"<<endl;
    cout<<"      @aaa@qq.com"<<endl;
    fushu h;
    h.jisuan();
}