C++长整数、高精度计算器设计一个程序实现两个任意长的整数(包括正数和负数)、任意精度实数的算术运算. 要求:(1)用动态链表存贮数据,每结点含一个整型变量,表示若干位数.(2)整

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 20:12:21
C++长整数、高精度计算器设计一个程序实现两个任意长的整数(包括正数和负数)、任意精度实数的算术运算. 要求:(1)用动态链表存贮数据,每结点含一个整型变量,表示若干位数.(2)整

C++长整数、高精度计算器设计一个程序实现两个任意长的整数(包括正数和负数)、任意精度实数的算术运算. 要求:(1)用动态链表存贮数据,每结点含一个整型变量,表示若干位数.(2)整
C++长整数、高精度计算器
设计一个程序实现两个任意长的整数(包括正数和负数)、任意精度实数的算术运算.

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

C++长整数、高精度计算器设计一个程序实现两个任意长的整数(包括正数和负数)、任意精度实数的算术运算. 要求:(1)用动态链表存贮数据,每结点含一个整型变量,表示若干位数.(2)整
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
#include
#include
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->next=temp;
e=temp;
return ;
}
Node* add(Node *e1,Node* e2)
{
Node*p1=e1;
Node*p2=e2;
Node*p3=NULL;
int carry=0;
int digit=0;
while(p1&&p2){
digit=p1->digit+p2->digit+carry;
carry=digit/10;
digit%=10;
Node* temp=new Node;
temp->next=NULL;
temp->digit=digit;
temp->next=p3;
p3=temp;
p1=p1->previous;
p2=p2->previous;
}
while(p1){
digit=p1->digit+carry;
carry=digit/10;
digit%=10;
Node* temp=new Node;
temp->digit=digit;
temp->next=p3;
p3=temp;
p1=p1->previous;
}
while(p2){
int digit=p2->digit+carry;
carry=digit/10;
digit%=10;
Node* temp=new Node;
temp->digit=digit;
temp->next=p3;
p3=temp;
p2=p2->previous;
}
if(carry){
Node* temp=new Node;
temp->digit=carry;
temp->next=p3;
p3=temp;
}
return p3;
}
Node* multiply(Node* h1,Node* e1,Node* h2,Node* e2)
{
Node* p2=NULL;
Node* pos=NULL;
Node* p=NULL;
Node* pre=NULL;
int digit=0;
int carry;
while(e2){
carry=0;
p=e1;
pre=pos;
p2=pos;
while(p){
digit=(e2->digit*p->digit+carry);
if(p2){
digit+=p2->digit;
p2->digit=digit%10;
carry=digit/10;
}
else if(!p2&&!pre){
Node* temp=new Node;
temp->next=NULL;
temp->previous=NULL;
temp->digit=digit%10;
carry=digit/10;
p2=temp;
pos=temp;
}
else{
Node* temp=new Node;
temp->next=pre;
temp->previous=NULL;
pre->previous=temp;
temp->digit=digit%10;
carry=digit/10;
p2=temp;
}
p=p->previous;
pre=p2;
p2=p2->previous;
}
if(carry){
Node* temp=new Node;
temp->digit=carry;
temp->next=pre;
pre->previous=temp;
temp->previous=NULL;
p2=temp;
pre=p2;
}
pos=pos->previous;
e2=e2->previous;
}
return pre;
}
bool cmp_digit(Node* e1,Node* h1,Node* e2,Node* h2)
{
int n_digit1=0;
int n_digit2=0;
Node* p1=e1;
Node* p2=e2;
Node* q1=h1;
Node* q2=h2;
while(p1){
n_digit1++;
p1=p1->previous;
}
while(p2){
n_digit2++;
p2=p2->previous;
}
if(n_digit1>n_digit2){
return true;
}
else if(n_digit1digit>q2->digit){
return true;
}
else if(q1->digitdigit){
return false;
}
else{
q1=q1->next;
q2=q2->next;
}
}
}
return true;
}
Node* subtract(Node* h1,Node* e1,Node* h2,Node* e2)
{
Node* p1h=h1;
Node* p1e=e1;
Node* p2h=h2;
Node* p2e=e2;
int digit=0;
bool flag=(cmp_digit(p1e,p1h,p2e,p2h));
if(flag==true){
Node* p3=NULL;
while(e2){
if(e2->digit>e1->digit){
digit=10+e1->digit-e2->digit;
e1->previous->digit--;
Node *temp=new Node;
temp->digit=digit;
temp->next=p3;
p3=temp;
}
else{
digit=e1->digit-e2->digit;
Node* temp=new Node;
temp->digit=digit;
temp->next=p3;
p3=temp;
}
e2=e2->previous;
e1=e1->previous;
}
while(e1){
Node *temp=new Node;
if(e1->digitdigit+=10;
e1->previous->digit--;
}
temp->digit=e1->digit;
temp->next=p3;
p3=temp;
e1=e1->previous;
}
return p3;
}
else{
Node* p3=NULL;
while(e1){
if(e1->digit>e2->digit){
digit=10+e2->digit-e1->digit;
e2->previous->digit--;
Node *temp=new Node;
temp->digit=digit;
temp->next=p3;
p3=temp;
}
else{
digit=e2->digit-e1->digit;
Node* temp=new Node;
temp->digit=digit;
temp->next=p3;
p3=temp;
}
e2=e2->previous;
e1=e1->previous;
}
while(e2){
Node *temp=new Node;
if(e2->digitdigit+=10;
e2->previous->digit--;
}
temp->digit=e2->digit;
temp->next=p3;
p3=temp;
e2=e2->previous;
}
return p3;
}
}
void output(Node* h)
{
Node*p=h;
while(p&&p->digit==0){
p=p->next;
}
if(!p){
cout

C++长整数、高精度计算器设计一个程序实现两个任意长的整数(包括正数和负数)、任意精度实数的算术运算. 要求:(1)用动态链表存贮数据,每结点含一个整型变量,表示若干位数.(2)整 设计一个程序:输入一个整数,判断它的奇偶性.请用c语言 设计一个程序:输入一个整数,判断它的奇偶性. 设计一个C ++程序,从键盘输入a b c 三个整数,将他们从大到小依次输出 C语言程序设计求助,求设计一个程序,要求输入1-7的整数,对应输出星期一~星期天,最好附上思路, 设计一个测试计算器的加减乘除功能的程序如题 设计一个计算器程序 要求:①有计算器界面,计算器可进行四则运算和部分函数运算;②可以输入浮点数;③通 设计一个运算程序 用C++语言设计一个简单计算器.用户输入四则运算表达式,程序输出正确结果(有追加)设计一个简单计算器.用户输入四则运算表达式,程序输出正确结果.当表达式中数据格式或运算符输入错误, 用单片机开发板89C51设计一个用数码管显示4*4键盘实现加减乘除计算器功能的程序 设计一个程序求输入的一个整数的各位数字之和 设计一个程序,输入一个整数,判断该数的奇偶性. 设计一个c程序输出1-20之间的奇数. 设计一个C语言程序;输入整数x,如果x是正数,输出x的平方;如果x是负数,输出x的2倍. pascal高精度快速幂程序 c计算器程序软件设计1,设计一程序,能够实现1~3位数的加减乘除运算.2,实现数据的乘方、对数、指数运算等等. 设计一个程序实现两个任意长的整数的求和运算.基本要求:利用双向循环链表,设计一个实现任意长的整数进行加法运算的演示程序.要求输入和输出每四位一组,组间用逗号隔开.如:1,0000,0000 设计一个程序实现两个任意长的整数的求和运算.设计一个实现任意长的整数进行加法运算的演示程序.要求输入和输出每四位一组,组间用逗号隔开.如:1,0000,0000,0000,0000.程序代码不要有错、