C++长整数、高精度计算器

来源:百度知道 编辑:UC知道 时间:2024/06/15 05:11:32
设计一个程序实现两个任意长的整数(包括正数和负数)、任意精度实数的算术运算。

要求:
(1)用动态链表存贮数据,每结点含一个整型变量,表示若干位数。
(2)整数输入和输出按中国对于长整数的习惯表示,每3位1组,组间用逗号隔开。
(3)实现加、减运算。
(4)程序运行界面清晰实用。

dos 界面
我刚编过,实现加减乘除:从文件读取数字和符号,文件格式是
1000
2000
+

299
188
-
这样的:

程序如下,你可以按你要求修改:
//read a file name
//the file contains nonnegtive integers and operators including + - *
//the format is two lines of integers and a line of operator
//the integers can be arbitrarily large

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct Node {
int digit;
Node* next;
Node* previous;
};

void insert(Node* &h,Node* &e,int num)
{
Node* p=h;
if(!p){
Node*temp=new Node;
temp->digit=num;
temp->next=NULL;
temp->previous=NULL;
h=temp;
e=temp;
return ;
}
while(p->next){
p=p->next;
}
Node* temp=new Node;
temp->digit=num;
temp->next=NULL;
temp->previous=p;
p->n