大整数类,重载运算符"<<",">>","!=","+=","+","*",uva424,uva485,uva495,uva324
设计大整数类以及几个运算符重载
#include
#include
#include
#include
#include
#include<memory.h>
using namespace std;
class bigInteger
{
private:
string number; //用string类来存放大整数
public:
bigInteger(string s=“0”){ number = s; } //带默认值的构造函数
void setNumber(string s){ number = s; }
string getNumber(){return number;}
friend istream& operator>>(istream& input, bigInteger& bigInt); //输入运算符重载,友元函数
friend ostream& operator<<(ostream& output, bigInteger& bigInt); //输出运算符重载,友元函数
bool operator!=(bigInteger bigInt); // "!=“运算符的重载
void operator+=(bigInteger bigInt); //”+=“运算符的重载
bigInteger operator+(bigInteger bigInt); //”+“运算符的重载
bigInteger operator*(int n); //”*"运算符的重载
};
//">>"重载
istream& operator>>(istream&input, bigInteger& bigInt) //输入运算符重载,友元函数
{
input >> bigInt.number;
return input;
}
//"<<"重载
ostream& operator<<(ostream& output, bigInteger& bigInt) //输出运算符重载,友元函数
{
output << bigInt.number;
return output;
}
//"!="重载
bool bigInteger::operator!=(bigInteger bigInt) //"!="运算符的重载
{
if (number != bigInt.number)
return true;
return false;
}
//"+="重载
void bigInteger::operator+=(bigInteger bigInt) //"+="运算符的重载
{
reverse(number.begin(),