读书人

设计一个大整数BigInt,重载整数的所有

发布时间: 2012-06-03 16:59:40 作者: rapoo

设计一个大整数BigInt,重载整数的所有算数运算和关系运算,设计一个运用实例
求大神帮忙写下 只要实现四则运算就行了

[解决办法]

C/C++ code
#ifndef BIGINT_H#define BIGINT_H#include<vector>#include<string>#include<iostream>using namespace std;class bigInt{public:    bigInt(){Flag=true;}    bigInt(unsigned int len);//大数长度为len,值为0    bigInt(string str);//大数为string    ~bigInt(){}    /*重载比较运算符*/    friend bool operator >(const bigInt& lInt,const bigInt& rInt);    friend bool operator >(const bigInt& lInt,const string& str);    friend bool operator <(const bigInt& lInt,const bigInt& rInt);    friend bool operator <(const bigInt& lInt,const string& str);    friend bool operator <=(const bigInt& lInt,const bigInt& rInt);    friend bool operator ==(const bigInt& lInt,const bigInt& rInt);    friend bool operator ==(const bigInt& lInt,const string& str);    /*重载输入输出运算符*/    friend istream& operator >>(istream& in,bigInt& bInt);    friend ostream& operator <<(ostream& out,bigInt& bInt);    /*重载+ - * /%运算符*/    friend bigInt operator +(const bigInt& lInt,const bigInt &rInt);    friend bigInt operator +(const bigInt& lInt,const string& str);    friend bigInt operator -(const bigInt& lInt,const bigInt &rInt);    friend bigInt operator -(const bigInt& lInt,const string& str);    friend bigInt operator *(const bigInt& lInt,const bigInt &rInt);    friend bigInt operator /(const bigInt& lInt,const bigInt &rInt);    friend bigInt operator %(const bigInt& lInt,const bigInt& rInt);    //bool Flag;//判断减法结果是否为负,TRUE表示结果为正private:    vector<int> num;//存放大数类    unsigned int length;//大数类的长度    bool Flag;//保存大数的符号    void delZeroFront();//去掉大数中前面的0,如果全为零则保留一个0    void addZeroFront(unsigned int len);//大数前面补零    void addZeroTail(unsigned int len);//大数后面补零};#endif 

读书人网 >C++

热点推荐