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

學生成績管理系統c語言

發布時間: 2020-12-01 15:12:44

A. 2.學生成績管理系統 (c語言做)

給你找一份類似的。不完全一致。做課程設計還是可行的。自己稍加修改即可!

總體設計
一、 仔細閱讀系統要求,首先將此系統化分為如下模塊(即如下函數)

1、輸入初始的學生信息:其中包括學生的姓名、學號和性別以及學生的語文、數學、英語和計算機等相關信息;可用函數cin(stu *p1)來實現此操作。

2、查詢模塊:可用stu *lookdata(stu *p1) 來實現。找到就輸出此學生全部信息包括學生的語文、數學、英語和計算機等的成績。

3、插入模塊:可用insert( )函數來實現。其中通過學號的大小來比較的,並且以此來排序。

4、輸出學生的信息以及成績:通過學生的姓名來查看學生的語文、數學、英語和計算機等相關成績,同時也可以分別通過caverage() 、maverage() 、eaverage() 和comaverage() 來輸出語文、數學、英語和計算機等成績的平均分數、最高和最低分數。

5、退出系統:可用一個函數exit()來實現,首先將信息保存到文件中,釋放動態創建的內存空間,再退出此程序。

二、系統主模塊結構圖:

詳細設計
一、 界面設計
此系統界面採用圖形和數字化菜單設計。
主界面設計如下:

學生成績管理系統

請選擇相應的數字執行相應的功能:
1:是否輸入其他數據
2:查看數據
3:插入數據
4:查找數據
5:更新數據
6:保留數據
7:顯示或列印數據
8:語文成績狀況
9:數學成績狀況
10:英語成績狀況
11:計算機成績狀況
12:?
13:退出系統
二、 數據結構設計:
程序設計中用到的結構體類型:
學生信息結構體類型:
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);
}
}

B. 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語言編寫一個學生成績管理系統

#include
"stdio.h"
#include
"stdlib.h"
#include
"string.h"
#define
NULL
0
int
shoudsave=0;
struct
student
{
char
num[10];
char
name[20];
char
sex[4];
int
cgrade;
int
mgrade;
int
egrade;
int
totle;
int
ave;
char
neartime[10];
};
typedef
struct
node
{
struct
student
data;
struct
node
*next;
}Node,*Link;
void
menu()
{
printf("********************************************************************************");
printf("\t1輸入學生資料\t\t\t\t\t2刪除學生資料\n");
printf("\t3查詢學生資料\t\t\t\t\t4修改學生資料\n");
printf("\t5顯示學生資料\t\t\t\t\t6統計學生成績\n");
printf("\t7排序學生成績\t\t\t\t\t8保存學生資料\n");
printf("\t9獲取幫助信息\t\t\t\t\t0退出系統\n");
printf("********************************************************************************\n");
}

D. 學生成績管理系統,使用c語言程序編寫。

給一個我以前寫過的吧,功能應該差不多

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
usingnamespacestd;

/*定義學生結構體*/

structStudent

{

charID[20];

charName[20];

floatMark1;

floatMark2;

floatMark3;

floatAverage;

};


/*聲明學生數組及學生數量*/

structStudentstudents[1000];

intnum=0;/*求平均值*/

floatAvg(structStudentstu)

{

return(stu.Mark1+stu.Mark2+stu.Mark3)/3;

}/*通過學號返回數組下標*/

intStudent_SearchByIndex(charid[])

{

inti;

for(i=0;i<num;i++)

{

if(strcmp(students[i].ID,id)==0)

{

returni;

}

}

return-1;

}/*通過姓名返回數組下標*/

intStudent_SearchByName(charname[])

{

inti;

for(i=0;i<num;i++)

{

if(strcmp(students[i].Name,name)==0)

{

returni;

}

}

return-1;

}/*顯示單條學生記錄*/

voidStudent_DisplaySingle(intindex)

{

printf("%10s%10s%8s%8s%8s%10s ","學號","姓名","成績","成績","成績","平均成績");

printf("------------------------------------------------------------- ");

printf("%10s%10s%8.2f%8.2f%8.2f%10.2f ",students[index].ID,students[index].Name,

students[index].Mark1,students[index].Mark2,students[index].Mark3,students[index].Average);

}/*插入學生信息*/

voidStudent_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;

}

}}/*修改學生信息*/

voidStudent_Modify()

