C++&QT-day4

#include  //运算符重载
using namespace std;

class Person
{
//    //全局函数实现+运算符重载
//    friend const Person operator+(const Person &L,const Person &R);
//    //全局函数实现-运算符重载
//    friend const Person operator-(const Person &L,const Person &R);
//    //全局函数实现*运算符重载
//    friend const Person operator*(const Person &L,const Person &R);
//    //全局函数实现/运算符重载
//    friend const Person operator/(const Person &L,const Person &R);
//    //全局函数实现%运算符重载
//    friend const Person operator%(const Person &L,const Person &R);

//    //全局函数实现>运算符重载
//    friend bool operator>(const Person &L, const Person &R);
//    //全局函数实现>=运算符重载
//    friend bool operator>=(const Person &L, const Person &R);
//    //全局函数实现<运算符重载
//    friend bool operator<(const Person &L, const Person &R);
//    //全局函数实现<=运算符重载
//    friend bool operator<=(const Person &L, const Person &R);
//    //全局函数实现==运算符重载
//    friend bool operator==(const Person &L, const Person &R);
//    //全局函数实现!=运算符重载
//    friend bool operator!=(const Person &L, const Person &R);


//    //全局函数实现=运算符重载
//    friend Person &operator=(Person &L, const Person &R);
//    //全局函数实现+=运算符重载
//    friend Person &operator+=(Person &L, const Person &R);
//    //全局函数实现-=运算符重载
//    friend Person &operator-=(Person &L, const Person &R);
//    //全局函数实现*=运算符重载
//    friend Person &operator*=(Person &L, const Person &R);
//    //全局函数实现/=运算符重载
//    friend Person &operator/=(Person &L, const Person &R);
//    //全局函数实现%=运算符重载
//    friend Person &operator%=(Person &L, const Person &R);

private:
    int a;
    int b;
public:
    Person(){}
    Person(int a, int b):a(a),b(b){}
/****************成员函数实现+运算符重载*******************/
    const Person operator+(const Person &p)const
    {
        Person temp;
        temp.a = a + p.a;
        temp.b = b + p.b;
        return  temp;
    }
    /****************成员函数实现-运算符重载*******************/
    const Person operator-(const Person &p)const
    {
        Person temp;
        temp.a = a - p.a;
        temp.b = b - p.b;
        return  temp;
    }
    /****************成员函数实现*运算符重载*******************/
    const Person operator*(const Person &p)const
    {
        Person temp;
        temp.a = a * p.a;
        temp.b = b * p.b;
        return  temp;
    }
    /****************成员函数实现/运算符重载*******************/
    const Person operator/(const Person &p)const
    {
        Person temp;
        if(0==p.a && 0==p.b)
            cout << "除数为0" << endl;
        else if(0==p.a && 0!=p.b)
        {
            cout << "a除数为0" << "  b = " << b << endl;
            temp.a = a / p.b;
        }
        else if(0!=p.a && 0==p.b)
        {
            temp.b = b / p.a;
            cout << "a = " << a << " b除数为0" << endl;
        }
        else
        {
            temp.b = b / p.a;
            temp.a = a / p.b;
            cout << "a = " << a << "  b = " << b << endl;
        }
        return  temp;
    }
    /****************成员函数实现%运算符重载*******************/
    const Person operator%(const Person &p)const
    {
        Person temp;
        temp.a = a % p.a;
        temp.b = b % p.b;
        return  temp;
    }
/***************成员函数实现>关系运算符重载***************/
    bool operator>(const Person &R)const
    {
        if(a>R.a && b>R.b)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    /***************成员函数实现>=关系运算符重载***************/
    bool operator>=(const Person &R)const
    {
        if(a>=R.a && b>=R.b)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    /***************成员函数实现<关系运算符重载***************/
    bool operator<(const Person &R)const
    {
        if(ap2" << endl;
    else if(p3>=p2)
        cout << "p3>=p2" << endl;
    else if(p3

C++&QT-day4_第1张图片

C++&QT-day4_第2张图片

你可能感兴趣的:(c++,qt,数据库)