?? importan.c
字號:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<dos.h>
#include<string.h>
#include<mem.h>
#include<conio.h>
#include<GRAPHICS.H>
#include<time.h>
#define NULL 0
#define N 1000
#define M 1000
int k=0;
char buf[]="E\\DATE.TXT";
struct students
{
int num1;
char name[10];
int chinese1;
int english1;
int math1;
}stu[M];
struct student
{
int mum;
char num[10];
int chinese;
int english;
int math;
float ave;
struct student *next;
}stud[N];
main()
{
struct student *creat();
struct student *SQL();
struct student *del();
struct student *mode();
struct student *insert();
struct student *writeDat(struct student *);
int readDat(struct student *);
void print(struct student *);
int readDat(void);
void print(struct student *)
void average();
void free_lost();
int far getbcolor();
void textbackground();
void textcolor();
void textmode(int mode);
int i;
int j=0;
int m;
struct student *head;
void textbackground(int red);
int far getbcolor(void);
void textcolor(int color);
void textmode(int mode);
time_t td;
putenv("TZ=EST5EDT");
tzset();
time(&td);
printf("current date and time is :%s\n",asctime(localtime(&td)));
m=readDat();
if(m)
{
head=creat(m);
print(head);
}
printf("\nplease choose your chose:\n0.Exit 1 insert 2.Delect 3.findout 4.modefy 5.average 6.free\n");
scanf("%d",&i);
while(i!=0)
{if(i==1)
{head=insert(head);
print(head);
printf("\nplease choose your chose:\n0.exit 1.insert 2.delect 3.findout 4.modefy 5.average 6.free\n");
scanf("%d",&i);
}
if(i==2)
{head=del(head);
print(head);
printf("\nplease choose your chose:\n0.exit.1.insert 2.delect 3.findout 4.modefy 5.average 6.free\n");
scanf("%d",&i);
}
if(i==3)
{head=SQL(head);
print(head);
printf("\nplease choose your chose:\n0.exit 1.insert 2.delect 3.findout 4.modefy 5.average 6.free\n");
scanf("%d",&i);
}
if(i==4)
{head=mode(head);
print(head);
printf("\nplease choose your chose:\n0.exit 1.insert 2.delect 3.findout 4.modefy 5.average 6.free\n");
scanf("%d",&i);
}
if(i==5)
{head=average(head);
print(head);
printf("\nplease choose your chose:\n0.exit 1.insert 2.delect 3.findout 4.modefy 5.average 6.free\n");
scanf("%d",&i);
}
else
if((i!=0)&&(i!=1)(i!=2)&&(i!=3)&&(i!=4)&&(i!=5)%%(i!=6)&&j<3))
{
printf("error choose!!!!!!!\n");
printf("\nplease choose your chose:\n0.exit 1.insert 2.delect 3.findout 4.modefy 5.average 6.free\n");
scanf("%d",&i);
j++;
}
}
head=writeDat(head);
}
struct student *creat(int x)
{
int i;
struct stduent *head,*p,*p1;
head1=stud;
for(p=head1,i=1;p<stud+x;i++)
{
strcpy(p->name,stu->name1);
p->num=stu->num1;
p->chinese=stu->chinese1;
p->english=stu->english1;
P->math=stu->math1;
p1=p;
p->ave=(p->chinese+p->english+p->math)/3.0;
p->next=stud+i;
p=p->next;
}
p1->next=null;
return(head1);
}
struct student *SQL(struct student *head)
{
struct student *p;
int key;
p=head;
printf("\n please input student's number your want to kown:\n");
scanf("%d",%key);
while(p!=null)
{
if(p->num==key)
{printf("\nNUMBER NAME CHINESE ENGLISH MATH AVERAGE\N");
printf("%-10d%-10s %-6.2d %-6.2d %-6.2d %-6.2f\n",p->num,p->name,p->chinese,p->english,p->math,p->ave);
break;
}
else
p=p->next;
}
if(p==null)
printf("\n DON'T HAVE SUCH A STUDENT!!\N");
retrun(head);
}
struct stedent *del(struct stduent *head)
{
struct student *p,*back;
int key;
p=head;
printf("\nplease input student's number you want to delect:/n");
scanf("%d",&key);
while(key!=0)
{
if(p->next==NULL)
{printf("\nDON'T FOUND!!");break;}
if(head->num==key)
{head=p->next;
free(p);
break;
}
back=p;
p=p->nxet;
if(p->num==key)
{back->next=p->next;
free(p);break;}
}
return(head);
}
struct student *mode(struct student *head)
{
struct student *p;
int key;
p=head;
printf("\nplease input student's number you want to modefy:\n");
scanf("%d",&key);
while(p!=NULL)
{
if(p->num==key)
{
printf("\nplease input student's old name or new name:\n");
scanf("%s",p->name);
printf("\nplease input student's chinese score(0~100):\n");
scanf("%d",&p->chinese);
while(p->chinese>100||p->chinese<0)
{printf("\n ERROR!!!\nplease input student's chinese score(0~100):\n);
scanf("%d",&p->chinese);
}
printf("\nplease input student's new english score(0~100):\n");
scanf("%d",&p->english);
while(p->english>100||p->english<0)
{printf("ERROR!!!\nplease input student's english score(0~100):\n);
scanf("%d",&p->english);
}
printf("\nplease input student's new math score(0~100):\n);
scanf("%d",&p->math);
while(p->math>100||p->math<0)
{printf("\nERROR!!!\nplease input student's math score(0~100):\n");
scanf("%d",&=->math);
}
p->ave=(p->chinese+p->english+p->math)/3.0;
break;
}
else
p=p->next;
if(p->next==NULL)
{printf("\nDON'T HAVE such a student!!\n");
break;
}
}
return(head);
}
struct student *insert(struct student *head)
{
struct student *p,*newstudent;
p=head;
newstudent=(struct student *malloc(sizeof(struct student));
printf("\nplease input newstudent's number:");
scanf("%d",&newstudent->num);
while(p!=NULL)
{
while(newstudent->num==p->num)
{printf("\nthese has been such a student,please input another:");
scanf("%d",*newstudent->num);
}
p=p->next;
}
printf("\nplease input newstudent's name:");
scanf("%s",newstudent->name);
printf("\nplease input student's chinese score(0~100):\n");
scanf("%d",&newstudent->chinese);
while(newstudent->chinese>100||newstudent->chinese<0)
{printf("\nERROR!!!\nplease input student's chinese score(0~100):\n");
scanf("%d",&newstudnet->chinese);
}
printf("\nplese input student's new english score(0~100):\n");
scanf("%d",&newsstudnet->english);
while(newstudent->english>100||newstudeht->english<0)
{printf("\nERROR!!!!\nplease input student's english score(0~100):\n");
scanf("%d",&newstudent->english);
}
printf("\nplease input student's new math score(0~100):\n);
scanf("%d",&newstudent->math);
while(newstudeht->math>100||newstudent->math<0)
{printf("\nERROR!!!\nplease input student's math score:\n");
scanf("%d",*newstudent->math);
}
newstudent->ave=(newstudent->chinese+newstudent->english+newstudent->math)/3.0;
p=head;
if(head->num>newstudent->num)
{newstudent_>next=head;
head=newstudent;
}
else
while(p!=NULL)
{if((p->num<newstudent->num&&newstudent->num<p->next)||p->next==NULL)
{newstudent->next=p->next;
p->next=newstudent;
break;
}
p=p->next;
}
}
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("\nNUMBER NAME CHINESE MATH AVERAGE\N");
p=head;
if(p!=NULL)
{do
{printf("%-10d%-10s%-6.2d %-6.2d %-6.2d %-6.2f\n",p->num,p->name,p->chinese,p->english,p->math,p->ave);
p=p->next;
}
while(p!=NULL)
}
void average(struct student *head)
{
int j;
float sum;
struct student *p;
p=head;
for(j=0,sum=0;p->next!=NULL;j++)
{
sum+=p->ave;
p=p->next;
free(p);
}
}
struct student *writeDat(struct student *head)
{
FILE *fp;
struct student *p;
char savefile[10];
p=head;
if((fp=fopen(buf,"w"))==NULL)
{printf("\ncan't open the DATE file!!\n");
exit(0);
}
while(p!=NULL)
{fprintf(fp,"%-10d%-10s%-6.2d %-6.2d %-6.2d %-6.2f\n",p->num,p->name,p->chinese,p->english,p->math,p->ave);
p=p->next;
}
fclose(fp);
return(head);
}
int readDat(void)
{FILE *fp;
if((fp=fopen(buf,"a"))==NULL)
{
printf("\ncann't open savefile \n");
exit(0);
}
else
while(!feof(fp))
{fread(&stu[k],sizeof(struct student),1,fp);
k++;
}
fclose(fp);
return(k);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -