2024/04/26

1.思维导图

2.

#include <iostream>
 
using namespace std;
class Complex
{
    int rel;    //实部
    int vir;    //虚部
public:
    Complex(){}
    Complex(int rel,int vir):rel(rel),vir(vir){}
   /* Complex operator+(const Complex c1);
    Complex operator-(const Complex c1);
    Complex operator*(const Complex c1);
    Complex operator/(const Complex c1);*/
    friend Complex operator+(const Complex c1,const Complex c2);
    friend Complex operator-(const Complex c1,const Complex c2);
    friend Complex operator*(const Complex c1,const Complex c2);
    friend Complex operator/(const Complex c1,const Complex c2);
    bool operator>(const Complex c1);
    bool operator<(const Complex c1);
    bool operator>=(const Complex c1);
    bool operator<=(const Complex c1);
    bool operator==(const Complex c1);
    bool operator!=(const Complex c1);
    bool operator!();
    bool operator&&(const Complex c1);
    bool operator||(const Complex c1);
    Complex operator++();
    Complex operator--();
    friend Complex operator++(Complex &c1,int );
    friend Complex operator--(Complex &c1,int );
    friend ostream &operator<<(ostream &out,Complex c1);
    friend istream &operator>>(istream &in,Complex &c1);
    Complex operator^(Complex c1);
    Complex operator<<(int a);
    Complex operator>>(int a);
    Complex operator~();
    Complex show()
    {cout << rel << "+"<< vir << "i" << endl;}
    operator int()
    {return this->rel;}
    operator double()
    {return this->rel;}
    operator char()
    {return 'a';}
    int operator()(int a,int b )
    {return a>b?a:b;}
};
//^,<<,>>,~
Complex Complex::operator^(Complex c1)
{
    Complex temp;
    temp.rel=(this->rel)^c1.rel;
    temp.vir=(this->vir)^c1.vir;
    return temp;
}
Complex Complex::operator<<(int a)
{
    rel=rel<<a;
    vir=vir<<a;
    return *this;
}
Complex Complex::operator>>(int a)
{
    rel=rel>>a;
    vir=vir>>a;
    return *this;
}
Complex Complex::operator~()
{
    rel=~rel;
    vir=~vir;
    return *this;
}
//自增自减
Complex Complex::operator++()
{
    ++this->rel;
    ++this->vir;
    return *this;
}
Complex Complex::operator--()
{
    --this->rel;
    --this->vir;
    return *this;
}
Complex operator++(Complex &c1,int )
{
    Complex temp=c1;
    c1.rel++;
    c1.vir++;
    return temp;
}
Complex operator--(Complex &c1,int )
{
    Complex temp=c1;
    c1.rel--;
    c1.vir--;
    return temp;
}
 

bool Complex::operator!()
{
    return !(this->rel || this->vir);
}
bool Complex::operator&&(const Complex c1)
{
    return this->rel && c1.rel && this->vir && c1.vir;
}
bool Complex::operator||(const Complex c1)
{
    return this->rel || c1.rel || this->vir || c1.vir;
}
bool Complex::operator>(const Complex c1)
{
    return this->rel>c1.rel;
}
bool Complex::operator<(const Complex c1)
{
    return this->rel<c1.rel;
}
bool Complex::operator>=(const Complex c1)
{
    return this->rel>=c1.rel;
}
bool Complex::operator<=(const Complex c1)
{
    return this->rel<=c1.rel;
}
bool Complex::operator==(const Complex c1)
{
    return this->rel==c1.rel&&this->vir==c1.vir;
}
bool Complex::operator!=(const Complex c1)
{
    return this->rel!=c1.rel||this->vir!=c1.vir;
}
 
//加减乘除
Complex operator+(const Complex c1,const Complex c2)
{
    Complex temp;
    temp.rel =  c1.rel + c2.rel;
    temp.vir =  c1.vir + c2.vir;
    return temp;
}
Complex operator-(const Complex c1,const Complex c2)
{
    Complex temp;
    temp.rel =  c1.rel - c2.rel;
    temp.vir =  c1.vir - c2.vir;
    return temp;
}
Complex operator*(const Complex c1,const Complex c2)
{
    Complex temp;
    temp.rel =  c1.rel * c2.rel-c1.vir * c2.vir;
    temp.vir =  c1.vir * c2.rel+c1.rel * c2.vir;
    return temp;
}
Complex operator/(const Complex c1,const Complex c2)
{
    Complex temp;
    int a = c1.rel;
    int b = c1.vir;
    int c = c2.rel;
    int d = c2.vir;
    temp.rel =  (a*c+b*d)/(c*c-d*d);
    temp.vir =  (b*c-a*d)/(c*c+d*d);
    return temp;
}
/*
Complex Complex::operator+(const Complex c1)
{
    Complex temp;
    temp.rel = this ->rel+c1.rel;
    temp.vir = this->vir +c1.vir;
    return temp;
}
Complex Complex::operator-(const Complex c1)
{
    Complex temp;
    temp.rel = this->rel - c1.rel;
    temp.vir = this->vir - c1.vir;
    return temp;
}
Complex Complex::operator*(const Complex c1)
{
    Complex temp;
    temp.rel = this->rel * c1.rel;
    temp.vir = this->vir * c1.vir;
    return temp;
}
Complex Complex::operator/(const Complex c1)
{
    Complex temp;
    temp.rel = this->rel / c1.rel;
    temp.vir = this->vir / c1.vir;
    return temp;
}*/
 
//输出
ostream &operator<<(ostream &out,Complex c1)
{
    out << c1.rel << "+" << c1.vir << "i" ;
    return out;
}
//输出
istream &operator>>(istream &in,Complex &c1)
{
    in >> c1.rel >> c1.vir;
    return in;
}
 
int main()
{
    Complex c1(4,6),c2(4,0),c3(1,2),c4;
   // cin >> c3 >> c4 ;
   // cout << c3 << endl << c4 << endl;
    cout << (c1<<1) << endl << (c2>>1) << endl;
    cout << ~c3 <<endl;
    c4 =  c1^c2 ;
    cout << c4 <<endl;
 
 
   return 0;
}

3.

//+
myString myString::operator+(const myString s1){
    strcat(this->str,s1.str);
    this->size=this->size+s1.size;
    return *this;
}
//==
bool myString::operator==(const myString s1){
    return !strcmp(this->str,s1.str);
}
//>=
bool myString::operator>=(const myString s1){
    if(strcmp(this->str,s1.str)==0 || strcmp(this->str,s1.str)){
        return 1;
    }else
    return 0;
}
//&&
bool myString::operator&&(const myString s1){
    return this->str && s1.str;
}
//!
bool myString::operator!(){
    return !this->size;
}
//输出
ostream &operator<<(ostream &out,myString s1){
    out << s1.str << '\t' << s1.size ;
    return out;
}
//输入
istream &operator>>(istream &in,myString s1){
    in >> s1.str >> s1.size;
    return in;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值