| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 682 人关注过本帖
标题:数据结构实验课程:自然数类型的设计
只看楼主 加入收藏
dlg
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-6-29
收藏
 问题点数:0 回复次数:0 
数据结构实验课程:自然数类型的设计

设计一个自然数数据类型,使得计算机能做更多位数的数字处理
头文件:
//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;
}


想是想自己一个人能做,但现在无从下手,希望有人可以指点一下,有兴趣的话,你们也可以一块做一下做个啊

搜索更多相关主题的帖子: 自然数 数据结构 课程 实验 类型 
2006-06-29 00:44
快速回复:数据结构实验课程:自然数类型的设计
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016988 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved