设计实现大整数类
题目
设计实现“HugeInteger” 大整数类,实现大整数的加法、输入和输出功能。能够满足以下程序的运行:
#include
#include
using namespace std;
/* 请在这里写出HugeInteger类的定义和实现 */
int main()
{
HugeInteger n1( 7654321 );
HugeInteger n2( 7891234 );
HugeInteger n3( “99999999999999999999999999999” );
HugeInteger n4( “1” );
HugeInteger n5;
cout << "n1 is " << n1 << "\nn2 is " << n2
<< "\nn3 is " << n3 << "\nn4 is " << n4
<< "\nn5 is " << n5 << “\n\n”;
n5 = n1 + n2;
cout << n1 << " + " << n2 << " = " << n5 << “\n\n”;
cout << n3 << " + " << n4 << "\n= " << ( n3 + n4 ) << “\n\n”;
n5 = n1 + 9;
cout << n1 << " + " << 9 << " = " << n5 << “\n\n”;
n5 = n2 + “10000”;
cout << n2 << " + " << “10000” << " = " << n5 << endl;
return 0;
}
输入样例:
无。
输出样例:
n1 is 7654321
n2 is 7891234
n3 is 99999999999999999999999999999
n4 is 1
n5 is 0
7654321 + 7891234 = 15545555
99999999999999999999999999999 + 1
= 100000000000000000000000000000
7654321 + 9 = 7654330
7891234 + 10000 = 7901234
答案
#include <cstring>
#include <sstream>
class HugeInteger
{
public:
HugeInteger(int i = 0);
HugeInteger(string str);
~HugeInteger(){
}
string stradd(string a, string b);
HugeInteger