一元多项式简单计算器

来源:百度知道 编辑:UC知道 时间:2024/05/19 14:34:58
要求:一元多项式计算器的基本功能定为
(1) 建立多项式
(2) 输出多项式
(3) 两个多项式相加,建立并输出和多项式
(4) 两个多项式相减,建立并输出差多项式
实现提示:可选择带头结点的单向循环链表
或单链表存储多项式,头结点可存放多项式
的参数,如项数等。(附:什么是带头结点的单向循环链表或单链表)我第一次上这个,希望各位高手能帮帮我..

#include <iostream>
#include <cstdlib>
#include <cctype>
using namespace std;

void eatspaces(char* str);
double expr(char* str);
double term(char* str,int& index);
double number(char* str,int& index);
char* extract(char* str, int& index);

const int MAX = 80;

int main()
{
char buffer[MAX] = {0};
cout<< endl
<< "欢迎使用计算器"<<endl
<<"请输入表达式进行计算或者输入空白行退出"<<endl;
for(;;)
{
cin.getline(buffer,sizeof buffer);
eatspaces(buffer);

if(!buffer[0])
return 0;

cout<<"\t="<<expr(buffer)
<<endl<<endl;
}
}

void eatspaces(char* str)
{
int i = 0;
int j = 0;

while((*(str + i)=