一元稀疏多项式简单计算器

上传人:平*** 文档编号:11989330 上传时间:2017-10-16 格式:DOC 页数:70 大小:511.10KB
返回 下载 相关 举报
一元稀疏多项式简单计算器_第1页
第1页 / 共70页
一元稀疏多项式简单计算器_第2页
第2页 / 共70页
一元稀疏多项式简单计算器_第3页
第3页 / 共70页
一元稀疏多项式简单计算器_第4页
第4页 / 共70页
一元稀疏多项式简单计算器_第5页
第5页 / 共70页
点击查看更多>>
资源描述

《一元稀疏多项式简单计算器》由会员分享,可在线阅读,更多相关《一元稀疏多项式简单计算器(70页珍藏版)》请在金锄头文库上搜索。

1、1浏水浮芸 QQ632069015数据结构课程设计报告一元稀疏多项式计算器、迷宫问题、成绩分析问题、图的基本操作与实现以及背包问题的求解学院(系): 计算机 班 级: 软件工程 4 班 学生姓名: 江志伟 学号 10803080409 指导教师: 时间: 从 2010 年 01 月 11 日到 2010 年 01 月 15 日2一、课程设计概述:本次数据结构课程设计共完成五个题:一元稀疏多项式计算器、迷宫问题、成绩分析问题、图的基本操作与实现以及背包问题的求解使用语言:C编译环境:TC3.0二、课程设计题目一实验内容一元稀疏多项式计算器问题描述设计一个一元稀疏多项式简单计算器。基本要求一元稀疏

2、多项式简单计算器的基本功能是:(1) 输入并建立多项式;(2) 输出多项式,输出形式为整数序列:n,c 1,e1, c2,e2, cn,en,其中 n 是多项式的项数,ci,ei,分别是第 i 项的系数和指数,序列按指数降序排序;(3) 多项式 a 和 b 相加,建立多项式 a+b;(4) 多项式 a 和 b 相减,建立多项式 a-b;(5) 计算多项式在 x 处的值。(6) 计算器的仿真界面。 (选做)概要设计-=ADT=-Test1:主类,程序的启动 Item :项,表示多项式中的某一项Ploynomial:多项式类 存储结构Item 属性:private double c;/系数priv

3、ate int e;/指数Item 方法:public void setC(double c)/设置系数public void setE(int e) /设置指数public double getC()/获取系数3public int getE()/获取指数public double resultItem(double x)/在 x 处 Item 的值private double fac(double x,int e)/求 x 的 e 次方,当 e 为整数时Polynomial 属性:private LinList list;/单链表Polynomial 方法:public Polynomia

4、l()public Polynomial(Item item)throws Exception /构造函数 private void initItem(Item item)/初始化 Item 数组,使其是按降序排序 public int getItemNum()/获取项数 public void print()throws Exception/打印多项式 不空行public void println()throws Exception/打印多项式 空行public LinList getLinList()/获取单链表4public void printPolynomial()throws Ex

5、ception/只打印项数、系数和指数public Polynomial add(Polynomial other)throws Exception/多项式相加public Polynomial subtraction(Polynomial other)throws Exception/多项式相减public double result(double x)throws Exception 详细设计Item 类:public class Item private double c;/系数private int e;/指数public Item()public Item(double c,int

6、e)this.c=c;this.e=e;public void setC(double c)this.c=c;5public void setE(int e)this.e=e;public double getC()return c;public int getE()return e;public double resultItem(double x)return getC()*fac(x,getE();private double fac(double x,int e)/求 x 的 e 次方,当 e 为整数时if(e=0) return 1;return x*fac(x,e-1); Poly

7、nomial 类:import java.util.*;public class Polynomial/多项式类private LinList list;/单链表public Polynomial()list=new LinList(0,null);public Polynomial(Item item)throws Exception /构造函数int n=item.length;list=new LinList(n,null);if(n=0) return;6initItem(item); tryfor(int i=0;iitemmax.getE() max=j;if(max!=i)Ite

8、m temp=itemi;itemi=itemmax;itemmax=temp;public int getItemNum()/获取项数 Object temp=list.head.getElement();int n=-1;if(temp instanceof Integer)Integer i=(Integer)temp;n=i.intValue();return n;public void print()throws Exception/打印多项式 不空行int n=getItemNum();/ System.out.println(n);if(n=-1) return ;if(n=0)

9、7System.out.print(0);return;boolean flag=true;/是不是输出第一项的标志for(int i=0;i0)System.out.print(+c+x+temp.getE(); else if(c=0 & pointrc-1.w=0 & !visitedrc-1 ) return pointrc-1;/向右 即西if(r-1=0 & pointr-1c.w=0 & !visitedr-1c) return pointr-1c;/向上 即北22return null;/连通不到下一个路口public InterSection getNext(InterSec

10、tion p1,InterSection p2)/按顺时针获取的int r1=p1.row;int c1=p1.col;int r2=p2.row;int c2=p2.col;if(r2=0 & pointr2-2c2.w=0)return pointr2-2c2;if(r2-1=0 & c2-1=0 & pointr2-1c2-1.w=0)return pointr2-1c2-1;if(r2=r1 & c1=0 & pointr1c2-2.w=0)return pointr1c2-2; if(c2-1=0 & r1-1=0 & pointr1-1c2-1.w=0)return pointr1

11、-1c2-1;if(r2r1 & c1=c2 & c2-1col )/在该点下方时 if(c2-1=0 & pointr1c2-1.w=0 )return pointr1c2-1;if(r2-2=0 & pointr2-2c2.w=0 )return pointr2-2c2;if(r2-1=0 & c2+1c2 & r2-1col )/在该点左方时if( r2-1=0 & pointr2-1c1.w=0)return pointr2-1c1;23if( c2+2=90,n+9,2);table.setValueAt(countMath4+,n+9,3);table.setValueAt(cou

12、ntEnglish4+,n+9,4);table.setValueAt(countComputer4+,n+9,5);table.setValueAt(,n+10,2);/这是为删除做准备 table.setValueAt(,n+10,3);table.setValueAt(,n+10,4); table.setValueAt(,n+10,5);private void initFile()/初始化文件 即给文件赋值arrayList=new ArrayList();Student temp=new Student(001,王放,78,77,90),new Student(002,张强,89,

13、67,88),new Student(003,李浩,56,66,78),new Student(004,黄小兵,89,86,85),new Student(005,李浩,67,88,76),new Student(006,陈利风,45,54,67),new Student(007,尚晓,78,76,70),;readFile();for(int i=0;isum2) max=j;if(max!=i)Student temp1=(Student)arrayList.get(i);Student temp2=(Student)arrayList.get(max); arrayList.set(i,

14、temp2);arrayList.set(max,temp1); updateTabel(); public void sortMath()/按数学int n=arrayList.size();int i,j,max;for(i=0;isum2) max=j;if(max!=i)39Student temp1=(Student)arrayList.get(i);Student temp2=(Student)arrayList.get(max); arrayList.set(i,temp2);arrayList.set(max,temp1); updateTabel(); public void sortEnglish()/按英语int n=arrayList.size();int i,j,max;for(i=0;isum2) max=j;if(max!=i)Student temp1=(Student)arrayList.get(i);Student temp2=(Student)arrayList.get

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号