| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 488 人关注过本帖
标题:我的错该怎么改?我还要这个程序的流程图!谢谢!
只看楼主 加入收藏
bryanzhong
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-6-20
收藏
 问题点数:0 回复次数:2 
我的错该怎么改?我还要这个程序的流程图!谢谢!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <mem.h>
#include <ctype.h>
#include <alloc.h>
#define N 3
typedef struct z1
{
char number[11];
char name[15];
char sex[10];
int score[N];
float sum;
float average;
int order;
struct z1 *next;
}STUDENT;

STUDENT *init();
STUDENT *create();
STUDENT *delete(STUDENT *h);
void print(STUDENT *h);
void search(STUDENT *h);
void save(STUDENT *h);
STUDENT *load();
void computer(STUDENT *h);
STUDENT *insert(STUDENT *h);
void append();
void copy();
STUDENT *sort(STUDENT *h);
STUDENT *index(STUDENT *h);
void total(STUDENT *h);
int menu_select();

main()
{
int i;
STUDENT *head;
head=init();
clrscr();
for(;;)
{
switch(menu_select())
{
case 0:head=init();break;
case 1:head=create();break;
case 2:head=delete(head);break;
case 3:print(head);break;
case 4:search(head);break;
case 5:save(head);break;
case 6:head=load(); break;
case 7:computer(head);break;
case 8:head=insert(head); break;
case 9:copy();break;
case 10:head=sort(head);break;
case 11:append();break;
case 12:head=index(head);break;
case 13:total(head);break;
case 14:exit(0);
}
}
}

menu_select()
{
char *menu[]={"***************MENU***************",
" 0. init list", " 1. Enter list",
" 2. Delete a record from list",
" 3. print list ",
" 4. Search record on name",
" 5. Save the file",
" 6. Load the file",
" 7. compute the score",
" 8. insert record to list ",
" 9. copy the file to new file",
" 10. sort to make new file",
" 11. append record to file",
" 12. index on numbermber",
" 13. total on numbermber",
" 14. Quit"};
char s[3];
int c,i;
gotoxy(1,25);
printf("press any key enter menu......\n");
getch();
clrscr();
gotoxy(1,1);
textcolor(YELLOW);
textbackground(BLUE);
gotoxy(10,2);
putch(0xc9);
for(i=1;i<44;i++)
putch(0xcd);
putch(0xbb);
for(i=3;i<20;i++)
{
gotoxy(10,i);putch(0xba);
gotoxy(54,i);putch(0xba);
}
gotoxy(10,20);putch(0xc8);
for(i=1;i<44;i++)
putch(0xcd);
putch(0xbc);
window(11,3,53,19);
clrscr();
for(i=0;i<16;i++)
{
gotoxy(10,i+1);
cprintf("%s",menu[i]);
}
textbackground(BLACK);
window(1,1,80,25);
gotoxy(10,21);
do{
printf("\n Enter you choice(0~14):");
scanf("%s",s);
c=atoi(s);
}while(c<0||c>14);
return c;
}
STUDENT *init()
{
return NULL;
}

