1、算法与数据结构程序设计报告1021算法与数据结构设计报告(2013 / 2014 学年 第 二 学期)题 目: 数字组合求和等运算问题、 求多重积分问题 专 业 计算机科学与技术 (信息安全) 学 生 姓 名 张晨磊 班 级 学 号 12001021 指 导 教 师 沙 超 指 导 单 位 计算机学院计算机科学与技术系 日 期 2014.4.21-4.24 评 分 细 则评分项优秀良好中等差遵守机房规章制度上机时的表现学习态度算法思想准备情况程序设计能力解决问题能力课题功能实现情况算法设计合理性算法效能评价报告书写认真程度内容详实程度文字表达熟练程度回答问题准确度简 短 评 语教师签名: 年
2、月 日评分等级备注评分等级有五种:优秀、良好、中等、及格、不及格课题A:数字组合求和等运算问题一、课题内容和要求 用户任意输入两个大于0的数(分别命名k和p),系统根据用户的输入建立数列1,2,3.k,并能够从该数列中取出任意m个数字(mk+1),使得这m个数字的和正好等于p,要求能够将所有符合上述要求的各种可能的数字组合列举出来。(每个数字在每次求和中只能取1次) 实例 输入:5,10 输出:1+2+3+4=10 2+3+5=102、数据结构说明方法:递归1:输入两个数并加以判断2:正确输入后加以运算3:输出所有满足条件的式子3、算法设计 四、详细设计#include #include us
3、ing namespace std;listlist1; void find_factor(int p, int k) int XX=0; if(k = 0 | p= 0) return ; if(p= k) list1.reverse(); for(list:iterator iter = list1.begin(); iter != list1.end();iter+) cout *iter + ; XX+=(*iter); cout k =(XX+k)endl; list1.reverse(); list1.push_front(k); find_factor(p-k, k-1); li
4、st1.pop_front(); find_factor(p, k-1); int main() int p, k; cout 请输入你要等于多少的数值p: 请输入你要从1.k数列中取值的m: p; cink; cout 所有可能的序列,如下: endl; find_factor(k,p); return 0; 5、测试数据及其结果分析结果分析:结果清晰明了,符合题目要求。6、调试过程中的问题1、输入时得按要求进行分部输入,无法按要求“5,10”输入;进行修改后输入变为“5 10”无法加入标点。2、输出无等号如:“1+2+3+4”;修改后得以解决,满足要求。 课题B:求多重积分问题一、课题内容
5、和要求输入待求函数,积分上下限,求出积分结果。具体要求: 1、用户任意输入一个多项式,系统可以处理并求出一重积分(假设积分变量为x)2、用户任意输入一个多项式,系统可以处理并求出二重积分(假设两个积分变量分别为x和y)3、有较为完善的出错处理机制4、设计出简洁易操作的窗口界面二、数据结构说明多项式以链表表示,链表中包含:X的系数a,指数exponentX,Y的系数b,指数exponentY。这些封装在结构体student中。函数:create(void):创建多项式(链表)。函数:print(struct student * head):查看系数和指数。函数:view_polynomial(s
6、truct student * head):输出查看多项式。函数:calculous_df(struct student * head):计算一重积分。函数:calculous_ds(struct student * head):计算二重积分。函数:get_command():获取输入选项。函数:showMenu():查看菜单。函数:main():主函数。3、算法设计四、详细设计#include #include #include #define NULL 0#define LEN sizeof(struct student)struct student float a; int expone
7、ntX; float b; int exponentY; double y_b; / struct student * next;int n;struct student * create(void) struct student * head; struct student * p1,* p2; n=0; p1=p2=(struct student *)malloc(LEN); scanf(%f,%d,%f,%d,&p1-a,&p1-exponentX,&p1-b,&p1-exponentY); head=NULL; while(p1-a!=0&p1-b!=0) n+; if(n=1) he
8、ad=p1; else p2-next=p1; p2=p1; p1=(struct student * )malloc(LEN); scanf(%f,%d,%f,%d,&p1-a,&p1-exponentX,&p1-b,&p1-exponentY); p2-next=NULL; return (head);void print(struct student * head)/查看系数和指数 struct student *p; printf(nNow,These %d records are:n,n); p=head; if(head!=NULL) do printf(%5.1f %5d %5.
9、1f %5dn,p-a,p-exponentX,p-b,p-exponentY); p=p-next; while(p!=NULL);/输出多项式void view_polynomial(struct student * head)/查看系数和指数 struct student *p; printf(nNow,The polynomial is:n); p=head; if(head!=NULL) do if(int)(p-a)=1) printf(X); else printf(%1.1fX,p-a); if(p-exponentX!=1) printf(%d,p-exponentX); i
10、f(int)(p-b)=1) printf(Y); else printf(%4.1fY,p-b); if(p-exponentY!=1) printf(%d,p-exponentY); /printf(%1.1fX%d%4.1fY%d,p-a,p-exponentX,p-b,p-exponentY); p=p-next; if(p!=NULL) printf(+); while(p!=NULL); printf(n);/求积分void calculous_df(struct student * head) float x1,x2; double result1=0.0; double res
11、ult2=0.0; printf(请输入X的积分上下限,用英文“,”隔开:n); scanf(%f,%f,&x1,&x2); / struct student *p; printf(n积分结果:n,n); p=head; if(head!=NULL) do result1+=(p-a) * pow(x1,(p-exponentX)+1)/(p-exponentX+1); result2+=(p-a) * pow(x2,(p-exponentX)+1)/(p-exponentX+1); p=p-next; while(p!=NULL); printf(%0.1fn,result1-result2
12、);void calculous_ds(struct student * head) float x1,x2,y1,y2; double result1=0.0; double result2=0.0; double resultY1=0.0; double resultY2=0.0; printf(请输入X的积分上下限,用英文“,”隔开:n); scanf(%f,%f,&x1,&x2); printf(请输入Y的积分上下限,用英文“,”隔开:n); scanf(%f,%f,&y1,&y2);/ struct student *p,*q; printf(n二重定积分结果:n,n); p=hea
13、d;q=head; /一次遍历,对X求定积分 if(head!=NULL) do result1=(p-a) * pow(x1,(p-exponentX)+1)/(p-exponentX+1); result2=(p-a) * pow(x2,(p-exponentX)+1)/(p-exponentX+1); p-y_b=result1-result2; p=p-next; while(p!=NULL); /对Y求定积分 p=head; if(head!=NULL) do resultY1+=(p-y_b)*(p-b) * pow(y1,(p-exponentY)+1)/(p-exponentY+1); resultY2+=(p-y_b)*(p-b) * pow(y2,(p-exponentY)+1)/(p-exponentY+1);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1