资源描述:
《大数运算加减乘除幂正负数整数小数源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、/*jiegou.h*/structshuzi{charshu;shuzi*front;shuzi*next;};/*hanshu.h*/#include#include#include#include#include"jiegou.h"usingnamespacestd;voidfindend(shuzi*&);//指针末置voidbianli(shuzi*);//遍历链表voidguifang(shuzi*);//将结果用逗号规范化后再输出voidshuru(shuzi*&,int&);//输入数据,记录符号i
2、ntlenpoint(shuzi*);//计算输入的数小数点后的长度intlenfront(shuzi*);//计算输入的数小数点前的长度voiddeletepoint(shuzi*);//删除数据中的小数点voidqingkong(shuzi*);//清空链表intcompare(shuzi*,shuzi*);//比较两个数的大小voidjiafuhao(shuzi*&);//在链表表头加上负号voidjia(shuzi*,shuzi*,shuzi*&);//大数相加voidjian(shuzi*,shuzi*,shuzi*&);//大数相减voidcheng(shuzi*,shuzi
3、*,shuzi*&);//大数相乘voidchu(shuzi*,shuzi*,shuzi*&,int);//大数相除voidmicheng(shuzi*,shuzi*&,int);//大数幂乘voidchengjia(shuzi*,shuzi*,shuzi*&);//乘加:乘法计算中把临时结果加入最终结果的函数(即大数整数相加)voidchujian(shuzi*,shuzi*,shuzi*&);//除减:除法计算中得到临时链表和除数相减结果的函数(即大数整数相减)/*删除小数点.cpp*/#include"jiegou.h"voiddeletepoint(shuzi*head){whi
4、le(head->shu!='.'&&head->next)//当指针指向的不是小数点且后面还有结点时,继续向后偏移寻找小数点结点{head=head->next;}if(head->next)//当指针指向的是小数点结点时,删除小数点,否则不做操作(指向的为尾结点,即数据为整数,不需要删除){shuzi*p=head->front;p->next=head->next;p=p->next;p->front=head->front;deletehead;}}/*小数点前面的长度.cpp*/#include"jiegou.h"intlenfront(shuzi*head){intlongt
5、h=0;while(head->next&&head->shu!='.'){longth++;head=head->next;}if(head->shu!='.')longth++;returnlongth;}/*指针末置.cpp*/#include"jiegou.h"voidfindend(shuzi*&pb){while(pb->next){pb=pb->next;}}/*比较两个数的大小.cpp*/#include"jiegou.h"intlenpoint(shuzi*);//计算输入的数小数点后的长度intlenfront(shuzi*);//计算输入的数小数点前的长度intco
6、mpare(shuzi*heada,shuzi*headb){intlena=lenfront(heada),lenb=lenfront(headb);intlenaftera=lenpoint(heada),lenafterb=lenpoint(headb);if(lena>lenb){return1;}//a整数部分比b长,a大elseif(lena0;lena--){if(heada->shu>headb->shu){return1;}elseif(he
7、ada->shushu){return0;}else{if(heada->next&&heada->shu!='.'){heada=heada->next;headb=headb->next;}}}//整数部分完全一样,比较小数部分if(lenaftera!=0&&lenafterb==0){return1;}//若b没有小数部分,a有,a大elseif(lenaftera==0&&lenafterb!=0){ret