求救,构造一种新的整数类型MEGA_INTEGER
来源:百度知道 编辑:UC知道 时间:2024/09/22 15:42:11
提示:可以用数组,字符串,指针,复合数据类型
请哪位给出c++程序
fengerzh 提供的 MEGA_INTEGER 类是个开始,但它的一些细节楼主必须注意:
1)没有减和除的操作
2)调用 C++ 里不该调用的 C 资源管理函数:malloc( ), realloc( ) ...
3)利用非标准 C++ 数据类型:微软 C++ 的 _int64
4)实际上只是 int 而已:MEGA_INTEGER( 2147483647 ) + 1 即导致溢出
也许还有其它待改进的地方。大家继续参与。。。
这是别人写的,应该可以用:
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
class MEGA_INTEGER
{
public:
MEGA_INTEGER(const _int64& x=0);
~MEGA_INTEGER()
{
free(datepoint);
}
MEGA_INTEGER(const MEGA_INTEGER& x);
MEGA_INTEGER& operator=(const MEGA_INTEGER& right);
friend ostream& operator<<(ostream& os,const MEGA_INTEGER& r);
friend ostream& operator>>(ostream& os,const MEGA_INTEGER& r);
friend const MEGA_INTEGER operator*(const MEGA_INTEGER& left,const MEGA_INTEGER& right);
friend const MEGA_INTEGER operator+(const MEGA_INTEGER& left,const MEGA_INTEGER& right);
pri