4.27打卡

 

复制代码
#include<bits/stdc++.h>
using namespace std;
class Time
{
    private:
    int minute;
    int hour;
    public:
    void set(int h, int m)
    {
        minute = m;
        hour = h;
    }
    friend int operator-(Time, Time);
};

int operator-(Time t2, Time t1)
{
    return(t2.hour-t1.hour)*60+t2.minute-t1.minute;
}

int main()
{
    int a, b, c, d;
    Time t1, t2;
    cin >> a >> b >> c >> d;
    do{
        t1.set(a,b);
        t2.set(c,d);
        cout <<(t2-t1)<<endl;
        cin >> a>> b >> c >> d;
    }while(!(a == 0 && b == 0 && c == 0 && d == 0));
}
复制代码

 

 

 

复制代码
#include<bits/stdc++.h>
using namespace std;
class CComplex
{
    public:
    CComplex(double r=0, double i=0):real(r), imag(i){};
    CComplex operator+(const CComplex& c)
    {
        CComplex temp;
        temp=*this;
        temp.real += c.real;
        temp.imag += c.imag;
        return temp;
    };
    CComplex operator -=(const CComplex& c)
    {
        real-=c.real;
        imag-=c.imag;
        return *this;
    };
    friend CComplex operator-(const CComplex& c1, const CComplex& c2);
    void Display() const;
    private:
    double real;
    double imag;
};
    CComplex operator-(const CComplex& c1, const CComplex& c2)
    {
        CComplex temp;
        temp.real=c1.real-c2.real;
        temp.imag=c1.imag-c2.imag;
        return temp;
    }

void CComplex::Display() const
{
    cout <<"("<<real <<","<<" "<<imag<<")"<<endl;
}
int main()
{
    double r,m;
    cin>>r>>m;
    CComplex c1(r,m);
    cin >>r>>m;
    CComplex c2(r,m);
    CComplex c3=c1+c2;
    c3.Display();
    c3 = c1-c2;
    c3.Display();
    c3 -= c1;
    c3.Display();
    return 0;
}
复制代码

 

posted @   yblll  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示