- 36
- 0
- 约7.14千字
- 约 19页
- 2021-10-13 发布于天津
- 举报
*************************************************
*************************************************
1.1设计内容及要求 1)设计内容
使用顺序存储结构实现多项式加、减、乘运算。
例如:
f(x) 8x6 5x5 10x4 32x2 x 10,g(x) 7x5 10x4 20x3 10x2 x
求和结果:f (x) g(x) 8x6 12x5 20x3 22x2 10
使用链式存储结构实现多项式加、减、乘运算,
f(x) 100x100 5x50 30x10 10,g(x) 150x90 5x50 40x20 20x10 3x
求和结果:f(x) g(x) 100x100 150x90 40x20 10x10 3x 10
2 )设计要求
(1)用C语言编程实现上述实验内容中的结构定义和算法。
要有main()函数,并且在main()函数中使用检测数据调用上述算法
用switch语句设计如下选择式菜单。
***************
数据结构综合性实验
****************
、多项式的加法、减法、乘法运算
**********
*******
1?多项式创建
**********
*******
2?多项式相加
**********
*******
3?多项式相减
**********
*******
4?多项式相乘
**********
********************
**********
**********
5.清空多项式
*******请选择(0 — 5)
*******
请选择(0 — 5)
**********
请选择(0-5 )
1.2数据结构设计
根据下面给出的存储结构定义:
#defi ne MAXSIZE 20//定义线性表最大容量//定义多项式项数据类型typedef struct{float coef;//系数
#defi ne MAXSIZE 20
//定义线性表最大容量
//定义多项式项数据类型
typedef struct
{
float coef;
//系数
int exp n;
//指数
}term,elemType;
typedef struct
{
term terms[MAXSIZE]; int last;
}SeqList;
typedef SeqList polyno mial;
1.3基本操作函数说明
//线性表中数组元素
//指向线性表中最后一个元素位置
polyno mial* Ini t_Po lyno mial();
//初始化空的多项式
int Pioyn Status(poly no mial*p)
//判断多项式的状态
int Location_Element(polynomial*p,term x)
在多项式p中查找与x项指数相同的项是否存在
int In sert_Eleme ntByOrder(poly no mial*p,term x)
//在多项式p中插入一个指数项x
int CreatePo lyn(polyno mial*P ,int m)
//输入m项系数和指数,建立表示一元多项式的有序表 p
char compare(term term1,term term2)
//比较指数项term1和指数项term2
poly no mial*addPlo yn (poly no mial*p1,poly no mial*p2)
//将多项式p1和多项式p2相加,生成一个新的多项式
poly no mial*subStractPlo yn (poly no mial*p1,poly no mial*p2)
//多项式p1和多项式p2相减,生成一个新的多项式
poly no mial*mulitPlo yn (poly no mial*p1,poly no mial*p2)
//多项式p1和多项式p2相乘,生成一个新的多项式
void prin tPlo yn (poly no mial*p)
//输出在顺序存储结构的多项式 p
1.4程序源代码 #in cludestdlib.h
#i ncludestdio.h #i ncludeiostream.h
#defi ne NULL 0
#defi ne MAXSIZE 20 typedef struct
{
float coef;
int exp n;
}term,elemType;
typedef struct
{
term terms[MAXSIZE];
int last;
}SeqList;
typedef SeqList polyno mial; void prin tPlo yn (
原创力文档

文档评论(0)