资源简介
#ifndef HUGEINT_H
#define HUGEINT_H
#include <iostream>
using std::ostream;
class HugeInt
{
friend ostream& operator<<(ostream&, const HugeInt&);
public:
HugeInt(long = 0);
HugeInt( const char * );
HugeInt operator ( const HugeInt & ) const;
HugeInt operator ( int ) const;
HugeInt operator ( const char * ) const;
bool operator==(const HugeInt&) const;
bool operator!=( const HugeInt & ) const;
bool operator<( const HugeInt & ) const;
bool operator<=( const HugeInt & ) const;
bool operator>( const HugeInt & ) const;
bool operator>=( const HugeInt & ) const;
HugeInt operator-( const HugeInt & ) const;
HugeInt operator*( const HugeInt & ) const;
HugeInt operator/( const HugeInt & ) const;
void output();
int getLength() const;
private:
int integer[40];
};
#endif
#define HUGEINT_H
#include <iostream>
using std::ostream;
class HugeInt
{
friend ostream& operator<<(ostream&, const HugeInt&);
public:
HugeInt(long = 0);
HugeInt( const char * );
HugeInt operator ( const HugeInt & ) const;
HugeInt operator ( int ) const;
HugeInt operator ( const char * ) const;
bool operator==(const HugeInt&) const;
bool operator!=( const HugeInt & ) const;
bool operator<( const HugeInt & ) const;
bool operator<=( const HugeInt & ) const;
bool operator>( const HugeInt & ) const;
bool operator>=( const HugeInt & ) const;
HugeInt operator-( const HugeInt & ) const;
HugeInt operator*( const HugeInt & ) const;
HugeInt operator/( const HugeInt & ) const;
void output();
int getLength() const;
private:
int integer[40];
};
#endif
代码片段和文件信息
#include
#include“hugeint.h“
using namespace std;
ostream& operator<<(ostream& output const HugeInt& n)
{
int i;
for (i = 0; (n.integer[i] == 0) && (i <= 39); i++);
if (i == 40)
output << 0;
else
for (i; i < 40; i++)
{
output << n.integer[i];
}
return output;
}
HugeInt::HugeInt(long num)
{
for (int i = 0; i < 40; i++)
{
integer[i] = 0;
}
for (int j = 39; num != 0 && j > 0; --j)
{
integer[j] = num % 10;
num /= 10;
}
}
HugeInt::HugeInt(const char* c)
{
for (int i = 0; i < 40; i++)
integer[i] = 0;
int lenth = strlen(c);
for (int j = 40 - lenth k = 0; j < 40; j++ k++)
if (isdigit(c[k]))
integer[j] = c[k] - ‘0‘;
}
HugeInt HugeInt::operator+(const HugeInt& n) const
{
HugeInt temp;
int carry = 0;
for (i
- 上一篇:计算器 实现普通计算、进制转换和阶乘计算
- 下一篇:C语言基础思维导图
相关资源
- C++实战源码-小蛇长得快
- C++实战源码-文字水平滚动
- C++实战源码-替换指定的字符串
- C++实战源码-小球称重
- C++实战源码-新同学的年龄
- C++实战源码-向数组中赋值
- C++实战源码-用#打印三角形
- C++实战源码-统计学生成绩分布
- C++实战源码-向数组中插入元素
- C++实战源码-用指向函数的指针比较大
- C++实战源码-用宏定义实现值互换
- C++实战源码-CD抓取
- C++实战源码-指定符号分割字符串
- C++实战源码-抓不住的兔子
- C++实战源码-用new动态创建结构体
- C++实战源码-将AVI动画分解成BMP位图
- C++实战源码-修改可执行文件中的资源
- C++实战源码-指向结构体变量的指针
- C++实战源码-将二维数组行列对换
- C++实战源码-应用random_shuffle算法将元
- C++实战源码-应用adjacent_find算法搜索相
- C++实战源码-数组中整数的判断
- C++实战源码-获取数组中元素的个数
- C++实战源码-将二维数组转换为一维数
- C++实战源码-迭代器的用法
- C++实战源码-二维数组行最大值中的最
- C++实战源码-输出数组元素
- C++实战源码-使用指针变量遍历二维数
- C++实战源码-数组中连续相等数的计数
- C++实战源码-计算字符串中有多少个单
评论
共有 条评论