{

//floatmark1,mark2,mark3;

while(1)

{

charid[20];

intindex;

printf("請輸入要修改的學生的學號:");

scanf("%s",&id);

getchar();

index=Student_SearchByIndex(id);

if(index==-1)

{

printf("學生不存在! ");

}

else

{

printf("你要修改的學生信息為: ");

Student_DisplaySingle(index);

printf("--請輸入新值-- ");


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;

}

}

}/*刪除學生信息*/

voidStudent_Delete()

{

inti;

while(1)

{

charid[20];

intindex;

printf("請輸入要刪除的學生的學號:");

scanf("%s",&id);

getchar();

index=Student_SearchByIndex(id);

if(index==-1)

{

printf("學生不存在! ");

}

else

{

printf("你要刪除的學生信息為: ");

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;

}

}

}/*按姓名查詢*/

voidStudent_Select()

{

while(1)

{

charname[20];

intindex;

printf("請輸入要查詢的學生的姓名:");

scanf("%s",&name);

getchar();

index=Student_SearchByName(name);

if(index==-1)

{

printf("學生不存在! ");

}

else

{

printf("你要查詢的學生信息為: ");

Student_DisplaySingle(index);

}

printf("是否繼續?(y/n)");

if(getchar()=='n')

{

break;

}

}

}/*按平均值排序*/

voidStudent_SortByAverage()

{

inti,j;

structStudenttmp;

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;

}

}

}

}/*顯示學生信息*/

voidStudent_Display()

{

inti;

printf("%10s%10s%8s%8s%8s%10s ","學號","姓名","成績","成績","成績","平均成績");

printf("------------------------------------------------------------- ");

for(i=0;i<num;i++)

{

printf("%10s%10s%8.2f%8.2f%8.2f%10.2f ",students[i].ID,students[i].Name,

students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Average);

}

}/*將學生信息從文件讀出*/

voidIO_ReadInfo()

{

FILE*fp;

inti;

if((fp=fopen("Database.txt","rb"))==NULL)

{

printf("不能打開文件! ");

return;

}

if(fread(&num,sizeof(int),1,fp)!=1)

{

num=-1;

}

else

{

for(i=0;i<num;i++)

{

fread(&students[i],sizeof(structStudent),1,fp);

}

}

fclose(fp);

}/*將學生信息寫入文件*/

voidIO_WriteInfo()

{

FILE*fp;

inti;

if((fp=fopen("Database.txt","wb"))==NULL)

{

printf("不能打開文件! ");

return;

}

if(fwrite(&num,sizeof(int),1,fp)!=1)

{

printf("寫入文件錯誤! ");

}

for(i=0;i<num;i++)

{

if(fwrite(&students[i],sizeof(structStudent),1,fp)!=1)

{

printf("寫入文件錯誤! ");

}

}

fclose(fp);

}

/*主程序*/

voidmain()

{

intchoice;

IO_ReadInfo();

while(1)

{

/*主菜單*/

printf(" ------學生成績管理系統------ ");

printf("1.增加學生記錄 ");

printf("2.修改學生記錄 ");

printf("3.刪除學生記錄 ");

printf("4.按姓名查詢學生記錄 ");

printf("5.按平均成績排序 ");

printf("6.退出 ");

printf("請選擇(1-6):");

scanf("%d",&choice);

getchar();

switch(choice)

{

case1:

Student_Insert();

break;

case2:

Student_Modify();

break;

case3:

Student_Delete();

break;

case4:

Student_Select();

break;

case5:

Student_SortByAverage();

Student_Display();

break;

case6:

exit(0);

break;

}

IO_WriteInfo();

}

}

E. 學生成績管理系統(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);
}

F. 求C語言學生成績管理系統代碼。要能用的。

