程序设计二(面向对象)_实训8_完整的Int包装类

该文章展示了一个名为Int的C++类,这个类用于封装整数并实现了加法、减法、乘法、除法和取模等基本算术运算的重载操作符,以及自增和自减操作。类中包含了构造函数、复制构造函数、析构函数以及获取和设置值的方法。
摘要由CSDN通过智能技术生成

第1关:完整的包装类

/********** BEGIN **********/
#include <iostream>
#include "Int.h"
#include "IntOp.h"
using namespace std;
Int::Int() {}
Int::Int(const Int&rhs) { value = rhs.value; }
Int::Int(int v) { value = v; }
Int::~Int() { }
int Int::getValue()const { return value; }
void Int::setValue(int v) { value = v; }
Int& Int::operator +=(const Int& rhs) {
	this->value += rhs.value;
	return *this;
}
Int& Int::operator -=(const Int& rhs) {
	this->value -= rhs.value;
	return *this;
}
Int& Int::operator =(const Int& rhs) {
	this->value = rhs.value;
	return *this;
}
Int& Int::operator *=(const Int& rhs) {
	this->value *= rhs.value;
	return *this;
}
Int& Int::operator /=(const Int& rhs) {
	this->value /= rhs.value;
	return *this;
}
Int& Int::operator %=(const Int& rhs) {
	this->value %= rhs.value;
	return *this;
}
Int Int::operator ++(int tmp) {
	return Int(value++); 
}
Int Int::operator --(int tmp) {
	return Int(value--); 
}
Int& Int::operator ++() {
	value += 1;
	return *this;
}
Int& Int::operator --() {
	value -= 1;
	return *this;
}
/********** END **********/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值