| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 926 人关注过本帖
标题:请解析一个C程序
只看楼主 加入收藏
wangxiaoyu
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-6-29
收藏
 问题点数:0 回复次数:6 
请解析一个C程序

{

YXiPDFJl.txt (5.24 KB) 请解析一个C程序


请大家帮忙解析一下这个程序,是个一元多项式简单计算器.我看不懂啊!急着要交给老师验收啊!
#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)
{
}

 

搜索更多相关主题的帖子: void Polyn 计算器 struct 
2006-06-29 14:41
wangxiaoyu
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-6-29
收藏
得分:0 

一元多项式简单的计算器

1主要功能:

(1)输入并建立多项式;

(2)输出多项式;

(3)两个多项式相加,建立并输出和多项式;

(4)两个多项式相减,建立并输出差多项式。

(5)算法的时间复杂度、另外可以提出算法的改进方法

实现提示:可选择带头结点的单向循环链表或单链表存储多项式,头结点可存放多项式的参数,如项数等。

2.要求:一元多项式简单计算器的基本功能
急啊,高手快进来帮帮忙啊!!!!!!

2006-06-29 14:49
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
收藏
得分:0 
怪事年年有,惟独今年多。

现在有一帮子大学生先上网搜索代码,

再找人补写原理框图和流程图,然后

交到老师那儿去蒙学分。整个一群

小字辈学术腐败分子!!!

但愿哪位高手愿意帮楼主一个忙?

反正俺不会,会也不帮。郁闷!


落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。
2006-06-29 14:59
wangxiaoyu
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-6-29
收藏
得分:0 

我不是为了蒙老师,我是真的想学点东西,请指点迷津啊,拜托,我真的想弄明白!

2006-06-29 15:18
maui2000
Rank: 1
等 级:新手上路
威 望:1
帖 子:113
专家分:0
注 册:2006-5-23
收藏
得分:0 
还没学会走路就急着跑~~
学C可不像学VB
重要的是基础
2006-06-29 16:07
cnch
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-7-10
收藏
得分:0 
现在的学生自己动脑太少。
2006-07-10 11:27
ccjamting
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2006-7-10
收藏
得分:0 

对论坛灰心,以被本人删除。

[此贴子已经被作者于2006-7-31 16:49:26编辑过]


即非出自名门,又系旁门左道,我,就这样笑着。
2006-07-10 15:17
快速回复:请解析一个C程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024019 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved