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);