STUDENT *create()
{
int i; int s;
STUDENT *h=NULL,*info;
for(;;)
{
info=(STUDENT *)malloc(sizeof(STUDENT));
if(!info)
{
printf("\numberut of memory");
return NULL;
}
inputs("enter number:",info->number,11);
if(info->number[0]=='@') break;
inputs("enter name:",info->name,15);
inputs("enter sex:",info->sex,10);
printf("please input %d score \n",N);
s=0;
for(i=0;i<N;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&info->score[i]);
if(info->score[i]>100||info->score[i]<0)
printf("bad data,repeat input\n");
}while(info->score[i]>100||info->score[i]<0);
s=s+info->score[i];
}
info->sum=s;
info->average=(float)s/N;
info->order=0;
info->next=h;
h=info;
}
return(h);
}
inputs(char *prompt, char *s, int count)
{
char p[255];
do{
printf(prompt);
scanf("%s",p);
if(strlen(p)>count)printf("\n too long! \n");
}while(strlen(p)>count);
strcpy(s,p);
}
void print(STUDENT *h)
{
int i=0;
STUDENT *p;
clrscr();
p=h;
printf("\n\n\n****************************STUDENT********************************\n");
printf("|rec| number | name |sex | c++ score| vb score| average score | total score |order|\n");
printf("|---|-----------------------|-----------------------|----------|-------------|-------------|--------------------------|---------------|------|\n");
while(p!=NULL)
{
i++;
printf("|%3d |%-10s|%-15s|%-10s|%4d|%4d| %4.2f | %4.2f | %3d |\n", i, p->number,p->name,p->sex.,p->score[0],p->score[1],
p->score[2],p->sum,p->average, p->order);
p=p->next;
}
printf("**********************************end*********************************\n");
}
STUDENT *delete(STUDENT *h)
{
STUDENT *p,*q;
char s[11];
clrscr();
printf("please deleted number\n");
scanf("%s",s);
q=p=h;
while(strcmp(p->number,s)&&p!=NULL)
{
q=p;
p=p->next;
}
if(p==NULL)
printf("\nlist number %s student\n",s);
else
{
printf("*****************************have found***************************\n");
printf("|number | name | sc1| sc2| sc3| sum | ave |order|\n");
printf("|----------|---------------|----|----|----|--------|-------|-----|\n");
printf("|%-10s|%-15s|%4d|%4d|%4d| %4.2f | %4.2f | %3d |\n", p->number,
p->name,p->score[0],p->score[1],p->score[2],p->sum,
p->average,p->order);
printf("********************************end*******************************\n");
getch();
if(p==h)
h=p->next;
else
q->next=p->next;
free(p);
printf("\n have deleted Number %s student\n",s);
printf("Don't forget save\n");
}
return(h);
}
void search(STUDENT *h)
{
STUDENT *p;
char s[15];
clrscr();
printf("please enter name for search\n");
scanf("%s",s);
p=h;
while(strcmp(p->name,s)&&p!=NULL)
p=p->next;
if(p==NULL)
printf("\nlist number %s student\n",s);
else
{
printf("\n\n*****************************havefound***************************\n");
printf("|number | name | sc1| sc2| sc3| sum | ave |order|\n");
printf("|----------|---------------|----|----|----|--------|-------|-----|\n");
printf("|%-10s|%-15s|%4d|%4d|%4d| %4.2f | %4.2f | %3d |\n", p->number,
p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("********************************end*******************************\n");
}
}
STUDENT *insert(STUDENT *h)
{
STUDENT *p,*q,*info;
char s[11];
int s1,i;
printf("please enter location before the number\n");
scanf("%s",s); printf("\nplease new record\n");
info=(STUDENT *)malloc(sizeof(STUDENT));
if(!info)
{
printf("\numberut of memory");
return NULL;
}
inputs("enter number:",info->number,11);
inputs("enter name:",info->name,15);
printf("please input %d score \n",N);
s1=0;
for(i=0;i<N;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&info->score[i]);
if(info->score[i]>100||info->score[i]<0)
printf("bad data,repeat input\n");
}while(info->score[i]>100||info->score[i]<0);
s1=s1+info->score[i];
}
info->sum=s1;
info->average=(float)s1/N;
info->order=0;
info->next=NULL;
p=h;
q=h;
while(strcmp(p->number,s)&&p!=NULL)
{
q=p;
p=p->next;
}
if(p==NULL)
if(p==h)
h=info;
else
q->next=info;
else
if(p==h)
{
info->next=p;
h=info;
}
else
{
info->next=p;
q->next=info;
}
printf("\n ----have inserted %s student----\n",info->name);
printf("---Don't forget save---\n");
return(h);
}
void save(STUDENT *h)
{
FILE *fp;
STUDENT *p;
char outfile[10];
printf("Enter outfile name,for example c:\\f1\\te.txt:\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"wb"))==NULL)
{
printf("can numbert open file\n");
exit(1);
}
printf("\nSaving file......\n");
p=h;
while(p!=NULL)
{
fwrite(p,sizeof(STUDENT),1,fp);
p=p->next;
}
fclose(fp);
printf("-----save success!!-----\n");
}
STUDENT *load()
{
STUDENT *p,*q,*h=NULL;
FILE *fp;
char infile[10];
printf("Enter infile name,for example c:\\f1\\te.txt:\n");
scanf("%s",infile);
if((fp=fopen(infile,"rb"))==NULL)
{
printf("can numbert open file\n");
exit(1);
}
printf("\n -----Loading file!-----\n");
p=(STUDENT *)malloc(sizeof(STUDENT));
if(!p)
{
printf("out of memory!\n");
return h;
}
h=p;
while(!feof(fp))
{
if(1!=fread(p,sizeof(STUDENT),1,fp))
break;
p->next=(STUDENT *)malloc(sizeof(STUDENT));
if(!p->next)
{
printf("out of memory!\n");
return h;
}
q=p;
p=p->next;
}
q->next=NULL;
fclose(fp);
printf("---You have success read data from file!!!---\n");
return h;
}
void append()
{
FILE *fp;
STUDENT *info; /*新记录指针*/
int s1,i;
char infile[10];
printf("\nplease new record\n");
info=(STUDENT *)malloc(sizeof(STUDENT));
if(!info)
{
printf("\numberut of memory");
return ;
}
inputs("enter number:",info->number,11);
inputs("enter name:",info->name,15);
printf("please input %d score \n",N);
s1=0;
for(i=0;i<N;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&info->score[i]);
if(info->score[i]>100||info->score[i]<0)printf("bad data,repeat input\n");
}while(info->score[i]>100||info->score[i]<0);
s1=s1+info->score[i];
}
info->sum=s1;
info->average=(float)s1/N;
info->order=0;
info->next=NULL;
printf("Enter infile name,for example c:\\f1\\te.txt:\n");
scanf("%s",infile);
if((fp=fopen(infile,"ab"))==NULL)
{
printf("can numbert open file\n");
exit(1);
}
printf("\n -----Appending record!-----\n");
if(1!=fwrite(info,sizeof(STUDENT),1,fp))
{
printf("-----file write error!-----\n");
return;
}
printf("-----append sucess!!----\n");
fclose(fp);
}
void copy()
{
char outfile[10],infile[10];
FILE *sfp,*tfp;
STUDENT *p=NULL;
clrscr();
printf("Enter infile name,for example c:\\f1\\te.txt:\n");
scanf("%s",infile);
if((sfp=fopen(infile,"rb"))==NULL)
{
printf("can numbert open input file\n");
exit(0);
}
printf("Enter outfile name,for example c:\\f1\\te.txt:\n");
scanf("%s",outfile);
if((tfp=fopen(outfile,"wb"))==NULL)
{
printf("can numbert open output file \n");
exit(0);
}
while(!feof(sfp))
{
if(1!=fread(p,sizeof(STUDENT),1,sfp))
break;
fwrite(p,sizeof(STUDENT),1,tfp);
}
fclose(sfp);
fclose(tfp);
printf("you have success copy file!!!\n");
}
STUDENT *sort(STUDENT *h)
{
int i=0;
STUDENT *p,*q,*t,*h1;
h1=h->next;
h->next=NULL;
while(h1!=NULL)
{
t=h1;
h1=h1->next;
p=h;
q=h;
while(t->sum<p->sum&&p!=NULL)
{
q=p;
p=p->next;
}
if(p==q)
{
t->next=p;
h=t;
}
else
{
t->next=p;
q->next=t;
}
}
p=h;
while(p!=NULL)
{
i++;
p->order=i;
p=p->next;
}
printf("sort sucess!!!\n");
return h;
}
void computer(STUDENT *h)
{
STUDENT *p;
int i=0;
long s=0;
float average=0;
p=h;
while(p!=NULL)
{
s+=p->sum; /
i++;
p=p->next;
}
average=(float)s/i;
printf("\n--All students sum score is:%ld average is %5.2f\n",s,average);
}
STUDENT *index(STUDENT *h)
{
STUDENT *p,*q,*t,*h1;
h1=h->next;
h->next=NULL;
while(h1!=NULL)
{
t=h1;
h1=h1->next;
p=h;
q=h;
while(strcmp(t->number,p->number)>0&&p!=NULL)
{
q=p;
p=p->next;
}
if(p==q)
{
t->next=p;
h=t;
}
else
{
t->next=p;
q->next=t;
}
}
printf("index sucess!!!\n");
return h;
}
void total(STUDENT *h)
{
STUDENT *p,*q;
char snumber[9],qnumber[9],*ptr;
float s1,ave;
int i;
clrscr();
printf("\n\n *******************Total*****************\n");
printf("---class---------sum--------------average----\n");
p=h;
while(p!=NULL)
{
memcpy(snumber,p->number,8);
snumber[8]='\0';
q=p->next;
s1=p->sum;
ave=p->average;
i=1;
while(q!=NULL)
{
memcpy(qnumber,q->number,8);
qnumber[8]='\0';
if(strcmp(qnumber,snumber)==0)
{
s1+=q->sum;
ave+=q->average;
i++;
q=q->next;
else
break; }
printf("%s %10.2f %5.2f\n",snumber,s1,ave/i);
if(q==NULL)
break; else
p=q;
}
printf("---------------------------------------------\n");
}

搜索更多相关主题的帖子: 流程图 
2006-06-20 19:48
x5471140
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-6-19
收藏
得分:0 
基本上没有注释,怎么改?
2006-06-20 21:38
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
收藏
得分:0 
以下是引用x5471140在2006-6-20 21:38:45的发言:
基本上没有注释,怎么改?

很可能根本就是抄来的,哪有什么注解?
道高一尺、魔高一丈。老师要求画流程图!


落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。
2006-06-20 21:45
快速回复:我的错该怎么改?我还要这个程序的流程图!谢谢!
数据加载中...
 
   



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

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