資源簡介
任意長大整數(shù)求整商及余數(shù)(C++課程設(shè)計)
代碼片段和文件信息
#include??
#include?
using?namespace?std;
using?std::string;
//大整數(shù)類
class?BigInteger{?
public:?
int?*BigNum;
string::size_type?n;
//構(gòu)造函數(shù)
BigInteger(string);
BigInteger(string::size_type?m)?{
n=m;
BigNum=new?int[m];
for(string::size_type?i=0;i BigNum[i]=0;?
}
~BigInteger(){
delete?[]?BigNum;
}
//打印輸出
void?display();
};
//根據(jù)字符串構(gòu)造大整數(shù)
BigInteger::BigInteger(string?BigNumber){?
n=BigNumber.size();
BigNum=new?int[n];
for(string::size_type?i=0;i BigNum[i]=BigNumber[i]-‘0‘;?
}?
//打印大整數(shù)
void?BigInteger::display(){?
string::size_type?i=0;
//開始的0不輸出
while?(BigNum[i]==0)
++i;
//從第一個非0開始輸出
if?(i==n)?cout<<0;
else
for(;i cout< cout<
評論
共有 條評論