设计一个自然数数据类型,使得计算机能做更多位数的数字处理
头文件:
//Nature.h
#ifndef _NATURE_H_INCLUDED_
#define _NATURE_H_INCLUDED_
class Nature
{
public:
//Constructors:
Nature(unsigned a=0);
Nature(Nature const& );//copy constructor
~Nature(void);
Nature& operator=(Nature const& b);
//arithmatic operations
Nature& operator+=(Nature const& b);
Nature& operator-=(Nature const& b);
Nature& operator*=(Nature const& b);
Nature& operator/=(Nature const& b);
Nature& operator%=(Nature const& b);
Nature& operator&=(Nature const& b);
Nature& operator|=(Nature const& b);
Nature& operator^=(Nature const& b);
Nature& operator>>=(int bits);
Nature& operator<<=(int bits);
Nature operator>>(int bits) const;
Nature operator<<(int bits) const;
Nature& setbit(int n);
Nature& clearbit(int n);
void loadrandom(void);
};//class Nature
//relation operators
bool operator<(Nature const& a, Nature const& b);
//arithmatic operations
Nature operator+(Nature const& a, Nature const& b);
Nature operator-(Nature const& a, Nature const& b);
Nature operator*(Nature const& a, Nature const& b);
Nature operator/(Nature const& a, Nature const& b);
Nature operator%(Nature const& a, Nature const& b);
void add(Nature& result, Nature const& a, Nature const& b);
void sub(Nature& result, Nature const& a, Nature const& b);
void mul(Nature& result, Nature const& a, Nature const& b);
void div(Nature& result, Nature const& a, Nature const& b);
void mod(Nature& result, Nature const& a, Nature const& b);
void swap(Nature& a, Nature& b);
//input from istream, digits
std::istream& operator<<(std::istream&, Nature& );
//output to ostream, digits
std::ostream& operator>>(std::ostream&, Nature& );
//precondition: n > 0; 0 <= a, b <n
//postcondition: rst == a^b mod n; 0 <= rst < n
void powermod(Nature& rst, Nature const& a,
Nature const& b, Nature const& n);
#endif //~#ifndef _Nature_H_INCLUDED_
//~Nature.h
cpp:
//Nature.cpp
#include "StdAfx.h"
#include ".\Nature.h"
Nature::Nature(unsigned a)
{
}
Nature::~Nature(void)
{
}
Nature& Nature::operator=(Nature const& b)
{
if(this != &b)
{
}
return *this;
}
//~Nature.cpp
Nature& Nature::operator+=(Nature const& b)
{
//*this = *this + b
return *this;
}
//input from istream, digits
std::istream& operator<<(std::istream& is, Nature& a )
{
//read from is, the result is put in a
return is;
}
//output to ostream, digits
std::ostream& operator>>(std::ostream& os, Nature& a )
{
//write a into os;
return os;
}
想是想自己一个人能做,但现在无从下手,希望有人可以指点一下,有兴趣的话,你们也可以一块做一下做个啊