复数(手写体)

本文深入探讨了复数的概念,包括实部、虚部以及复数的几何表示。通过实例解析了复数的加减乘除运算,并讨论了复数在电气工程和量子物理中的应用。同时,介绍了手写体复数的正确写法,帮助读者更好地理解和掌握复数知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<iostream>
#include<string>
using namespace std;
class complex{
private:
    double real,imag;
    string com;
public:
    complex(string a):com(a){}
    void opr();
    friend ostream& operator<< (ostream&,complex&);
};
int main()
{
    string com;
    while(cin>>com){
        complex c(com);
        c.opr();
        cout << c;
    }
    return 0;
}
void complex::opr(){
    if(com=="i") real=0,imag=1; 
    else if(com=="-i") real=0,imag=-1;
    else{
    int len=com.size(),flag=0,k=0;string stra,strb;
    if(com[len-1]!='i') real=atof(com.c_str()),imag=0;
    else{
        for(int i=1;i<len;i++) if(com[i]=='+'||com[i]=='-') flag=1,k=i;
        if(flag){
            for(int i=0;i<k;i++) stra+=com[i];real=atof(stra.c_str());
            for(int i=k+1;i<len-1;i++) strb+=com[i];imag=atof(strb.c_str());
            if(com[k+1]=='i')imag=1;
            if(com[k]=='-')imag=-imag;
        }
        else{
            for(int i=0;i<len-1;i++)
                strb+=com[i];
            real=0;imag=atof(strb.c_str());
        }
    }
    }
}
ostream& operator<< (ostream& op,complex& cc){
    op << "complex " << cc.com << endl;
    op << "the real part is " << cc.real << endl;
    op << "and the imaginary part is " << cc.imag << endl;
    return op;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值