云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > c++实现任意长整数的四则运算

c++实现任意长整数的四则运算

  • 62 次阅读
  • 3 次下载
  • 2025/12/9 20:50:23

实用文档

{ cout<<\ } else{ cout<<\ list2.Display(); break; } } string choose; while (1) { cout<<\请选择运算法:\ cout<<\ /*菜单*/ cout<<\ |\ /*可以重复输入运算符,按'#'退出*/ cout<<\ |\ cout<<\ |\ cout<<\ while (1) {

cin>>choose; if (choose==\ {

list1+list2; break; } else if (choose==\ { list1*list2; break; } else if (choose==\ { return; } else { cout<<\输入有误,请重新输入!!\ continue; } } } }

标准

实用文档

/*头文件,包括长整数数据结构的定义,成员函数的定义*/

/***********************************************************/

#include #include #include using namespace std; struct DblNode{ int data;

DblNode * prior; DblNode * next; };

bool IsNum(char a){ //判断字符a是否是便是数字 int s=a-'0'; if(s>=0&&s<10) return true; else return false; }

bool IsInt(string a){ //判断字符串a是否表达一串数字 bool Jud=1; int i=1; char s=a[0]; if (a==\ return false; if (s=='+'||s=='-') {} else if (s>='1'&&s<='9'){} else if (a[0]=='0'&&a[1]=='\\0') return true; else return false; while (a[i]!='\\0') { Jud=IsNum(a[i]); if (Jud==0) return false; i++; } return true; }

int JudSign(string s){ //返回数字的符号 if (s[0]=='-') return -1; else if(s[0]=='0'&&s[1]=='\\0') return 0; else return 1; }

int CtoI(char a){

标准

实用文档

int i=a-'0'; return i; }

class DblList { //定义一个双向链表类,存储任意长度的数字 private: //并可以进行标准化输出和加法,乘法。 DblNode *head, *tail; DblNode *current; int sign; public: DblList(); ~DblList(); bool CreatList(string); int GetCount(); void Insert(DblNode *); void InsertFront(DblNode *); void Clear(); void operator+(DblList &); void operator*(DblList &); DblList & operator=(DblList &); int Compare(DblList &); void Display(); };

DblList::DblList(){ head=new DblNode(); head->next=NULL; head->prior=NULL; tail=head; current=NULL; sign=0; }

DblList::~DblList(){ while (head->next!=NULL) {

current=head->next; head->next=current->next; delete current; } current=NULL; sign=0; delete head; head=NULL;

标准

//构造函数 //析构函数 //生成一个双向链表 //获取整数的长度 //从表尾插入一个结点 //从表头插入一个结点 //清除该链表 //实现两个任意整数的加法 //实现两个任意整数的乘法 //重载赋值运算符

//两个整数的绝对值比较 //任意长度整数的标准化输出 //构造函数 //析构函数 实用文档

tail=NULL; }

int DblList::GetCount(){ //返回该数字的长度(不包括符号位) current=head->next; int count=0; while (current) { count++; current=current->next; } current=NULL; return count; }

void DblList::Insert(DblNode *p){ tail->next=p; p->prior=tail; tail=p; }

void DblList::InsertFront(DblNode *q){ if (head->next==NULL) { head->next=q; q->prior=head; tail=q; } else{ q->next=head->next; head->next->prior=q; head->next=q; q->prior=head; } }

bool DblList::CreatList(string s){ bool j=IsInt(s); if (!j) return j; else{ int i=0; sign=JudSign(s); if (s[0]=='+'||s[0]=='-') i++; while (s[i]!='\\0')

标准

//从链表尾部插入一个结点 //从链表头部插入一个结点 //输入的任意长度的表示数字的字符串 //以此生成双向链表

搜索更多关于: c++实现任意长整数的四则运算 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

实用文档 { cout<<\ } else{ cout<<\ list2.Display(); break; } } string choose; while (1) { cout<<\请选择运算法:\ cout<<\ /*菜单*/ cout<<\ |\ /*可以重复输入运算符,按'#'退出*/ cout<<\ |\ cout<<\ |\ cout<<\ while (1) { cin>>choose; if (choose==\ {

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com