c++单链表 一元多项式求和_一元多项式的各种运算实现(c++_c).doc

word文档 可自由复制编辑

一元多项式各种运算

本程序可完成一元多项式的加,减,乘,积分,微分运算

输入可按习惯书写形式输入各项,输出按指数降序

//头文件 :

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define TRUE 1

#define FALSE 0

#define OK 1

#define ERROR 0

typedef int status;

typedef float type;

typedef int fuhaosign;

结构体类型定义:

typedef struct list

{

type data;

int zhi;

struct list* next;

}list;

typedef struct node

{

int length;

list* next;

}node;

用到的函数:

注:各函数参数如是结构体指针,则此指针传入函数之前必将其赋值为NULL否则可能出现错误。

void shuoming()

{

cout<

cout<

cout<

cout<

cout<

cout<

}

//求未知数指数是-k时的值

float fumi(int k)

{

float a=1.0;

for(int i=1;i<=k;i++)

a=a*1e-1;

return a;

}

//赋值,参数是指向头结点的指针

void fuzhi(node *&toup)

{

float fumi(int k);

void init(node *&toup);

if(!toup) init(toup);

if(toup->next) init(toup);//保证赋值前链表有且仅有一个头结点

//初始化各变量

char c,ch=' ';//c接受字符,ch记录上一字符,用于检错

int k2=0;//k2标志着+-号前面是否有数值,0时没有,1为有

fuhaosign k1=1;//k1是符号位正负的标志,0为负,1为正

int k3=0;//小数点的个数

int kx=0;//标志前面是否有x

list* p=toup->next,* t;

type dat=0.0;

//输入

c=getchar();

int i=0;

while(c!='\n')

{

if(!p)

{ p=(list*)malloc(sizeof(list)); if(!p) {cout<

if(i==0) {toup->next=p;toup->length++;i++;p->next=NULL;t=p;}

else

{ t->next=p;t=p;p->next=NULL;toup->length++;}

}

if((ch=='+'||ch=='-')&&(c=='+'||c=='-')){cout<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值