算法与数据结构程序设计报告1021.docx

上传人:b****4 文档编号:2979174 上传时间:2022-11-16 格式:DOCX 页数:14 大小:166.80KB
下载 相关 举报
算法与数据结构程序设计报告1021.docx_第1页
第1页 / 共14页
算法与数据结构程序设计报告1021.docx_第2页
第2页 / 共14页
算法与数据结构程序设计报告1021.docx_第3页
第3页 / 共14页
算法与数据结构程序设计报告1021.docx_第4页
第4页 / 共14页
算法与数据结构程序设计报告1021.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

算法与数据结构程序设计报告1021.docx

《算法与数据结构程序设计报告1021.docx》由会员分享,可在线阅读,更多相关《算法与数据结构程序设计报告1021.docx(14页珍藏版)》请在冰豆网上搜索。

算法与数据结构程序设计报告1021.docx

算法与数据结构程序设计报告1021

 

算法与数据结构设计报告

(2013/2014学年第二学期)

题目:

数字组合求和等运算问题、

求多重积分问题

专业计算机科学与技术(信息安全)

学生姓名张晨磊

班级学号12001021

指导教师沙超

指导单位计算机学院计算机科学与技术系

日期2014.4.21-4.24

评分细则

评分项

优秀

良好

中等

遵守机房规章制度

上机时的表现

学习态度

算法思想准备情况

程序设计能力

解决问题能力

课题功能实现情况

算法设计合理性

算法效能评价

报告书写认真程度

内容详实程度

文字表达熟练程度

回答问题准确度

简短评语

 

教师签名:

年月日

评分等级

备注

评分等级有五种:

优秀、良好、中等、及格、不及格

课题A:

数字组合求和等运算问题

一、课题内容和要求

用户任意输入两个大于0的数(分别命名k和p),系统根据用户的输入建立数列1,2,3......k,并能够从该数列中取出任意m个数字(m

(每个数字在每次求和中只能取1次)

实例——

输入:

5,10

输出:

1+2+3+4=10

2+3+5=10

2、数据结构说明

方法:

递归

1:

输入两个数并加以判断

2:

正确输入后加以运算

3:

输出所有满足条件的式子

3、

算法设计

四、详细设计

#include

#include

usingnamespacestd;

listlist1;

voidfind_factor(intp,intk)

{

intXX=0;

if(k<=0||p<=0)

return;

if(p==k)

{

list1.reverse();

for(list:

:

iteratoriter=list1.begin();iter!

=list1.end();iter++){

cout<<*iter<<"+";

XX+=(*iter);

}

cout<<""<

list1.reverse();

}

list1.push_front(k);

find_factor(p-k,k-1);

list1.pop_front();

find_factor(p,k-1);

}

intmain()

{

intp,k;

cout<<"请输入你要等于多少的数值p:

"<<"请输入你要从1.....k数列中取值的m:

"<

cin>>p;

cin>>k;

cout<<"所有可能的序列,如下:

"<

find_factor(k,p);

return0;

}

5、测试数据及其结果分析

结果分析:

结果清晰明了,符合题目要求。

6、调试过程中的问题

1、输入时得按要求进行分部输入,无法按要求“5,10”输入;进行修改后输入变为“510”无法加入标点。

2、输出无等号如:

“1+2+3+4”;修改后得以解决,满足要求。

课题B:

求多重积分问题

一、课题内容和要求

输入待求函数,积分上下限,求出积分结果。

具体要求:

1、用户任意输入一个多项式,系统可以处理并求出一重积分(假设积分变量为x)

2、用户任意输入一个多项式,系统可以处理并求出二重积分(假设两个积分变量分别为x和y)

3、有较为完善的出错处理机制

4、设计出简洁易操作的窗口界面

二、数据结构说明

多项式以链表表示,链表中包含:

X的系数a,

指数exponentX,

Y的系数b,

指数exponentY。

这些封装在结构体student中。

函数:

create(void):

创建多项式(链表)。

函数:

print(structstudent*head):

查看系数和指数。

函数:

view_polynomial(structstudent*head):

输出查看多项式。

函数:

calculous_df(structstudent*head):

计算一重积分。

函数:

calculous_ds(structstudent*head):

计算二重积分。

函数:

get_command():

获取输入选项。

函数:

showMenu():

查看菜单。

函数:

main():

主函数。

3、

算法设计

四、详细设计

#include

#include

#include

#defineNULL0

#defineLENsizeof(structstudent)

structstudent

{

floata;

intexponentX;

floatb;

intexponentY;

doubley_b;

////

structstudent*next;

};

intn;

structstudent*create(void)

{

structstudent*head;

structstudent*p1,*p2;

n=0;

p1=p2=(structstudent*)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)head=p1;

elsep2->next=p1;

p2=p1;

p1=(structstudent*)malloc(LEN);

scanf("%f,%d,%f,%d",&p1->a,&p1->exponentX,&p1->b,&p1->exponentY);

}

p2->next=NULL;

return(head);

}

voidprint(structstudent*head)//查看系数和指数

{

structstudent*p;

printf("\nNow,These%drecordsare:

\n",n);

p=head;

if(head!

=NULL)

do

{

printf("%5.1f%5d%5.1f%5d\n",p->a,p->exponentX,p->b,p->exponentY);

p=p->next;

}while(p!

=NULL);

}

//输出多项式

voidview_polynomial(structstudent*head)//查看系数和指数

{

structstudent*p;

printf("\nNow,Thepolynomialis:

\n");

p=head;

if(head!

=NULL)

do

{

if((int)(p->a)==1)printf("X");elseprintf("%1.1fX",p->a);

if(p->exponentX!

=1)printf("^%d",p->exponentX);

if((int)(p->b)==1)printf("Y");elseprintf("%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");

}

//求积分

voidcalculous_df(structstudent*head)

{

floatx1,x2;

doubleresult1=0.0;

doubleresult2=0.0;

printf("请输入X的积分上下限,用英文“,”隔开:

\n");

scanf("%f,%f",&x1,&x2);

///////////////////

structstudent*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.1f\n",result1-result2);

}

 

voidcalculous_ds(structstudent*head)

{

floatx1,x2,y1,y2;

doubleresult1=0.0;

doubleresult2=0.0;

doubleresultY1=0.0;

doubleresultY2=0.0;

printf("请输入X的积分上下限,用英文“,”隔开:

\n");

scanf("%f,%f",&x1,&x2);

printf("请输入Y的积分上下限,用英文“,”隔开:

\n");

scanf("%f,%f",&y1,&y2);

///////////////////

structstudent*p,*q;

printf("\n二重定积分结果:

\n",n);

p=head;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