#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define N 3
typedef struct z1
{
char no[11];
char name[15];
int score[N];
float sum;
float average;
int order;
struct z1 *next;
}STUDENT;
STUDENT *init();
STUDENT *create();
STUDENT *del(STUDENT *h);
void print(STUDENT *h);
void search1(STUDENT *h);
void search2(STUDENT *h);
STUDENT *insert(STUDENT *h);
void sort(STUDENT *h);
void save(STUDENT *h);
void tongji(STUDENT *h);
int menu_select();
STUDENT *load();
void inputs(char *prompt,char *s,int count);
STUDENT *load();
main()
{
int i;
STUDENT *head;
head=init();
for(;;)
{
switch(menu_select())
{
case 0:head=init();break;
case 1:head=create();break;
case 2:head=insert(head);break;
case 3:save(head);break;
case 4:print(head);break;
case 5:search1(head);break;
case 6:head=del(head);break;
case 7:sort(head);break;
case 8:tongji(head);break;
case 9:search2(head);break;
case 10:exit(0);
}
}
}
int menu_select()
{
char *menu[]={"************菜單************",
"0. 初始化鏈表",
"1. 輸入學生成績",
"2. 插入學生成績",
"3. 保存學生記錄",
"4. 顯示學生記錄",
"5. 按學號查找學生信息",
"6. 刪除指定學號的學生信息",
"7. 按某一門課對學生成績排序",
"8. 統計某門課程的學生成績",
"9. 按姓名查找學生信息",
"10. 退出系統"};
char s[3];
int c,i;
for(i=0;i<=11;i++)
printf(" %s\n",menu[i]);
do
{
printf("\n請選擇0~10中的某一個選項\n");
scanf("%s",s);
c=atoi(s);
}while(c<0||c>10);
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("\n內存不足");
return NULL;
}
inputs("輸入學號:",info->no,11);
if(info->no[0]=='@')break;
inputs("輸入姓名:",info->name,15);
printf("開始輸入%d門課的成績\n",N);
s=0;
for(i=0;i<N;i++)
{
do{
printf("第%d門分數:",i+1);
scanf("%d",&info->score[i]);
if(info->score[i]>100||info->score[i]<0)
printf("輸入成績錯誤,請重新輸入:\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;
}
void inputs(char *prompt,char *s,int count)
{
char p[255];
do
{
printf(prompt);
scanf("%s",p);
if(strlen(p)>count)
printf("\n太長了!\n");
}while(strlen(p)>count);
strcpy(s,p);
}
void print(STUDENT *h)
{
int i=0;
STUDENT *p;
p=h;
printf("\n\n\n***********************學生***********************\n");
printf("|序號|學號 | 姓名 | 語文 | 英語 |數學 | 總分 |平均分 |名次 |\n");
printf("|---|-------|--------|----|----|----|------|------|---|\n");
while(p!=NULL)
{
i++;
printf("|%3d |%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",i,p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("***********************end***********************\n");
}
STUDENT *del(STUDENT *h)
{
STUDENT *p,*q;
char s[11];
printf("請輸入要刪除的學生的學號\n");
scanf("%s",s);
q=p=h;
while(strcmp(p->no,s)&&p!=NULL)
{
q=p;
p=p->next;
}
if(p==NULL)
printf("\n鏈表中沒有學號為%s的學生\n",s);
else
{
printf("\n\n\n***********************找到了***********************\n");
printf("|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n");
printf("|----------|----------|----|----|----|------|------|---|\n");
printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("***********************end***********************\n");
printf("請按任意鍵刪除\n");
getchar();
if(p==h)
h=p->next;
else q->next=p->next;
free(p);
printf("\n已經刪除學號為%s的學生\n",s);
printf("不要忘了保存數據\n");
}
return h;
}
void search1(STUDENT *h)
{
STUDENT *p;
char s[11];
printf("請輸入你要查找的同學的學號\n");
scanf("%s",s);
p=h;
while(strcmp(p->no,s)&&p!=NULL)
p=p->next;
if(p==NULL)
printf("'n沒有學號為%s的學生\n",s);
else
{
printf("\n\n\n***********************找到了***********************\n");
printf("|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n");
printf("|----------|-----------|----|----|----|------|------|---|\n");
printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("***********************end***********************\n");
}
}
void search2(STUDENT *h)
{
STUDENT *p;
char s[11];
printf("請輸入你要查找的同學的姓名\n");
scanf("%s",s);
p=h;
while(strcmp(p->name,s)&&p!=NULL)
p=p->next;
if(p==NULL)
printf("\n沒有姓名為%s的學生\n",s);
else
{
printf("\n\n\n***********************找到了***********************\n");
printf("|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n");
printf("|----------|-----------|----|----|----|------|------|---|\n");
printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,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("請輸入插入點的學生學號\n");
scanf("%s",s);
printf("\n請輸入新的學生信息\n");
info=(STUDENT *)malloc(sizeof(STUDENT));
if(!info)
{
printf("\n內存不足!");
return NULL;
}
inputs("輸入學號:",info->no,11);
inputs("輸入姓名:",info->name,15);
printf("請輸入%d門課的分數\n",N);
s1=0;
for(i=0;i<N;i++)
{
do{
printf("分數%d",i+1);
scanf("%d",&info->score[i]);
if(info->score[i]>100||info->score[i]<0)
printf("輸入數據有誤,請重新輸入\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->no,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已經插入了%s這個學生\n",info->name);
printf("----不要忘了存檔啊--\n");
return(h);
}
void save(STUDENT *h)
{
FILE *fp;
STUDENT *p;
char outfile[10];
printf("請輸入保存文件的文件名,例如 c:\\f1\\te.txt:\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"wb"))==NULL)
{
printf("不能打開文件\n");
exit(1);
}
printf("\n正在保存......\n");
p=h;
while(p!=NULL)
{
fwrite(p,sizeof(STUDENT),1,fp);
p=p->next;
}
fclose(fp);
printf("------保存成功!!!------\n");
}
void sort(STUDENT *h)
{
int i=0,j;
STUDENT *p,*q,*t,*h1;
printf("請輸入要按哪門課程的編號來排序:(0.語文 1.數學 2.英語)\n");
scanf("%d",&j);
h1=h->next;
h->next=NULL;
while(h1!=NULL)
{
t=h1;
h1=h1->next;
p=h;
q=h;
while(t->score[j]<p->score[j]&&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;
}
print(h);
printf("排序成功!!!\n");
}
void tongji(STUDENT *h)
{
STUDENT *p;
int a,b,i;
printf("請輸入課程編號\n");
scanf("%d",&i);
printf("請輸入分數段:\n");
scanf("%d,%d",&a,&b);
p=h;
while(p!=NULL)
{
printf("\n\n\n***********************找到了***********************\n");
if(p->score[i]>=a&&p->score[i]<=b)
{
printf("|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n");
printf("|--------|---------|----|----|----|------|------|---|\n");
printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
}
p=p->next;
}
printf("***********************end***********************\n");
}

你可以改一下。希望對你有用

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

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

#include <stdlib.h>
#defineMAX1000

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

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


(7)學生成績管理系統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標准新增)

H. 用c語言實現一個簡單的學生成績管理系統,包括:學號,姓名,科目,成績

//用字元界面實現,比如按數字1,可以錄入學生所有信息;
//按數字2,顯示所有學生成績;
//按數字3,進入查詢,按學號或姓名查詢該學生是否存在,如果存在顯示他的所有信息,///否則給出不存在提示。
#include<stdio.h>
structstudent
{
charnum[6];/*學號*/
charname[10];
charsubject[20];/*科目*/
floatgrade;
}stu[10];
voidmenu()
{
printf("==================================== ");
printf("|學生成績管理系統| ");
printf("|1輸入學生成績| ");
printf("|2輸出學生成績| ");
printf("|3查詢學生成績| ");
printf("|0退出管理系統| ");
printf("==================================== ");
}
voidinput()
{
for(inti=0;i<10;i++)
scanf("%s%s%s%f",stu[i].num,stu[i].name,stu[i].subject,&stu[i].grade);
}
voidshow()
{
printf("學號 姓名 科目 成績 ");
for(inti=0;i<10;i++)
printf("%s %s %s %f ",stu[i].num,stu[i].name,stu[i].subject,stu[i].grade);
}
voidserach()
{
charobj[10];
printf("輸入要查詢的學號");
scanf("%s",obj);
for(inti=0;i<10;i++)
{
if(strcmp(obj,stu[i].num))
{
printf("學號 姓名 科目 成績 ");
printf("%s %s %s %f ",stu[i].num,stu[i].name,stu[i].subject,stu[i].grade);
}
}
}
intmain()
{
intselection;
while(true)
{
clrscr();
menu();
printf("請選擇0--3:");
scanf("%d",&selection);
switch(selection)
{
case1:input();break;
case2:show();break;
case3:search();break;
case0:exit(0);break;
default:printf("錯誤的輸入,請重新輸入:");
}
}
return0;
}

I. 學生成績管理系統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();
}
}

J. 學生成績管理系統(C語言)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#define NUM_SUBJECT 4
typedef struct zl
{
char no[5]; /*學號*/
char name[6]; /*姓名*/
int score[NUM_SUBJECT]; /*各門學科成績*/
float total; /*總分*/
float average; /*平均分*/
int order; /*名次*/
}STUDENT;
int REC_NUM=0; /*學生記錄數*/
char*subject[]={"數學","電腦","物理","電工學"};
char*menu[]={"**************MENU***************",
"1. Enter new record",
"2. Display record",
"3. Search record",
"4. Modify record",
"5. Delete a record to list",
"6. Add a record to list",
"7. Sort to make new file",
"8. Save the file",
"9. Load the file",
"10. Quit"};
STUDENT records[10];
void newRec();
void showTable();
void showTable2(Iint);
void display();
void searchRec();
void modifyRec();
void deleteRec();
void addRec();
void orderRec();
void sortRec();
void saveRec();
void loadRec();
void Rec(STUDENT*,STUDENT*);
void quit();
int menu_select();
int findRec(char*,int,int);
void main()
{
system("cls");
for(;;)
{
switch(menu_select())
{
case 1: newRec();break;
case 2: display();break;
case 3: searchRec();break;
case 4: modifyRec();break;
case 5: deleteRec();break;
case 6: addRec();break;
case 7: sortRec();break;
case 8: saveRec();break;
case 9: loadRec();break;
case 10: quit();
}
}
}

int menu_select()
{
char s[3];
int c,i;
for(i=0;i<11;i++)
{
printf("%s",menu[i]);
}
window(1,1,80,25);
do
{
printf(" Enter you choice(1-10):");
scanf("%s",s);
c=atoi(s);
}while(c<0||c>11);
return c;
}
void showTable1()
{
system("cls");
printf("*****************STUDENT INFORMATION****************");
printf("????D?D?D?D?D?D?D?D?D?D???\n");
printf("|Rec | No | Name | Computer | Physics | English | total | Average | Order\n");
printf("?¨¤?¨¤?¨¤?¨¤?¨¤?¨¤?¨¤?¨¨\n");
}
void showTable2(int n)
{
if(n==0)n=1;
if(REC_NUM==0)n=-1;
printf("??????????????????\n");
}
void quit()
{
char str[5];
printf("Save records?(Y/N)");
scanf("%s",str);
if(str[0]=='Y'||str[0]=='y')
saveRec();
exit(0);
}
void newRec()
{
int i, j, sum;
system("cls");
printf("Please input the REC_NUM:");
scanf("%d",&REC_NUM);
for(i=0;i<REC_NUM;i++)
{
system("cls");
sum=0;
for(j=0;j<NUM_SUBJECT;j++);
{
scanf("%d",&records[i].score[j]);
sum=sum+records[i].score[j];
}
records[i].total=sum;
records[i].average=records[i].total/NUM_SUBJECT;
records[i].order=0;
}
}
void display()
{
int i=0;
showTable1();
for(i=0;i<REC_NUM;i++)
{
printf("|%2d |%4s |6s?%4d | %4d | %4d | %5.1f | %5.1f | %2d \n",i+1,records[i].no,records[i].name,records[i].score[0],records[i].score[1],records[i].score[2],records[i].score[3],records[i].total,records[i].average,records[i].order);
}
showTable2(i);
printf("Press any key to return!");
getch();
}
void saveRec()
{
FILE*fp1,*fp2;
if((fp1=fopen("d:\\cjt\\tc\\lianxiti\\keshe\\keshe.dat","wb"))==NULL)
{
printf("Cannot open this file!");
exit(1);
}
if((fp2=fopen("d:\\cjt\\tc\\lianxiti\\keshe\\keshe.dat","wb"))==NULL)
{
printf("Cannot open this file!");
exit(1);
}

printf("\nSaving file......\n");
fwrite(&REC_NUM,sizeof(REC_NUM),1,fp2);
fwrite(records,sizeof(STUDENT),REC_NUM,fp1);
fclose(fp1);fclose(fp2);
printf("n\Save success!!\n");delay(1000);
printf("\nPress any key to return!");
getch();
}
void loadRec()
{
FILE*fp1,*fp2;
if((fp1=fopen("d:\\cjt\\tc\\lianxiti\\keshe\\keshe.dat","rb"))==NULL)
{
printf("Cannot open this file!");
exit(1);
}
if((fp2=fopen("d:\\cjt\\tc\\lianxiti\\keshe\\keshe.dat","rb"))==NULL)
{
printf("Cannot open this file!");
exit(1);
}
system("cls");
printf("\nLoading file.....\n");
fread(&REC_NUM,sizeof(REC_NUM),1,fp2);
fread(records,sizeof(STUDENT),REC_NUM,fp1);
fclose(fp1);fclose(fp2);
delay(2000);
printf("\nYou have success read date from file!!!\n");
printf("\press any key to return!");
getch();
}
void searchRec()
{
char str[20];
int i;
system("cls");
printf("Please input the number you want to get:");
scanf("%s",str);
i=findRec(str,1,0);
if(i!=-1)
{
printf("|%2d |%4s | 6s| %4d | %4d | %4d | %4d| %5.1f | %5.1f | %2d \n",i+1,records[i].no,records[i].name,records[i].score[0],records[i].score[1],records[i].score[2],records[i].score[3],records[i].total,records[i].average,records[i].order);
showTable2(0);
}
else printf("Not find!\n");
printf("Press any key to return!");
getch();
}

void deleteRec()
{
int i, j;
char str[20];
system("cls");
printf("Please input the number you want to delete:");
scanf("%S",str);
i=findRec(str,1,0);
for(j=i;j<REC_NUM;j++)
records[j]=records[j+1];
REC_NUM--;
saveRec();
}
void Rec(STUDENT*src,STUDENT*dest)
{
int i;
strcpy(dest->no,src->no);
strcpy(dest->name,src->name);
for(i=0;i<NUM_SUBJECT;i++)
dest->score[i]=src->score[i];
dest->total=src->total;
dest->average=src->average;
dest->order=src->order;
}
void orderRec()
{
int i;
records[0].order=1;
for(i=1;i<REC_NUM;i++)
if(records[i].total==records[i-1].total)
records[i].order=records[i-1].order;
else
records[i].order=i+1;
}
void sortRec()
{
int i,j,flag;
STUDENT t;
system("cls");
printf("\nsorting file\n");
for(i=0;i<REC_NUM;i++)
{
flag=0;
for(j=REC_NUM-1;j>i;j--)
if(records[j].total>records[j-1].total)
{
Rec(&records[j],&t);
Rec(&records[j-1],&records[j]);
Rec(&t,&records[j-1]);
flag=1;
}
if(!flag) break;
}
orderRec();
delay(2000);
printf("\nsorting success\n");
saveRec();
}

int findRec(char *target,int tarType,int from)
{
int i;
for(i=from;i<REC_NUM;i++)
{
if((tarType==1&&strcmp(target,records[i].no)==0)
||tarType==2&&strcmp(target,records[i].name)==0)
return(i);
}
return(-1);
}
void modifyRec()
{
int i,j,sum;
char no[20],str[8];
system("cls");
printf("Please input the number you want to modify:");
scanf("%s",no);
i=findRec(no,1,0);
showTable1();
printf("| %2d | %4s | 6s |%4d |%4d | %4d | %4d | %5.1f | %5.1f|%2d |\n",i+1,records[i].no,records[i].name,records[i].score[0],records[i].score[1],records[i].score[2],records[i].score[3],records[i].total,records[i].average,records[i].order);
showTable2(0);
printf("Do you wang to modify this student(Y/N):");
scanf("%s",str);
if(str[0]=='y'||str[0]=='Y')
{
printf("enter number:");scanf("%s",records[i].no);
printf("enter name:");scanf("%s",records[i].name);
sum=0;
for(j=0;j<NUM_SUBJECT;j++)
{
printf("%s:",subject[j]);
scanf("%d",&records[i].score[j]);
sum=sum+records[i].score[j];
}
records[i].total=sum;
records[i].average=records[i].total/NUM_SUBJECT;
records[i].order=0;
}
printf("Press any key to return!");
getch();
}

void addRec()
{
int i,j,sum=0;
char no[20],str[8];
for(;;)
{
system("cls");
printf("Please input the number you want to add:");
scanf("%s",str);
i=findRec(str,1,0);
if(i==-1)break;
else printf("This number is exist!\n");
getch();
}
strcpy(records[REC_NUM].no,str);
printf("enter name:");scanf("%s",records[REC_NUM].name);
for(j=0;j<NUM_SUBJECT;j++)
{
printf("%s:",subject[j]);
scanf("%d",&records[REC_NUM].score[j]);
sum=sum+records[REC_NUM].score[j];
}
records[REC_NUM].total=sum;
records[REC_NUM].average=records[REC_NUM].total/NUM_SUBJECT;
records[REC_NUM].order=0;
REC_NUM++;
saveRec();
}

熱點內容
武漢大學學生會輔導員寄語 發布: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