一.问题描述

  编写程序定义类point,有数据成员x,y,为其定义函数实现重载“+”

二.设计思路

  按照题目要求编程即可

三.流程图

四.伪代码 

1

五.代码实现 

1#include<iostream>
using namespace std;

class counter
{
private:
    int i;
public:
    counter() {}
    counter(int p) { i = p; }
    ~counter() {}
    int geti() {
        return i;
    }
    void seti(int p) {
        i = p;
    }
    counter operator+(counter& r)
    {
        return counter(i + r.geti());
    }

};


int main()
{
    counter a(1), b(2), c;
    c = a + b;
    cout << c.geti() << endl;
    return 0;
}

 

posted on 2023-04-13 20:09  leapss  阅读(28)  评论(0)    收藏  举报