當前位置:首頁 » 考試成績 » c代碼學生成績管理系統

c代碼學生成績管理系統

發布時間: 2021-02-22 01:23:16

學生成績管理系統c語言代碼

這個成績統計系統,不是1個小時就能寫完的。要佔用回答者數小時時間,不多給點金幣?或是其它的?

⑵ C語言程序設計學生成績管理系統

#include
"stdio.h"
/*定義學生結構體*/
struct
Student
{
char
ID[20];
char
Name[20];
float
Mark1;
float
Mark2;
float
Mark3;
float
Average;
};
/*聲明學生數組及學生數量*/
struct
Student
students[1000];
int
num=0;
/*求平均值*/
float
Avg(struct
Student
stu)
{
return
(stu.Mark1+stu.Mark2+stu.Mark3)/3;
}
/*通過學號返回數組下標*/
int
Student_SearchByIndex(char
id[])
{
int
i;
for
(i=0;i<num;i++)
{
if
(strcmp(students[i].ID,id)==0)
{
return
i;
}
}
return
-1;
}
/*通過姓名返回數組下標*/
int
Student_SearchByName(char
name[])
{
int
i;
for
(i=0;i<num;i++)
{
if
(strcmp(students[i].Name,name)==0)
{
return
i;
}
}
return
-1;
}
/*顯示單條學生記錄*/
void
Student_DisplaySingle(int
index)
{
printf("%10s%10s%8s%8s%8s%10s\n","學號","姓名","成績","成績","成績","平均成績");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[index].ID,students[index].Name,
students[index].Mark1,students[index].Mark2,students[index].Mark3,students[index].Average);
}
/*插入學生信息*/
void
Student_Insert()
{
while(1)
{
printf("請輸入學號:");
scanf("%s",&students[num].ID);
getchar();
printf("請輸入姓名:");
scanf("%s",&students[num].Name);
getchar();
printf("請輸入成績:");
scanf("%f",&students[num].Mark1);
getchar();
printf("請輸入成績:");
scanf("%f",&students[num].Mark2);
getchar();
printf("請輸入成績:");
scanf("%f",&students[num].Mark3);
getchar();
students[num].Average=Avg(students[num]);
num++;
printf("是否繼續?(y/n)");
if
(getchar()=='n')
{
break;
}
}
}
/*修改學生信息*/
void
Student_Modify()
{
float
mark1,mark2,mark3;
while(1)
{
char
id[20];
int
index;
printf("請輸入要修改的學生的學號:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if
(index==-1)
{
printf("學生不存在!\n");
}
else
{
printf("你要修改的學生信息為:\n");
Student_DisplaySingle(index);
printf("--
請輸入新值--\n");
printf("請輸入學號:");
scanf("%s",&students[index].ID);
getchar();
printf("請輸入姓名:");
scanf("%s",&students[index].Name);
getchar();
printf("請輸入成績:");
scanf("%f",&students[index].Mark1);
getchar();
printf("請輸入成績:");
scanf("%f",&students[index].Mark2);
getchar();
printf("請輸入成績:");
scanf("%f",&students[index].Mark3);
getchar();
students[index].Average=Avg(students[index]);
}
printf("是否繼續?(y/n)");
if
(getchar()=='n')
{
break;
}
}
}
/*刪除學生信息*/
void
Student_Delete()
{
int
i;
while(1)
{
char
id[20];
int
index;
printf("請輸入要刪除的學生的學號:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if
(index==-1)
{
printf("學生不存在!\n");
}
else
{
printf("你要刪除的學生信息為:\n");
Student_DisplaySingle(index);
printf("是否真的要刪除?(y/n)");
if
(getchar()=='y')
{
for
(i=index;i<num-1;i++)
{
students[i]=students[i+1];
}
num--;
}
getchar();
}
printf("是否繼續?(y/n)");
if
(getchar()=='n')
{
break;
}
}
}
/*按姓名查詢*/
void
Student_Select()
{
while(1)
{
char
name[20];
int
index;
printf("請輸入要查詢的學生的姓名:");
scanf("%s",&name);
getchar();
index=Student_SearchByName(name);
if
(index==-1)
{
printf("學生不存在!\n");
}
else
{
printf("你要查詢的學生信息為:\n");
Student_DisplaySingle(index);
}
printf("是否繼續?(y/n)");
if
(getchar()=='n')
{
break;
}
}
}
/*按平均值排序*/
void
Student_SortByAverage()
{
int
i,j;
struct
Student
tmp;
for
(i=0;i<num;i++)
{
for
(j=1;j<num-i;j++)
{
if
(students[j-1].Average<students[j].Average)
{
tmp=students[j-1];
students[j-1]=students[j];
students[j]=tmp;
}
}
}
}
/*顯示學生信息*/
void
Student_Display()
{
int
i;
printf("%10s%10s%8s%8s%8s%10s\n","學號","姓名","成績","成績","成績","平均成績");
printf("-------------------------------------------------------------\n");
for
(i=0;i<num;i++)
{
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[i].ID,students[i].Name,
students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Average);
}
}
/*將學生信息從文件讀出*/
void
IO_ReadInfo()
{
FILE
*fp;
int
i;
if
((fp=fopen("Database.txt","rb"))==NULL)
{
printf("不能打開文件!\n");
return;
}
if
(fread(&num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;i<num;i++)
{
fread(&students[i],sizeof(struct
Student),1,fp);
}
}
fclose(fp);
}
/*將學生信息寫入文件*/
void
IO_WriteInfo()
{
FILE
*fp;
int
i;
if
((fp=fopen("Database.txt","wb"))==NULL)
{
printf("不能打開文件!\n");
return;
}
if
(fwrite(&num,sizeof(int),1,fp)!=1)
{
printf("寫入文件錯誤!\n");
}
for
(i=0;i<num;i++)
{
if
(fwrite(&students[i],sizeof(struct
Student),1,fp)!=1)
{
printf("寫入文件錯誤!\n");
}
}
fclose(fp);
}
/*主程序*/
main()
{
int
choice;
IO_ReadInfo();
while(1)
{
/*主菜單*/
printf("\n------
學生成績管理系統------\n");
printf("1.
增加學生記錄\n");
printf("2.
修改學生記錄\n");
printf("3.
刪除學生記錄\n");
printf("4.
按姓名查詢學生記錄\n");
printf("5.
按平均成績排序\n");
printf("6.
退出\n");
printf("請選擇(1-6):");
scanf("%d",&choice);
getchar();
switch(choice)
{
case
1:
Student_Insert();
break;
case
2:
Student_Modify();
break;
case
3:
Student_Delete();
break;
case
4:
Student_Select();
break;
case
5:
Student_SortByAverage();
Student_Display();
break;
case
6:
exit();
break;
}
IO_WriteInfo();
}
}
你的串號我已經記下,採納後我會幫你製作

⑶ C語言編寫一個簡單的學生成績管理系統

C語言程序:

#include<stdio.h>
#include<string.h>

typedefstructstudent
{
charname[20]; /*姓名*/
intcode; /*學號*/
intkor,eng,math; /*3門課程的成績*/
}STUDENT;

/*返回輸入數據*/
STUDENTInput();

/*輸出所有輸入的數據*/
voidOutput(STUDENTinfo[],intcnt);

/*將輸入分數轉換為A-F*/
chargrade(intscore);

intmain()
{
STUDENTS[10];
intcnt=0,select;
inti,j;
intcode;

while(1)
{
printf(" 學生信息管理系統 ");
printf(" 1 添加 ");
printf(" 2 刪除 ");
printf(" 3 查詢 ");
printf(" 0 結束 ");
printf(" 您的選擇[0-3]:");
scanf("%d",&select);

if(select<0||select>3)
continue;
if(select==0)
{
printf("退出系統! ");
break;
}

if(select==1) /*添加*/
{
S[cnt++]=Input();
}
elseif(select==2) /*刪除*/
{
printf(" 待刪除學生的學號:");
scanf("%d",&code);

for(i=0;i<cnt;i++)
if(S[i].code==code)
break;
if(i>=cnt)
{
printf("學號不存在,刪除失敗! ");
}
else{
for(j=i+1;j<cnt;j++)
{
strcpy(S[j-1].name,S[j].name);
S[j-1].code=S[j].code;
S[j-1].kor=S[j].kor;
S[j-1].eng=S[j].eng;
S[j-1].math=S[j].math;
}
cnt--;
printf("刪除成功! ");
}
}
else /*查詢*/
{
printf(" 待查找學生的學號:");
scanf("%d",&code);

for(i=0;i<cnt;i++)
if(S[i].code==code)
break;
if(i>=cnt)
{
printf("學號不存在,查找失敗! ");
}
else
{
printf(" 查詢結果: ");
Output(S,i);
}
}
}

return0;
}

/*返回輸入數據*/
STUDENTInput()
{
STUDENTstu;
printf(" 新學生信息 ");
printf(" 學號:");
scanf("%d",&stu.code);
printf(" 姓名:");
getchar();
gets(stu.name);
printf(" 3門課程成績(以空格分隔):");
scanf("%d%d%d",&stu.kor,&stu.eng,&stu.math);

returnstu;
}

/*輸出所有輸入的數據*/
voidOutput(STUDENTinfo[],intcnt)
{
printf("學號:%d ",info[cnt].code);
printf("姓名:");
puts(info[cnt].name);
printf("成績:%c%c%c ",grade(info[cnt].kor),grade(info[cnt].eng),grade(info[cnt].math));
}

/*將輸入分數轉換為A-F*/
chargrade(intscore)
{
if(score<0||score>100)
return'F';
if(score>=90)
return'A';
if(score>=80)
return'B';
if(score>=70)
return'C';
if(score>=60)
return'D';
else
return'E';
}


運行測試:

⑷ C語言編寫一個學生成績管理系統

這么大的問題,至少要一百塊工錢

⑸ C語言學生成績管理系統代碼

typedef struct student{
char name[MAX];
int num[MAX];
char sex[MAX];
int chinese;
int mathematic;
int english;
int computer;
struct student *next;
}

程序代碼:
//原始密碼是123456
#include"stdio.h"
#include"stddef.h"
#include"stddef.h"
#include"string.h"
#define MAX 10
typedef struct student{ /*定義結構體*/
char name[MAX]; /*姓名*/
int num[MAX]; /* 學號*/
char sex[MAX]; /*性別*/
int chinese; /*語文*/
int mathematic; /* 數學*/
int english; /*英語*/
int computer; /*計算機*/
struct student *next; /*結構體指針*/
}stu;
stu *head; /*頭指針*/
void print() /*顯示或列印函數*/
{
system("cls");
printf("\t\t\tScore Manage System\n"); /*成績管理系統*/
printf("<1>Enter Record\t"); /*輸入數據*/
printf("<2>Display\t"); /*顯示*/
printf("<3>Insert\t"); /*插入數據*/
printf("<4>Quest\t"); /*訪問數據*/
printf("<5>Update\t"); /*以前數據*/
printf("<6>Save\t"); /*保留數據*/
printf("<7>Fresh\t"); /*更新數據*/
printf("<8>Chinese Average\t"); /*語文平均成績*/
printf("<9>Math Average\t"); /*數學平均成績*/
printf("<10>English Average\t"); /*英語平均成績*/
printf("<11>Computer Average\t"); /*計算機平均成績*/
printf("<12>Quit\t\n"); /*退出*/
}

void cin(stu *p1) /*輸入相關數據的函數*/
{ printf("Enter name:\n");
scanf("%s",&p1->name);
printf("Enter num:\n");
scanf("%d",&p1->num);
printf("Enter sex:\n");
scanf("%s",&p1->sex);
printf("Enter score:\n");
printf("Enter chinese:\n");
scanf("%d",&p1->chinese);
printf("Enter math:\n");
scanf("%d",&p1->mathematic);
printf("Enter English:\n");
scanf("%d",&p1->english);
printf("Enter Computer:\n");
scanf("%d",&p1->computer);
}
stu *cindata() /*其他數據是否繼續輸入的函數*/
{ stu *p1,*p2;
int i=1;
char ch;
p1=(stu *)malloc(sizeof(stu));
head=p1;
while(i)
{
cin(p1);
printf("Do you Want to Continue?yes or no"); /*是否繼續輸入數據*/
ch=getchar();
ch=getchar();
if(ch=='n'||ch=='N')
{ i=0;
p1->next=NULL;
}
else
{ p2=p1;
p1=(stu *)malloc(sizeof(stu));
p2->next=p1;
}
}
return(p1->next);
}

stu *lookdata(stu *p1) /*查看數據的函數*/
{
while(p1!=NULL)
{ printf("Num:%d\t",p1->num);
printf("Name:%s\t",p1->name);
printf("Sex:%s\t",p1->sex);
printf("\n");
printf("Chinese:%d\t",p1->chinese);
printf("Math:%d\t",p1->mathematic);
printf("English:%d\t",p1->english);
printf("Computer:%d\t",p1->computer);
printf("\n");
p1=p1->next;
}
return p1;
}

void insert() /*通過比較學號來插入數據的函數*/
{ stu *p1,*p3,*p2;
char ch;
p1=head;
p3=(stu *)malloc(sizeof(stu));

p3->next=NULL;
if(head==NULL){ head=p3; return;}
cin(p3);
while(p1!=NULL&&(p1->num<p3->num)) /*通過學號的比較來插入*/
{ p2=p1;p1=p1->next;}
if(p2==head) {p3->next=head; head=p3; return;}
p3->next=p1;
p2->next=p3;

}

find(stu *p2) /*通過姓名查找查看數據的函數*/
{ char name[20];
int b=0;
printf("Enter the name of the student you want to find:"); /*通過姓名查看*/
scanf("%s",name);
while(p2!=NULL)
{if(strcmp(name,p2->name)==0)
{
printf("The data you want has be found\n");
printf(" Name:%s\t",p2->name);
printf("Num:%d\t",p2->num);
printf("sex%s\t",p2->sex);
printf("\n");
printf("Chinese:%d\t",p2->chinese);
printf("Math:%d\t",p2->mathematic);
printf("English:%d\t",p2->english);
printf("Computer:%d\t",p2->computer);
printf("\n");

b=1;
}
else if(b==0)
printf("sorry not find data!");
p2=p2->next;
}

if(b==1)
{
print();
printf("Find one\n");}
else
{print();
printf("Not find\n");

}
}

void caverage() /*求各學生語文平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->chinese;
aver=sum/i;

p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->chinese)
max=p1->chinese;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->chinese)
min=p1->chinese;
}
printf("Chinese Average:%f",aver);
printf("Chinese Max:%f",max);
printf("Chinese Min:%f",min);
}

void maverage() /*求各學生數學平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->mathematic;
aver=sum/i;

p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->mathematic)
max=p1->mathematic;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->mathematic)
min=p1->mathematic;
}
printf("Mathe Average:%f",aver);
printf("Mathe Max:%f",max);
printf("Mathe Min:%f",min);
}

void eaverage() /*求各學生英語平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->english;
aver=sum/i;

p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->english)
max=p1->english;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->english)
min=p1->english;
}
printf("English Average:%f",aver);
printf("English Max:%f",max);
printf("English Min:%f",min);
}

void comaverage() /*求各學生計算機平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->computer;
aver=sum/i;

p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->computer)
max=p1->computer;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->computer)
min=p1->computer;
}
printf("Computer Average:%f",aver);
printf("Computer Max:%f",max);
printf("Computer Min:%f",min);
}

update(stu *p2) /*通過姓名查找來更新數據*/
{
char name[10]; /*p2為指向結構體struct student的指針*/
int b=0;
printf("Enter The Name"); /*輸入姓名*/
scanf("%s",name);

while(p2!=NULL)
{if(strcmp(name,p2->name)==0)
{
printf("Find you data\n");
scanf("Name:%s",p2->name);
scanf("Num:%s",p2->num);
scanf("Sex:%s",p2->sex);
scanf("Chinese:%d",p2->chinese);
scanf("Math:%d",p2->mathematic);
scanf("english:%d",p2->english);
scanf("Computer:%d",p2->computer);
printf("Success!");

b=1;}
else if(b==0)
printf("Sorry not Find data!");
p2=p2->next;}
if(b==0)
{print();
printf("Sorry not Find data!");
}
else
{
print();
printf("Finish!");
}
}

save(stu *p2) /*保留數據函數*/
{
FILE *fp;
char file[10];
printf("Enter file name"); /*輸入文件名*/
scanf("%s",file);
fp=fopen(file,"w");
while(p2!=NULL)
{
fprintf(fp,"%s",p2->name);
fprintf(fp,"%s",p2->num);
fprintf(fp,"%s",p2->sex);
fprintf(fp,"%d",p2->chinese);
fprintf(fp,"%d",p2->mathematic);
fprintf(fp,"%d",p2->english);
fprintf(fp,"%d",p2->computer);
p2=p2->next;
}
fclose(fp);
}

char password[7]="123456"; /*定義初始密碼*/

void main() /*主函數*/
{ int choice;
stu *p2;
char s[8];
int flag=0,i; /*標志項*/
int n=3;
do{ printf("Enter password:\n");
scanf("%s",s);
if(!strcmp(s,password)) /*進行密碼匹配驗證*/
{ printf("PASS\n\n\n");
flag=1;
break;
}
else{
printf("Error Enter again:\n");
n--;
}
}
while(n>0);
if(!flag)
{printf("you have Enter 3 times!"); /*輸入密碼超過了3次!!*/
exit(0); /*自動退出*/
}
/*密碼驗證成功後進入的界面*/

printf("~~~~~~~~~~\t\t\t~~~~~~~~~~~~\n"); /*操作界面*/
printf("\t\tWelcom to the Mis\n");
printf("Author:-----\tClass:------\tNum:------\n"); /*作者,班級和號碼*/
printf("Adress:HG\n"); /*地址*/
printf("%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
printf("\t\tEnter OP:\n");
printf("\n\n\n\n");
printf("==============\t\t==============\n");
printf("==============\t\t==============\n");
printf("\t\tEnter the MIS yes or no\n"); /*問進入系統與否*/

scanf("%d",&choice);
if(choice=='n'||choice=='N')
exit(1);

print();
while(1)
{
printf("Enter choice:");
scanf("%d",&i);
if(i<1||i>13)
{
printf("Enter num from 1 to 13:\n"); /*再從1-13中進行選擇*/
exit(1);
}

switch(i)
{ case 1:
p2=cindata(); /*其他數據是否繼續輸入的函數*/
break;
case 2:
p2=lookdata(head); /*查看數據的函數*/
break;
case 3:
insert(); /*通過比較學號來插入數據的函數*/
break;
case 4:
find(head); /*通過姓名查找查看數據的函數*/
break;
case 5:
update(head); /*通過姓名查找來更新數據*/
break;
case 6:
save(head); /*保留數據函數*/
break;
case 7:
print(); /*顯示或列印函數*/
break;
case 8:
caverage(); /*求各學生語文平均分、最高和最低分成績的函數*/
break;
case 9:
maverage(); /*求各學生數學平均分、最高和最低分成績的函數*/
break;
case 10:
eaverage(); /*求各學生英語平均分、最高和最低分成績的函數*/
break;
case 11:
comaverage(); /*求各學生計算機平均分、最高和最低分成績的函數*/
break;
case 12:
; /*空操作*/
case 13:
exit(1); /*退出*/
break;
}
scanf("%d",&i);
}
}

⑹ 用C語言編程實現一個簡單的學生成績管理系統

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<memory.h>

typedefstructstudent
{
charnum[16];
charname[20];
floatscore[4];
structstudent*next;
}stu;

stu*head; //鏈頭指針

stu*create() //創建鏈表,從文件讀取信息
{
printf("Readingstudentinformation: ");
stu*p=NULL; //指針,指向個待插入的結點
stu*q=NULL; //指針,用於在其後插入結點
head=NULL; //一開始鏈表為空
FILE*r=fopen("input.dat","r");
p=(stu*)malloc(sizeof(stu));
while(fscanf(r,"%s%s%f%f%f",p->num,p->name,&p->score[0],&p->score[1],&p->score[2])!=EOF)
{
p->score[3]=(p->score[0]+p->score[1]+p->score[2])/3.0;
fprintf(stdout,"%s %s %g %g %g %.2f ",p->num,p->name,p->score[0],p->score[1],p->score[2],p->score[3]);
p->next=NULL;
if(head==NULL) //head為空,要插入第一個
{
head=p;
} //結點,讓頭指針指向結點p
else
{ //否則不是頭結點,應將p結點
q->next=p; //插入到q結點的後面
}
q=p; //q指向當前最後一個結點
p=(stu*)malloc(sizeof(stu));
}
fclose(r);
if(head!=NULL)
{
q->next=NULL; //讓q所指的最後一個結點的指針域為空說明這已是鏈尾了
}
returnhead; //返回頭指針
}

voidsort(stu**head,intn)
{
FILE*w=NULL;
if(n==0)
{
w=fopen("sortByMath.dat","w");
}
elseif(n==1)
{
w=fopen("sortByEnglish.dat","w");
}
elseif(n==2)
{
w=fopen("sortByComputer.dat","w");
}
elseif(n==3)
{
w=fopen("sortByAvg.dat","w");
}
stu*q,*t,*p;
stu*new_head=newstu;
new_head->next=*head;
p=new_head;
t=NULL;
while(t!=new_head->next)
{
p=new_head;
q=p->next;
while(q->next!=t)
{
if((p->next->score[n])<(q->next->score[n]))
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
t=q;
}
*head=new_head->next;


p=*head;
q=p->next;
printf("學號 姓名 數學 英語 計算機 平均成績 ");
intgrade=1;
while(p!=NULL)
{
fprintf(w,"%s %s %g %g %g %.2f %d ",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->score[3],grade);
fprintf(stdout,"%s %s %g %g %g %.2f %d ",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->score[3],grade);
if(q!=NULL&&q->score[3]<p->score[3])grade+=1;
p=p->next;
if(q!=NULL)q=q->next;
}
printf(" ");
fclose(w);
}

voidcount(stu*head)
{
floatcnt[4][8];
inti,j;
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
if(j!=2)cnt[i][j]=0;
elsecnt[i][j]=100;
}
}
stu*r=head;
while(r!=NULL)
{
r=r->next;
}
}
intmain()
{
head=create();
printf("Sortingbyaveragescore: ");
sort(&head,3);

system("pause");
return0;
}

⑺ c語言學生信息管理系統代碼

代碼如下:

#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
typedef struct examinee //考生信息結構
{ char examno[20]; //准考證號
char name[10]; //姓名
char sex[4]; //性別
short age; //年齡
char examtype[10]; //報考科目
}ElemType;

typedef struct Node //定義鏈表結點
{
ElemType data; //數據域
struct Node *next; //指針域
}Node,*List,*position;

List make_empty( List L ); //創建一個帶頭結點的空表
int is_empty( List L ); //測試鏈表是否是空表
int is_last( position p, List L ); //測試當前位置是否是表尾
position make_node( position p,int n ); //創建結點並輸入考生信息
void put_information( position p ); //是否輸出該考生信息
void put_name_information( List L ); //輸出姓名為xx的考生信息
int put_pos_information( position p ); //輸出該地址考生信息
void link_to_tail( List L, position p ); //將結點連接到表尾
int ciculation_make(); //循環創建考生信息
int judge_put_all(); //是否輸出所有考生信息
void put_all(List L); //輸出所有考生信息。
position find( List L ); //查找第一個姓名為xx的元素並返回位置
position find_previous( List L ); //查找第一個姓名為xx的元素並返回該元素直接前驅的位置
//int judge_delete_val(); //詢問是否刪除考生數據
int delete_val( List L ); //刪除指定考生信息並輸出其信息
void menu(List L); //菜單函數
List L;
//position p;

int
main( void )
{
List L = NULL; //定義頭結點指針
position p = NULL; //定義表工作指針
L = make_empty( L ); //創建空表
printf(" ★★考生報名管理程序★★ ---------------------------------------- ");
menu(L);
return 0;
}

//創建一個帶頭結點的空表
List
make_empty( List L)
{
L = ( List ) malloc (sizeof( Node ));
if(NULL == L)
{
printf("內存分配失敗");
exit( 1 );
}
L->next = NULL;
//printf("空表創建成功。 ");
return L;
}

//創建結點並輸入考生信息
position
make_node( position p ,int n)
{
if(n) //n為1是創建結點並輸入,n為0是修改
{
p = ( position ) malloc ( sizeof ( Node ));
p->next = NULL ;
}
printf("請輸入考生准考證號:");
gets(p->data.examno);
printf("請輸入考生姓名:");
gets(p->data.name);
do
{
printf("請輸入考生性別,只能輸入「男」或者「女」:");
gets(p->data.sex);
}
while( 0 != strcmp( p->data.sex, "男" ) && 0 != strcmp( p->data.sex, "女" )); //判斷性別是否有誤
printf("請輸入考生年齡:");
scanf("%hd",&p->data.age);
getchar(); //如果把這句刪掉,就「無法執行」下面的報考類別
/*下面的do while用來判斷報考類別是否輸入有誤*/
do
{
printf("請輸入報考類別,只能輸入「數學」或「英語」或者「數據結構」:");
gets(p->data.examtype);
}
while( 0 != strcmp( "英語", p->data.examtype ) && 0 != strcmp( "數學", p->data.examtype ) && 0 != strcmp( "數據結構", p->data.examtype ));
if(n)
{
printf("報名成功 ");
}
else
{
printf("修改成功 ");
}
return p;
}

//前插法;
void
link_to_tail( List L, position p)
{
p->next = L->next;
L->next = p;
}

//查找第一個姓名為xx的元素並返回位置
position
find( List L )
{
position p = L->next;
char name[10];
printf("請輸入你要查找的考生姓名:");
gets(name);
while( p != NULL && 0 != strcmp( p->data.name , name))
{
p=p->next;
}
return p;
}

//測試鏈表是否是空表
int
is_empty( List L )
{
return L->next == NULL;
}

//測試當前位置是否是表尾
int
is_last( position p, List L )
{
return p->next == NULL;
}

//輸出姓名為xx的考生信息
void
put_name_information( List L )
{
position p = find(L);
if(p!=NULL)
{
printf("您要查找的考生信息: ");
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s ",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
}
else
{
printf("沒有您要找的學生。 ");
}

}

//循環創建考生信息
int
ciculation_make()
{
int n = 2;
do
{
printf("是否繼續創建考生信息?是請輸入「1」,不是請輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
return n;
}

//是否輸出考生信息
void
put_information( position p )
{
int n=2;
do
{
printf("是否輸出該考生信息?是請輸入「1」,不是請輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
if(n)
{
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s ",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
}
}


//是否輸出所有考生信息
int
judge_put_all()
{
int n = 2;
do
{
printf("是否輸出所有考生信息?是請輸入「1」,不是請輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
return n;
}

//輸出所有考生信息
void
put_all(List L)
{
if(L->next == NULL)
{
printf("現無考生報名! ");
}
else
{
position p=L->next;
while( p != NULL )
{
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s ",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
p=p->next;
}
}
//getchar();

}

//詢問是否刪除考生數據
int
judge_delete_val()
{
int n = 2;

do
{
printf("是否要刪除某個考生數據?是請輸入「1」,不是輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
return n;
}

//查找第一個姓名為xx的元素並返回其直接前驅的位置
position
find_previous( List L )
{
position q = L;
position p = L->next;
char name[10];
printf("請輸入你要查找的考生姓名:");
gets(name);
while( p != NULL && 0 != strcmp( p->data.name , name))
{
q=p;
p=p->next;
}
if( p != NULL )
{
return q;
}
else
return p;
}

//刪除指定考生信息並輸出其信息
int
delete_val(List L)
{
int n=2;
position q=NULL;
position p=find_previous( L ); //返回考生信息地址
if( NULL == p )
{
printf("你要刪除的考生不存在 ");
return 0;
}
else
{
q = p->next;
p->next = q->next;
printf("刪除成功。 刪除的考生信息為: ");
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s ",q->data.examno,q->data.name,q->data.sex,q->data.age,q->data.examtype);
free(q);
return 1;
}

}

//輸出該地址考試信息
int
put_pos_information( position p )
{
if(p != NULL )
{
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s ",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
return 1;
}
else
{
printf("沒有您要查找的學生。");
return 0;
}
}
//菜單函數
void
menu(List L)
{
printf(" a. 考生報名入口 ");
printf(" b. 查詢考生信息 ");
printf(" c. 修改考生信息 ");
printf(" d. 刪除考生信息 ");
printf(" e. 全部考生信息 ");
printf(" f. 程序作者信息 ");
printf(" g. 退出程序 ");
char n='h';

while(n != 'g')
{
do //確定正確輸入
{
printf("請通過字母序號選擇功能:");
n = getchar();
getchar();
putchar(' ');
if( n < 'a' || n > 'g')
{
printf("錯誤的字母序號。 ");
}
}
while( n < 'a' || n > 'g' );
switch (n)
{
case 'a':
{
printf("請輸入報名考生信息: ");
position p = make_node( p, 1 ); //創建新結點
link_to_tail( L, p ); //將新結點連接到表上
put_information( p ); //是否輸出該考生信息
putchar(' ');
}
break;

case 'b':
{
put_name_information( L );
putchar(' ');
}
break;

case 'c':
{
int n=0;
position p = NULL;
printf("您正在進行修改操作。 ");
p = find(L);
n = put_pos_information( p );
if(n)
{
make_node( p , 0 );
put_information( p ); //是否輸出該考生信息
}
putchar(' ');
}
break;

case 'd':
{
printf("您正在進行刪除操作。 ");
delete_val( L );
putchar(' ');
}
break;

case 'e':
{
put_all( L );
putchar(' ');
}
break;

case 'f':
{
printf(" 修改日期 版本號 修改人 修改內容 ");
printf(" -------------------------------------------------------- ");
printf(" 2018.6.19 v2.0 陳百川 增加主菜單 ");
printf(" 2018.6.23 v3.0 陳百川 增加生成文件功能 ");
printf(" 該版本號為v2.0 ");
putchar(' ');
}
break;

default:
break;
}
}
printf(" 感謝本次使用,祝您生活愉快。");
getch();
}

(7)c代碼學生成績管理系統擴展閱讀:

C語言是一門通用計算機編程語言,廣泛應用於底層開發。C語言的設計目標是提供一種能以簡易的方式編譯、處理低級存儲器、產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。

盡管C語言提供了許多低級處理的功能,但仍然保持著良好跨平台的特性,以一個標准規格寫出的C語言程序可在許多電腦平台上進行編譯,甚至包含一些嵌入式處理器(單片機或稱MCU)以及超級電腦等作業平台。

二十世紀八十年代,為了避免各開發廠商用的C語言語法產生差異,由美國國家標准局為C語言制定了一套完整的美國國家標准語法,稱為ANSI C,作為C語言最初的標准。[1]目前2011年12月8日,國際標准化組織(ISO)和國際電工委員會(IEC)發布的C11標準是C語言的第三個官方標准,也是C語言的最新標准,該標准更好的支持了漢字函數名和漢字標識符,一定程度上實現了漢字編程。

C語言是一門面向過程的計算機編程語言,與C++,Java等面向對象的編程語言有所不同。

其編譯器主要有Clang、GCC、WIN-TC、SUBLIME、MSVC、Turbo C等。

參考資料:

網路——C語言

⑻ 學生成績管理系統C語言代碼

#include"stdio.h"
#include<string.h>
#include<stdlib.h>

#define N 30
struct student
{
int num;
char name[20];
int age;
int Math;
int English;
int Physical;
long int sum;
}stu[N];

enter()
{int i,n;
printf("How many students(1-%d)?:",N);
scanf("%d",&n);
printf("\nEnter data now\n\n");
for(i=0;i<n;i++)
{printf("\n Input %dth student record.\n",i+1);
input(i);
}
if(i!=0) save(n);
printf_back(); /* browse or back */
}

add()
{int i,n,m,k;
FILE *fp;
n=load();
printf("How many students are you want to add(1-%d)?:",N-n);
scanf("%d",&m);
k=m+n;
for(i=n;i<k;i++)
{printf("\n Input %dth student record.\n",i+1);
input(i);
}
if((fp=fopen("score.txt","ab"))==NULL)
{printf("Cannot open file.\n");
}
for(i=n;i<k;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error.\n");
fclose(fp);
printf_back();
}

/* insert()
{int n,c;
struct student s;
n=load();
puts("\n Input one data.\n");
do
{input(n);
printf_face();
printf_one(n);
printf("\n\nAre you sure?\n\n\t 1.Sure\t2.cancel and again\t3.Back without save [ ]\b\b");
scanf("%d",&c);
if(c==1)
{
save(n+1);
printf_back();
}
else if(c!=2) menu();
}
while(c==2);
} */

modify()
{struct student s;
FILE *fp;
int i,n,k,w0=1,w1,w2=0;
n=load();
do
{
k=-1;
printf_face();
for(i=0;i<n;i++)
{if((i!=0)&&(i%10==0))
{printf("\n\nRemember NO.031073- which needed modify.Pass any key to continue ...");
getch();
puts("\n\n");
}
printf_one(i);
printf("\n");
}
do
{printf("\n\nEnter NO.031073- that you want to modify! NO.:031073-");
scanf("%d",&s.num);
for(i=0;i<n;i++)
if(s.num==stu[i].num)
{k=i;
s=stu[i]; /* chengji beifei */
}
if(k==-1) printf("\n\nNO exist!please again");
}
while(k==-1);
printf_face();
printf_one(k);
w1=modify_data(k,n);
if(w1==1)
{printf("\nSuccessful ^_^.\n\nAre you modify another?\n\n\t1.Yes2.Back with save\t[ ]\b\b");
scanf("%d",&w0);
w2=1;
}
else
{w0=0; /* end */
if(w2==1)
stu[k]=s;
}
if(w0!=1&&w2==1) save(n); /* w0!=1 return w2==1 modify */
}
while(w0==1);
menu();
}

delete()
{struct student s;
FILE *fp;
int i,n,k,w0=1,w1,w2=0;
n=load();
do
{
k=-1;
printf_face();
for(i=0;i<n;i++)
{if((i!=0)&&(i%10==0))
{printf("\n\nRemember NO.031073- which needed delete.Pass any key to continue ...");
getch();
puts("\n\n");
}
printf_one(i);
printf("\n");
}
do
{printf("\n\nEnter NO.031073- that you want to delete! NO.:031073-");
scanf("%d",&s.num);
for(i=0;i<n;i++)
if(s.num==stu[i].num)
{k=i;
s=stu[i]; /* chengji beifei */
}
if(k==-1) printf("\n\nNO exist!please again");
}
while(k==-1);
printf_face();
printf_one(k);
printf("\nAre you sure?\n\n\t1.Sure2.Back without save in this time [ ]\b\b");
scanf("%d",&w1);
if(w1==1)
{
stu[k].sum=0;
printf("\nSuccessful ^_^.\n\nAre you delete another?\n\n\t1.Yes2.Back with save\t[ ]\b\b");
scanf("%d",&w0);
w2=1;
}
else
{w0=0; /* end */
if(w2==1)
stu[k]=s;
}
if(w0!=1&&w2==1) save(n);
}
while(w0==1);
menu();
}

modify_score()
{struct student s;
FILE *fp;
int i,n,k,w0=1,w1,w2=0;
n=load();
do
{
k=-1;
printf_face();
for(i=0;i<n;i++)
{if((i!=0)&&(i%10==0))
{printf("\n\nRemember NO.031073 which score needed modify.Pass any key to continue ...");
getch();
puts("\n\n");
}
printf_one(i);
printf("\n");
}
do
{printf("\n\nEnter NO.031073- that you want to modify! NO.:031073-");
scanf("%d",&s.num);
for(i=0;i<n;i++)
if(s.num==stu[i].num)

{k=i;
s=stu[i]; /* chengji beifei */
}
if(k==-1) printf("\n\nNO exist!please again");
}
while(k==-1);
printf_face();
printf_one(k);
w1=modify_score1(k);
if(w1==1)
{printf("\nSuccessful ^_^.\n\nAre you modify another score?\n\n\t1.Yes2.Back with save\t[ ]\b\b");
scanf("%d",&w0);
w2=1;
}
else
{w0=0; /* end */
if(w2==1)
stu[k]=s;
}
if(w0!=1&&w2==1) save(n); /* w0!=1 return w2==1 modify */
}
while(w0==1);
menu();
}

order()
{int i,j,k,n;
struct student s;
n=load();
for(i=0;i<n-1;i++)
{k=i;
for(j=i+1;j<n;j++)
if(stu[j].num<stu[k].num) k=j;
s=stu[i];stu[i]=stu[k];stu[k]=s;
}
save(n);
puts("\n\n");
printf_back();
}

browse()
{int i,j,n;
n=load();
printf_face();
for(i=0;i<n;i++)
{if((i!=0)&&(i%10==0))
{printf("\n\nPass any key to contiune ...");
getch();
puts("\n\n");
}
printf_one(i);
printf("\n");
}
printf("\tThere are %d record.\n",n);
printf("\nPass any key to back...");
getch();
menu();
}

save(int n)
{FILE *fp;
int i;
if((fp=fopen("score.txt","wb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;i<n;i++)
if(stu[i].sum!=0)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}

load()
{FILE *fp;
int i;
if((fp=fopen("score.txt","rb"))==NULL)
{printf("\nCannot open file\n");
return NULL;
}
for(i=0;!feof(fp);i++)
fread(&stu[i],sizeof(struct student),1,fp);
fclose(fp);
return(i-1);
}

no_input(int i,int n)
{int k,w1;
do
{w1=0;
printf("NO.:031073-");
scanf("%d",&stu[i].num);
if(stu[i].num<1 || stu[i].num>N)
{puts("Input error! Only be made up of(1-N).Please reinput!\n");
w1=1;
}
if(w1!=1)
for(k=0;k<n;k++)
if(k!=i&&(stu[k].num==stu[i].num))
{puts("This record is exist. Please reinput!\n");
w1=1;break;
}
}
while(w1==1);
}

enter_score(int i)
{printf("Math English Physical");
scanf("%d %d %d",&stu[i].Math,&stu[i].English,&stu[i].Physical);
}
sum(int i)
{
stu[i].sum=stu[i].Math+stu[i].English+stu[i].Physical;
}

input(int i)
{no_input(i,i);
printf("name: age:");
scanf("%s %d",stu[i].name,&stu[i].age);
enter_score(i);
sum(i);
}

modify_score1(int i)
{int c,w1;
do
{
puts("\nmodify by=>\n\n 1.Math 2.English 3.Physical4.all score 5.cancel and back");
printf("Which you needed?:[ ]\b\b");
scanf("%d",&c);
if(c>5||c<1)
{puts("\nChoice error! Please again!");
getchar();
}
}
while(c>5||c<1);
do
{switch(c)
{
case 1:printf("Math:");scanf("%d",&stu[i].Math);break;
case 2:printf("English:");scanf("%d",&stu[i].English);break;
case 3:printf("Physical:");scanf("%d",&stu[i].Physical);break;
case 4:enter_score(i);break;
case 5:break;
}
if(c>0&&c<5) sum(i);
puts("\nNow:\n");
printf_face();
printf_one(i);
printf("\nAre you sure?\n\n\t1.Sure 2.No and remodify3.Back without save in this time [ ]\b\b");
scanf("%d",&w1);
}
while(w1==2);
return(w1);
}

modify_data(int i,int n)
{int c,w1;
do
{
puts("\nmodify by=>\n\n 1.NO. 2.name 3.age 4.Math 5.English 6.Physical7.all score 8.all data 9.cancel and back");
printf("Which you needed?:[ ]\b\b");
scanf("%d",&c);
if(c>9||c<1)
{puts("\nChoice error! Please again!");
getchar();
}
}
while(c>9||c<1);
do
{switch(c)
{case 1:no_input(i,n);break;
case 2:printf("name:");scanf("%s",stu[i].name);break;
case 3:printf("age:");scanf("%d",&stu[i].age);break;
case 4:printf("Math:");scanf("%d",&stu[i].Math);break;
case 5:printf("English:");scanf("%d",&stu[i].English);break;
case 6:printf("Physical:");scanf("%d",&stu[i].Physical);break;
case 7:enter_score(i);break;
case 8:input(i);break;
case 9:break;
}
if(c>3&&c<8) sum(i);
puts("\nNow:\n");
printf_face();
printf_one(i);
printf("\nAre you sure?\n\n\t1.Sure 2.No and remodify3.Back without save in this time [ ]\b\b");
scanf("%d",&w1);
}
while(w1==2);
return(w1);
}

printf_face()
{printf("\nNO.031073 name age Math English Physical sum\n");
}

printf_one(int i)
{
printf("%6d %8s %4d",stu[i].num,stu[i].name,stu[i].age);
printf("%5d %5d %8d %10d",stu[i].Math,stu[i].English,stu[i].Physical,stu[i].sum);
}

printf_back()
{int k,w;
printf("\n\n\tSuccessful.^_^\n\n");
printf("What do you want to do?\n\n\t1.Browse all now\t2.Back:[ ]\b\b");
scanf("%d",&w);
if(w==1) browse();
else menu();
}
menu()
{int w1;
char n;
do
{
puts("\t\t****************MENU****************\n\n");
puts("\t\t\t\tA.Enter new data");
puts("\t\t\t\tB.Addition data");
puts("\t\t\t\tC.Modify data");
puts("\t\t\t\tD.Delete data");
puts("\t\t\t\tE.Modify score");
puts("\t\t\t\tF.Order by number");
puts("\t\t\t\tG.Browse all");
puts("\t\t\t\tH.Exit");
puts("\n\n\t\t************************************\n");
printf("Choice your number(A-H):[ ]\b\b");
n=getchar();
printf("\n");
if(n<'A'||n>'H')
w1=1;
else w1=0;
}
while(w1==1);
switch(n)
{case 'A':enter();break;
case 'B':add();break;
case 'C':modify();break;
case 'D':delete();break;
case 'E':modify_score();break;
case 'F':order();break;
case 'G':browse();break;
case 'H':exit(0);
}
}
char password[7]="123456";
main()
{
char s[7];
printf("\t\t請輸入密碼:\n\t\t\n\t\t");
scanf("%s",s);
if(!strcmp(s,password))
{
printf("\n\t\t恭喜你進入學生成績管理系統\n");
menu();
}
else
{
printf("\t\t 密碼錯誤\n\n");
main();
}
}

⑼ C語言學生成績管理系統

學生成績管理系統C代碼
/*頭文件*/
#include <stdio.h>
#include<dos.h>
#include<stdlib.h> /*其它說明*/
#include<string.h> /*字元串函數*/
#include<mem.h> /*內存操作函數*/
#include<ctype.h> /*字元操作函數*/
#include<alloc.h> /*動態地址分配函數*/
#define LEN sizeof(STUDENT)
typedef struct stu /*定義結構體數組用於緩存數據*/
{char num[6];
char name[5];
int score[3];
int sum;
float average;
int order;
struct stu *next;
}STUDENT;

/*函數原型*/
STUDENT *init(); /*初始化函數*/
int menu_select(); /*菜單函數*/
STUDENT *create(); /*創建鏈表*/
void print(STUDENT *head); /* 顯示全部記錄*/
void search(STUDENT *head); /*查找記錄*/
STUDENT *delete(STUDENT *head); /*刪除記錄*/
STUDENT *sort(STUDENT *head); /*排序*/
STUDENT *insert(STUDENT *head,STUDENT *new); /*插入記錄*/
void save(STUDENT *head); /*保存文件*/
STUDENT *load(); /*讀文件*/

/*主函數界面*/
main()
{STUDENT *head,new;
head=init(); /*鏈表初始化,使head的值為NULL*/
for(;;) /*循環無限次*/
{switch(menu_select())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:search(head);break;
case 4:head=delete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,&new);break; /*&new表示返回地址*/
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0); /*如菜單返回值為9則程序結束*/
}
}
}

/*初始化函數*/
STUDENT *init()
{
return NULL; /*返回空指針*/
}

/*菜單選擇函數*/
menu_select()
{int n;
struct date d; /*定義時間結構體*/
getdate(&d); /*讀取系統日期並把它放到結構體d中*/
printf("press any key to enter the menu......"); /*按任一鍵進入主菜單*/
getch(); /*從鍵盤讀取一個字元,但不顯示於屏幕*/
clrscr(); /*清屏*/
printf("********************************************************************************\n");
printf("\t\t Welcome to\n");
printf("\n\t\t The student score manage system\n");
printf("*************************************MENU***************************************\n");
printf("\t\t\t1. Enter the record\n"); /*輸入學生成績記錄*/
printf("\t\t\t2. Print the record\n"); /*顯示*/
printf("\t\t\t3. Search record on name\n"); /*尋找*/
printf("\t\t\t4. Delete a record\n"); /*刪除*/
printf("\t\t\t5. Sort to make new a file\n"); /*排序*/
printf("\t\t\t6. Insert record to list\n"); /*插入*/
printf("\t\t\t7. Save the file\n"); /*保存*/
printf("\t\t\t8. Load the file\n"); /*讀取*/
printf("\t\t\t9. Quit\n"); /*退出*/
printf("\n\t\t Made by Hu Haihong.\n");
printf("********************************************************************************\n");
printf("\t\t\t\t%d\\%d\\%d\n",d.da_year,d.da_mon,d.da_day); /*顯示當前系統日期*/
do{
printf("\n\t\t\tEnter your choice(1~9):");
scanf("%d",&n);
}while(n<1||n>9); /*如果選擇項不在1~9之間則重輸*/
return(n); /*返回選擇項,主函數根據該數調用相應的函數*/
}

/*輸入函數*/
STUDENT *create()
{int i,s;
STUDENT *head=NULL,*p; /* 定義函數.此函數帶回一個指向鏈表頭的指針*/
clrscr();
for(;;)
{p=(STUDENT *)malloc(LEN); /*開辟一個新的單元*/
if(!p) /*如果指針p為空*/
{printf("\nOut of memory."); /*輸出內存溢出*/
return (head); /*返回頭指針,下同*/
}
printf("Enter the num(0:list end):");
scanf("%s",p->num);
if(p->num[0]=='0') break; /*如果學號首字元為0則結束輸入*/
printf("Enter the name:");
scanf("%s",p->name);
printf("Please enter the %d scores\n",3); /*提示開始輸入成績*/
s=0; /*計算每個學生的總分,初值為0*/
for(i=0;i<3;i++) /*3門課程循環3次*/
{
do{
printf("score%d:",i+1);
scanf("%d",&p->score[i]);
if(p->score[i]<0 || p->score[i]>100) /*確保成績在0~100之間*/
printf("Data error,please enter again.\n");
}while(p->score[i]<0 || p->score[i]>100);
s=s+p->score[i]; /*累加各門成績*/
}
p->sum=s; /*將總分保存*/
p->average=(float)s/3; /*先用強制類型轉換將s轉換成float型,再求平均值*/
p->order=0; /*未排序前此值為0*/
p->next=head; /*將頭結點做為新輸入結點的後繼結點*/
head=p; /*新輸入結點為新的頭結點*/
}
return(head);
}

/* 顯示全部記錄函數*/
void print(STUDENT *head)
{int i=0; /* 統計記錄條數*/
STUDENT *p; /*移動指針*/
clrscr();
p=head; /*初值為頭指針*/
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
while(p!=NULL)
{
i++;
printf("| %3d | %4s | %-4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
i, p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("-------------------------------------------------------------------------------\n");
printf("**************************************END**************************************\n");
}

/*查找記錄函數*/
void search(STUDENT *head)
{STUDENT *p; /* 移動指針*/
char s[5]; /*存放姓名用的字元數組*/
clrscr();
printf("Please enter name for searching.\n");
scanf("%s",s);
p=head; /*將頭指針賦給p*/
while(strcmp(p->name,s) && p != NULL) /*當記錄的姓名不是要找的,或指針不為空時*/
p=p->next; /*移動指針,指向下一結點*/
if(p!=NULL) /*如果指針不為空*/
{printf("\n*************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
}
else
printf("\nThere is no num %s student on the list.\n",s); /*顯示沒有該學生*/
}

/*刪除記錄函數*/
STUDENT *delete(STUDENT *head)
{int n;
STUDENT *p1,*p2; /*p1為查找到要刪除的結點指針,p2為其前驅指針*/
char c,s[6]; /*s[6]用來存放學號,c用來輸入字母*/
clrscr();
printf("Please enter the deleted num: ");
scanf("%s",s);
p1=p2=head; /*給p1和p2賦初值頭指針*/
while(strcmp(p1->num,s) && p1 != NULL) /*當記錄的學號不是要找的,或指針不為空時*/
{p2=p1; /*將p1指針值賦給p2作為p1的前驅指針*/
p1=p1->next; /*將p1指針指向下一條記錄*/
}
if(strcmp(p1->num,s)==0) /*學號找到了*/
{printf("**************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1->num,p1->name,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
printf("Are you sure to delete the student Y/N ?"); /*提示是否要刪除,輸入Y刪除,N則退出*/
for(;;)
{scanf("%c",&c);
if(c=='n'||c=='N') break; /*如果不刪除,則跳出本循環*/
if(c=='y'||c=='Y')
{
if(p1==head) /*若p1==head,說明被刪結點是首結點*/
head=p1->next; /*把第二個結點地址賦予head*/
else
p2->next=p1->next; /*否則將一下結點地址賦給前一結點地址*/
n=n-1;
printf("\nNum %s student have been deleted.\n",s);
printf("Don't forget to save.\n");break; /*刪除後就跳出循環*/
}
}
}
else
printf("\nThere is no num %s student on the list.\n",s); /*找不到該結點*/
return(head);
}

/*排序函數*/
STUDENT *sort(STUDENT *head)
{int i=0; /*保存名次*/
STUDENT *p1,*p2,*t,*temp; /*定義臨時指針*/
temp=head->next; /*將原表的頭指針所指的下一個結點作頭指針*/
head->next=NULL; /*第一個結點為新表的頭結點*/
while(temp!=NULL) /*當原表不為空時,進行排序*/
{
t=temp; /*取原表的頭結點*/
temp=temp->next; /*原表頭結點指針後移*/
p1=head; /*設定移動指針p1,從頭指針開始*/
p2=head; /*設定移動指針p2做為p1的前驅,初值為頭指針*/
while(t->average<p1->average&&p1!=NULL) /*作成績平均分比較*/
{
p2=p1; /*待排序點值小,則新表指針後移*/
p1=p1->next;
}
if(p1==p2) /*p1==p2,說明待排序點值大,應排在首位*/
{
t->next=p1; /*待排序點的後繼為p*/
head=t; /*新頭結點為待排序點*/
}
else /*待排序點應插入在中間某個位置p2和p1之間,如p為空則是尾部*/
{
t->next=p1; /*t的後繼是p1*/
p2->next=t; /*p2的後繼是t*/
}
}
p1=head; /*已排好序的頭指針賦給p1,准備填寫名次*/
while(p1!=NULL) /*當p1不為空時,進行下列操作*/
{
i++; /*結點序號*/
p1->order=i; /*將結點序號賦值給名次*/
p1=p1->next; /*指針後移*/
}
printf("Sorting is sucessful.\n"); /*排序成功*/
return (head);
}

/*插入記錄函數*/
STUDENT *insert(STUDENT *head,STUDENT *new)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head; /*使p1指向第一個結點*/
p0=new; /*p0指向要插入的結點*/
printf("\nPlease enter a new record.\n"); /*提示輸入記錄信息*/
printf("Enter the num:");
scanf("%s",new->num);
printf("Enter the name:");
scanf("%s",new->name);
printf("Please enter the %d scores.\n",3);
sum1=0; /*保存新記錄的總分,初值為0*/
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&new->score[i]);
if(new->score[i]>100||new->score[i]<0)
printf("Data error,please enter again.\n");
}while(new->score[i]>100||new->score[i]<0);
sum1=sum1+new->score[i]; /*累加各門成績*/
}
new->sum=sum1; /*將總分存入新記錄中*/
new->average=(float)sum1/3;
new->order=0;
if(head==NULL) /*原來的鏈表是空表*/
{head=p0;p0->next=NULL;} /*使p0指向的結點作為頭結點*/
else
{while((p0->average<p1->average)&&(p1->next!=NULL))
{p2=p1; /*使p2指向剛才p1指向的結點*/
p1=p1->next; /*p1後移一個結點*/
}
if(p0->average>=p1->average)
{if(head==p1)head=p0; /*插到原來第一個結點之前*/
else p2->next=p0; /*插到p2指向的結點之後*/
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;} /*插到最後的結點之後*/
}
n=n+1; /*結點數加1*/
head=sort(head); /*調用排序的函數,將學生成績重新排序*/
printf("\nStudent %s have been inserted.\n",new->name);
printf("Don't forget to save the new file.\n");
return(head);
}

/*保存數據到文件函數*/
void save(STUDENT *head)
{FILE *fp; /*定義指向文件的指針*/
STUDENT *p; /* 定義移動指針*/
char outfile[10];
printf("Enter outfile name,for example c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"wb"))==NULL) /*為輸出打開一個二進制文件,為只寫方式*/
{
printf("Cannot open the file\n");
return; /*若打不開則返回菜單*/
}
printf("\nSaving the file......\n");
p=head; /*移動指針從頭指針開始*/
while(p!=NULL) /*如p不為空*/
{
fwrite(p,LEN,1,fp); /*寫入一條記錄*/
p=p->next; /*指針後移*/
}
fclose(fp); /*關閉文件*/
printf("Save the file successfully!\n");
}

/* 從文件讀數據函數*/
STUDENT *load()
{STUDENT *p1,*p2,*head=NULL; /*定義記錄指針變數*/
FILE *fp; /* 定義指向文件的指針*/
char infile[10];
printf("Enter infile name,for example c:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"rb"))==NULL) /*打開一個二進制文件,為只讀方式*/
{
printf("Can not open the file.\n");
return(head);
}
printf("\nLoading the file!\n");
p1=(STUDENT *)malloc(LEN); /*開辟一個新單元*/
if(!p1)
{
printf("Out of memory!\n");
return(head);
}
head=p1; /*申請到空間,將其作為頭指針*/
while(!feof(fp)) /*循環讀數據直到文件尾結束*/
{
if(fread(p1,LEN,1,fp)!=1) break; /*如果沒讀到數據,跳出循環*/
p1->next=(STUDENT *)malloc(LEN); /*為下一個結點開辟空間*/
if(!p1->next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1; /*使p2指向剛才p1指向的結點*/
p1=p1->next; /*指針後移,新讀入數據鏈到當前表尾*/
}
p2->next=NULL; /*最後一個結點的後繼指針為空*/
fclose(fp);
printf("You have success to read data from the file!\n");
return (head);
}

⑽ 用C語言設計一個學生成績管理系統

#include <stdio.h>
#include <string.h>

#include <stdlib.h>
#defineMAX1000

/*定義學生成績信息結構*/
struct stu
{

char id[8];
char name[8];


(10)c代碼學生成績管理系統擴展閱讀:

short:修飾int,短整型數據,可省略被修飾的int。(K&R時期引入)

long:修飾int,長整型數據,可省略被修飾的int。(K&R時期引入)

long long:修飾int,超長整型數據,可省略被修飾的int。(C99標准新增)

signed:修飾整型數據,有符號數據類型。(C89標准新增)

unsigned:修飾整型數據,無符號數據類型。(K&R時期引入)

restrict:用於限定和約束指針,並表明指針是訪問一個數據對象的唯一且初始的方式。(C99標准新增)

復雜類型關鍵字

struct:結構體聲明。(K&R時期引入)

union:聯合體聲明。(K&R時期引入)

enum:枚舉聲明。(C89標准新增)

typedef:聲明類型別名。(K&R時期引入)

sizeof:得到特定類型或特定類型變數的大小。(K&R時期引入)

inline:內聯函數用於取代宏定義,會在任何調用它的地方展開。(C99標准新增)

熱點內容
武漢大學學生會輔導員寄語 發布:2021-03-16 21:44:16 瀏覽:612
七年級學生作文輔導學案 發布:2021-03-16 21:42:09 瀏覽:1
不屑弟高考成績 發布:2021-03-16 21:40:59 瀏覽:754
大學畢業證會有成績單 發布:2021-03-16 21:40:07 瀏覽:756
2017信陽學院輔導員招聘名單 發布:2021-03-16 21:40:02 瀏覽:800
查詢重慶2018中考成績查詢 發布:2021-03-16 21:39:58 瀏覽:21
結業考試成績怎麼查詢 發布:2021-03-16 21:28:40 瀏覽:679
14中醫醫師資格筆試考試成績查分 發布:2021-03-16 21:28:39 瀏覽:655
名著賞析課程標准 發布:2021-03-16 21:27:57 瀏覽:881
北京大學商業領袖高端培訓課程 發布:2021-03-16 21:27:41 瀏覽:919