{
请大家帮忙解析一下这个程序,是个一元多项式简单计算器.我看不懂啊!急着要交给老师验收啊!
#include "stdio.h"
#include "conio.h"
#include <stdlib.H>
struct Polynomial
{struct Polynomial *next;
float xi;
int zhi;
};
typedef struct Polynomial Poly;
typedef struct Polynomial * Polyn;
void CreatPolyn(Polyn *);
void DestroyPoln(Polyn *);
void PrintPolyn(Polyn *);
void AddPolyn(Polyn *);
void PolynLength(Polyn *);
void SubtractPolyn(Polyn *);
void MultiplyPolyn(Polyn *);
main()
{Polyn p=NULL;int a;
while(1)
{printf("\nEnter a choice\n");
printf("0:exit\n1:CreatPolyn\n2:DestroyPoln;\n3:PrintPolyn;\n4:PolynLength;\n");
printf("5:AddPolyn;\n6:SubtractPolyn;\n7:MultiplyPolyn;\n");
scanf("%d",&a);
switch(a)
{case 0:exit(0);
case 1:CreatPolyn(&p);break;
case 2:DestroyPoln(&p);break;
case 3:PrintPolyn(&p);break;
case 4:PolynLength(&p);break;
case 5:AddPolyn(&p);break;
case 6:SubtractPolyn(&p);break;
case 7:MultiplyPolyn(&p);break;
}
}}
void CreatPolyn(Polyn *pt)
{int a,b,c,zhi;Polyn s,l,k,p;char ss[20];FILE *file; float xi;
printf("0:return,1:Enter use keyboard,2:Enter use file\n");
scanf("%d",&a);
s=malloc(sizeof(Poly));
s->next=NULL;
*pt=s;k=s->next;p=s;
switch(a)
{case 1:printf("Enter the number of note\n");
scanf("%d",&b);
for(c=1;c<=b;c++)
{l=malloc(sizeof(Poly));
printf("\nEnter xishu&&zhishu\n");
scanf("%f%d",&l->xi,&l->zhi);
s=p;k=s->next;
while(k&&k->zhi<l->zhi)
{k=k->next;s=s->next;}
if(k->zhi==l->zhi)
{k->xi+=l->xi;
if(k->xi==0)
{s->next=k->next;free(k);}
free(l);
}
else
{l->next=k;s->next=l;}
}
break;
case 2:printf("Enter file name\n");
scanf("%s",ss);
if((file=fopen(ss,"rt"))==NULL)
{printf("file could not been opened\n");return;}
fscanf(file,"%f,%d;",&xi,&zhi);
while(!feof(file))
{l=malloc(sizeof(Poly));
l->xi=xi;l->zhi=zhi;
s=p;k=s->next;
while(k&&k->zhi<l->zhi)
{k=k->next;s=s->next;}
if(k->zhi==l->zhi)
{k->xi+=l->xi;
if(k->xi==0)
{s->next=k->next;free(k);}
free(l);
}
else
{l->next=k;s->next=l;}
fscanf(file,"%f,%d;",&xi,&zhi);
}break;
case 0:return;
}
printf("Polyn has been created\n");
}
void DestroyPoln(Polyn *p)
{Polyn s,l;
l=s=*p;
if(s==NULL)
{printf("Polyn has been destroyed\n");return;}
else
{ do
{l=s->next;
free(s);
s=l;
}while(l);
}
*p=NULL;
printf("Polyn has been destroyed\n");
}
void PrintPolyn(Polyn *p)
{Polyn s;int a;
s=*p;
if(s==NULL) {printf("Polyn is not extend\n");return;}
if(s->next==NULL){printf("Polyn is NULL\n");return;}
s=s->next;
printf("xishu zhishu\n");
for(a=1;s;a++,s=s->next)
{printf("%-16f%d\n",s->xi,s->zhi);
if(a%10==0){printf("Enter anykey to continue\n");getch();}
}
}
void AddPolyn(Polyn *p)
{int a,b,c,zhi;Polyn s,l,k;FILE *file;char ss[20];float xi;
s=*p;k=s->next;
printf("0:return,1:Enter use keyboard,2:Enter use file\n");
scanf("%d",&a);
switch(a)
{case 1:l=malloc(sizeof(Poly));
printf("\nEnter xishu&&zhishu\n");
scanf("%f%d",&l->xi,&l->zhi);
while(k&&k->zhi<l->zhi)
{k=k->next;s=s->next;}
if(k->zhi==l->zhi)
{k->xi+=l->xi;
if(k->xi==0)
{s->next=k->next;free(k);}
free(l);
}
else
{l->next=k;s->next=l;}
break;
case 2:printf("Enter file name\n");
scanf("%s",ss);
if((file=fopen(ss,"rt"))==NULL)
{printf("file could not been opened\n");return;}
fscanf(file,"%f,%d;",&xi,&zhi);
while(!feof(file))
{l=malloc(sizeof(Poly));
l->zhi=zhi;l->xi=xi;
s=*p;k=s->next;
while(k&&k->zhi<l->zhi)
{k=k->next;s=s->next;}
if(k->zhi==l->zhi)
{k->xi+=l->xi;
if(k->xi<0.00000001)
{s->next=k->next;free(k);}
free(l);
}
else
{l->next=k;s->next=l;}
fscanf(file,"%f,%d;",&xi,&zhi);
}
break;
case 0:return;
}
}
void PolynLength(Polyn *p)
{Polyn s;int a;
s=*p;
if(s==NULL) {printf("Polyn is not extend\n");return;}
if(s->next==NULL){printf("Polyn is NULL\n");return;}
s=s->next;
for(a=0;s;a++)
s=s->next;
printf("\nPolyn Length is %d\n",a);
}
void SubtractPolyn(Polyn *p)
{Polyn s=*p,l,k,x;
CreatPolyn(&k);
l=s;
s=s->next;
x=k->next;free(k);k=x;x=x->next;
while(s&&k)
{while(s->zhi<k->zhi)
{l=l->next;s=s->next;}
if(s->zhi==k->zhi)
{s->xi+=k->xi;
free(k);k=x;x=x->next;
if(s->xi<0.0000001)
{l->next=s->next;
free(s);
s=l->next;
}
}
else if(s->zhi>k->zhi)
{k->next=s;l->next=k;s=k;
k=x;x=x->next;
}
}
if(s==NULL)l->next=k;
}
void MultiplyPolyn(Polyn *p)
{
}
----------------解决方案--------------------------------------------------------
一元多项式简单的计算器
1主要功能:
(1)输入并建立多项式;
(2)输出多项式;
(3)两个多项式相加,建立并输出和多项式;
(4)两个多项式相减,建立并输出差多项式。
(5)算法的时间复杂度、另外可以提出算法的改进方法
实现提示:可选择带头结点的单向循环链表或单链表存储多项式,头结点可存放多项式的参数,如项数等。
2.要求:一元多项式简单计算器的基本功能
急啊,高手快进来帮帮忙啊!!!!!!
----------------解决方案--------------------------------------------------------
怪事年年有,惟独今年多。
现在有一帮子大学生先上网搜索代码,
再找人补写原理框图和流程图,然后
交到老师那儿去蒙学分。整个一群
小字辈学术腐败分子!!!
但愿哪位高手愿意帮楼主一个忙?
反正俺不会,会也不帮。郁闷!
----------------解决方案--------------------------------------------------------
我不是为了蒙老师,我是真的想学点东西,请指点迷津啊,拜托,我真的想弄明白!
----------------解决方案--------------------------------------------------------
还没学会走路就急着跑~~
学C可不像学VB
重要的是基础
----------------解决方案--------------------------------------------------------
现在的学生自己动脑太少。
----------------解决方案--------------------------------------------------------
对论坛灰心,以被本人删除。
[此贴子已经被作者于2006-7-31 16:49:26编辑过]
----------------解决方案--------------------------------------------------------