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

c實現學生成績管理系統

發布時間: 2021-01-30 02:18:18

『壹』 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';elsereturn'E';}

運行測試:

『叄』 c語言實現設計一個學生成績管理系統課程

參考代碼如下,不過還是建議自己寫一寫比較好:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct student //結構體
{
char name[20]; //姓名
char number[20]; //學號
double math; //數學
double english; //英語
double chinese; //語文
double program; //程序
}s[50];

void head() //界面
{
printf(
"**********************************************************************\n"
"** **\n"
"** **\n"
"** 學生成績管理系統 **\n"
"** **\n"
"** 1.信息錄入 **\n"
"** 2.信息統計 **\n"
"** 3.信息瀏覽 **\n"
"** 4.信息查詢 **\n"
"** 5.信息排序 **\n"
"** 6.信息刪除 **\n"
"** 0.退出系統 **\n"
"** **\n"
"**********************************************************************\n"
);
}
void ru(struct student s[], int* n) //文件導入函數
{
FILE *p;
int i=*n;
if((p=fopen("數據.txt", "r"))==NULL)
{
n=n;
}
else
{
while(!feof(p))
{
fscanf(p, "%s%s%lf%lf%lf%lf\n", s[i].name, s[i].number, &s[i].math, &s[i].english, &s[i].chinese, &s[i].program);
i++;
*n=*n+1;
}
}
fclose(p);
}
void chu(struct student s[], int n)
{
FILE *p;
int i=0;
if((p=fopen("數據.txt", "w"))==NULL)
{
printf("無法打開此文件!");
}
else
{
while(i<n-1)
{
fprintf(p, "%s %s %lf %lf %lf %lf\n", s[i].name, s[i].number, s[i].math, s[i].english, s[i].chinese, s[i].program);
i++;
}
fprintf(p, "%s %s %lf %lf %lf %lf", s[i].name, s[i].number, s[i].math, s[i].english, s[i].chinese, s[i].program);
}
fclose(p);
}
void dayin(struct student s[], int n) //顯示所有信息
{
int i;
double all=0.0;
printf("\n姓名\t\t學號\t\t數學\t英語\t語文\t程序\t總分\n");
for (i=0; i<n; i++)
{
all=s[i].math+s[i].english+s[i].chinese+s[i].program;
printf("%s\t\t%s\t\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n", s[i].name, s[i].number, s[i].math, s[i].english, s[i].chinese, s[i].program, all);
}
}
void shuru(struct student s[], int* n) //信息輸入函數
{
int i=*n, j, k, m;
printf("請輸入學生姓名:");
scanf("%s", s[i].name);
printf("請輸入學生學號:");
for (j=0; ; j++)
{
m=0;
scanf("%s", s[i].number);
for (k=0; k<i; k++)
{
if (strcmp(s[i].number, s[k].number)==0)
{
m=m+1;
printf("學號重復,請重新輸入學號:");
break;
}
}
if (m==0)
{
break;
}
}
printf("請輸入數學成績:");
scanf("%lf", &s[i].math);
printf("請輸入英語成績:");
scanf("%lf", &s[i].english);
printf("請輸入語文成績:");
scanf("%lf", &s[i].chinese);
printf("請輸入程序成績:") ;
scanf("%lf", &s[i].program);
printf("添加信息成功!\n");
*n=*n+1;
chu(s, *n);
}
void paixu(struct student s[], int n) //排序函數
{
int i, j;
double all1, all2;
struct student stu;
for (i=0; i<n-1; i++)
{
for (j=i+1; j<n; j++)
{
all1=s[i].math+s[i].english+s[i].chinese+s[i].program;
all2=s[j].math+s[j].english+s[j].chinese+s[j].program;
if (all1<all2)
{
stu=s[i];
s[i]=s[j];
s[j]=stu;
}
}
}
printf("排序後的數據:\n");
dayin(s, n);
}
void chazhao(struct student s[], int n) //查找函數
{
char name[20], num[20];
int m1, m2=0, i, j;
printf("1.按姓名查找\n2.按學號查找\n選擇查詢方式(1或2):");
scanf("%d", &m1);
if (m1==1)
{
printf("請輸入您要查找的學生姓名:");
scanf("%s", name);
for (i=0; i<n; i++)
{
if (strcmp(s[i].name, name)==0)
{
m2=m2+1;
if (m2==1)
{
printf("\n姓名\t\t學號\t數學\t英語\t語文\t程序\n");
}
printf("%s\t\t%s\t\t%s\t\t%s\t\t%s\n", s[i].name, s[i].number, s[i].math, s[i].english, s[i].chinese, s[i].program);
}
}
if (m2==0)
{
printf("沒有此學生信息!\n");
}
}
else if (m1==2)
{
printf("請輸入您要查找的學生學號:");
scanf("%s", num);
j=0;
for (i=0; i<n; i++)
{
if (strcmp(s[i].number, num)==0)
{
m2=m2+1;
if (m2==1)
{
printf("\n姓名\t\t學號\t數學\t英語\t語文\t程序\n");
}
printf("%s\t\t%s\t\t%s\t\t%s\t\t%s\n", s[i].name, s[i].number, s[i].math, s[i].english, s[i].chinese, s[i].program);
}
}
if (m2==0)
{
printf("沒有此學生信息!\n");
}
}
}
void shanchu(struct student s[], int* n) //刪除函數
{
char num[20];
int m=0, i, j;
printf("請輸入您要刪除的學生學號:");
scanf("%s", num);
for (i=0; i<=*n; i++)
{
if (strcmp(s[i].number, num)==0)
{
m=m+1;
for (j=i; j<*n; j++)
{
s[j]=s[j+1];
}
*n=*n-1;
}
}
if (m==0)
{
printf("沒有此學生信息!\n");
}
else
{
chu(s, *n);
printf("刪除完畢!\n");
}
}
void allAndAver(struct student s[], int n)
{
int i ;
double all=0.0, aver=0.0;
for (i=0; i<n; i++)
{
all=s[i].math+s[i].english+s[i].chinese+s[i].program;
aver=all/4;
printf("%s\t\t%s\t\t%.1lf\t%.1lf\n", s[i].name, s[i].number, all, aver);
}
}
void Fail(struct student s[], int n) //統計單科不及格人數
{
int i, fail[4]={0};
for (i=0; i<n; i++)
{
if (s[i].math<60)
{
fail[0]++;
}
if (s[i].english<60)
{
fail[1]++;
}
if (s[i].chinese<60)
{
fail[2]++;
}
if (s[i].program<60)
{
fail[3]++;
}
}
printf("\n不及格信息:\n");
printf("數學不及格的人數為:%d人\n", fail[0]);
printf("英語不及格的人數為:%d人\n", fail[1]);
printf("語文不及格的人數為:%d人\n", fail[2]);
printf("程序不及格的人數為:%d人\n", fail[3]);
}
void Max(struct student s[], int n) //統計單科最高分人數
{
int i, counter[4]={0};
double max[4]={s[0].math, s[0].english, s[0].chinese, s[0].program};
for (i=0; i<n; i++)
{
if (s[i].math>max[0])
{
max[0]=s[i].math;
}
if (s[i].math>max[1])
{
max[1]=s[i].math;
}
if (s[i].math>max[2])
{
max[2]=s[i].math;
}
if (s[i].math>max[3])
{
max[3]=s[i].math;
}
}
for (i=0; i<n; i++)
{
if (s[i].math==max[0])
{
counter[0]++;
}
if (s[i].math==max[1])
{
counter[1]++;
}
if (s[i].math==max[2])
{
counter[2]++;
}
if (s[i].math==max[3])
{
counter[3]++;
}
}
printf("\n最高分信息:\n");
printf("數學最高分為:%.1lf, 人數為:%d人\n", max[0], counter[0]);
printf("英語最高分為:%.1lf, 人數為:%d人\n", max[1], counter[1]);
printf("語文最高分為:%.1lf, 人數為:%d人\n", max[2], counter[2]);
printf("程序最高分為:%.1lf, 人數為:%d人\n", max[3], counter[3]);
}
void Min(struct student s[], int n) //統計單科最低分人數
{
int i, counter[4]={0};
double min[4]={s[0].math, s[0].english, s[0].chinese, s[0].program};
for (i=0; i<n; i++)
{
if (s[i].math<min[0])
{
min[0]=s[i].math;
}
if (s[i].math<min[1])
{
min[1]=s[i].math;
}
if (s[i].math<min[2])
{
min[2]=s[i].math;
}
if (s[i].math<min[3])
{
min[3]=s[i].math;
}
}
for (i=0; i<n; i++)
{
if (s[i].math==min[0])
{
counter[0]++;
}
if (s[i].math==min[1])
{
counter[1]++;
}
if (s[i].math==min[2])
{
counter[2]++;
}
if (s[i].math==min[3])
{
counter[3]++;
}
}
printf("\n最低分信息:\n");
printf("數學最低分為:%.1lf, 人數為:%d人\n", min[0], counter[0]);
printf("英語最低分為:%.1lf, 人數為:%d人\n", min[1], counter[1]);
printf("語文最低分為:%.1lf, 人數為:%d人\n", min[2], counter[2]);
printf("程序最低分為:%.1lf, 人數為:%d人\n", min[3], counter[3]);
}
void tongji(struct student s[], int n) //統計函數
{
printf("統計信息如下:\n");
printf("\n姓名\t\t學號\t\t總分\t平均分\n");
allAndAver(s, n);
Max(s, n);
Min(s, n) ;
Fail(s, n);
}
int main() //主函數
{
int k, n=0;
ru(s, &n);
chu(s, n);
while (1)
{
head();
printf("\n請按對應的鍵選擇相應的功能:");
scanf("%d",&k);
switch (k)
{
case 1:
shuru(s, &n);
break;
case 2:
tongji(s, n);
break;
case 3:
dayin(s, n);
break;
case 4:
chazhao(s, n);
break;
case 5:
paixu(s, n);
break;
case 6:
shanchu(s, &n);
break;
case 0:
exit(1);
break;
default : printf("請輸入正確的命令!\n");
}
system("pause");
system("cls");
}
return 0;
}

『肆』 用C語言實現學生成績管理系統的程序

我參考書里的一個程序:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
#define LEN sizeof(struct student)
#define FORMAT "%-8d%-15s%-12.1lf%-12.1lf%-12.1lf%-12.1lf\n"
#define DATA stu[i].num,stu[i].name,stu[i].elec,stu[i].expe,stu[i].requ,stu[i].sum
struct student/*定義學生成績結構體*/
{ int num;/*學號*/
char name[15];/*姓名*/
double elec;/*選修課*/
double expe;/*實驗課*/
double requ;/*必修課*/
double sum;/*總分*/
};
struct student stu[50];/*定義結構體數組*/
void in();/*錄入學生成績信息*/
void show();/*顯示學生信息*/
void order();/*按總分排序*/
void del();/*刪除學生成績信息*/
void modify();/*修改學生成績信息*/
void menu();/*主菜單*/
void insert();/*插入學生信息*/
void total();/*計算總人數*/
void search();/*查找學生信息*/
void main()/*主函數*/
{ int n;
menu();
scanf("%d",&n);/*輸入選擇功能的編號*/
while(n)
{ switch(n)
{ case 1: in();break;
case 2: search();break;
case 3: del();break;
case 4: modify();break;
case 5: insert();break;
case 6: order();break;
case 7: total();break;
default:break;
}
getch();
menu();/*執行完功能再次顯示菜單界面*/
scanf("%d",&n);
}
}

void in()/*錄入學生信息*/
{ int i,m=0;/*m是記錄的條數*/
char ch[2];
FILE *fp;/*定義文件指針*/
if((fp=fopen("data.txt","a+"))==NULL)/*打開指定文件*/
{ printf("can not open\n");return;}
while(!feof(fp)) {
if(fread(&stu[m] ,LEN,1,fp)==1)
m++;/*統計當前記錄條數*/
}
fclose(fp);
if(m==0)
printf("No record!\n");
else
{
system("cls");
show();/*調用show函數,顯示原有信息*/
}
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(i=0;i<m;i++) fwrite(&stu[i] ,LEN,1,fp);/*向指定的磁碟文件寫入信息*/
printf("please input(y/n):");
scanf("%s",ch);
while(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判斷是否要錄入新信息*/
{
printf("number:");scanf("%d",&stu[m].num);/*輸入學生學號*/
for(i=0;i<m;i++)
if(stu[i].num==stu[m].num)
{
printf("the number is existing,press any to continue!");
getch();
fclose(fp);
return;
}
printf("name:");scanf("%s",stu[m].name);/*輸入學生姓名*/
printf("elective:");scanf("%lf",&stu[m].elec);/*輸入選修課成績*/
printf("experiment:");scanf("%lf",&stu[m].expe);/*輸入實驗課成績*/
printf("required course:");scanf("%lf",&stu[m].requ);/*輸入必修課成績*/
stu[m].sum=stu[m].elec+stu[m].expe+stu[m].requ;/*計算出總成績*/
if(fwrite(&stu[m],LEN,1,fp)!=1)/*將新錄入的信息寫入指定的磁碟文件*/
{ printf("can not save!"); getch(); }
else { printf("%s saved!\n",stu[m].name);m++;}
printf("continue?(y/n):");/*詢問是否繼續*/
scanf("%s",ch);
}
fclose(fp);
printf("OK!\n");
}

void show()
{ FILE *fp;
int i,m=0;
fp=fopen("data.txt","rb");
while(!feof(fp))
{
if(fread(&stu[m] ,LEN,1,fp)==1)
m++;
}
fclose(fp);
printf("number name elective experiment required sum\t\n");
for(i=0;i<m;i++)
{
printf(FORMAT,DATA);/*將信息按指定格式列印*/
}
}

void menu()/*自定義函數實現菜單功能*/
{
system("cls");
printf("\n\n\n\n\n");
printf("\t\t|---------------------STUDENT-------------------|\n");
printf("\t\t|\t 0. exit |\n");
printf("\t\t|\t 1. input record |\n");
printf("\t\t|\t 2. search record |\n");
printf("\t\t|\t 3. delete record |\n");
printf("\t\t|\t 4. modify record |\n");
printf("\t\t|\t 5. insert record |\n");
printf("\t\t|\t 6. order |\n");
printf("\t\t|\t 7. number |\n");
printf("\t\t|-----------------------------------------------|\n\n");
printf("\t\t\tchoose(0-7):");
}

void order()/*自定義排序函數*/
{ FILE *fp;
struct student t;
int i=0,j=0,m=0;
if((fp=fopen("data.txt","r+"))==NULL)
{
printf("can not open!\n");
return;
}
while(!feof(fp))
if(fread(&stu[m] ,LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
if((fp=fopen("data.txt","wb"))==NULL)
{
printf("can not open\n");
return;}
for(i=0;i<m-1;i++)
for(j=i+1;j<m;j++)/*雙重循環實現成績比較並交換*/
if(stu[i].sum<stu[j].sum)
{ t=stu[i];stu[i]=stu[j];stu[j]=t;}
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(i=0;i<m;i++)/*將重新排好序的內容重新寫入指定的磁碟文件中*/
if(fwrite(&stu[i] ,LEN,1,fp)!=1)
{
printf("%s can not save!\n");
getch();
}
fclose(fp);
printf("save successfully\n");
}
void del()/*自定義刪除函數*/
{FILE *fp;
int snum,i,j,m=0;
char ch[2];
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp)) if(fread(&stu[m],LEN,1,fp)==1) m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
printf("please input the number:");
scanf("%d",&snum);
for(i=0;i<m;i++)
if(snum==stu[i].num)
break;
printf("find the student,delete?(y/n)");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判斷是否要進行刪除*/
for(j=i;j<m;j++)
stu[j]=stu[j+1];/*將後一個記錄移到前一個記錄的位置*/
m--;/*記錄的總個數減1*/
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(j=0;j<m;j++)/*將更改後的記錄重新寫入指定的磁碟文件中*/
if(fwrite(&stu[j] ,LEN,1,fp)!=1)
{ printf("can not save!\n");
getch();}
fclose(fp);
printf("delete successfully!\n");
}

void search()/*自定義查找函數*/
{ FILE *fp;
int snum,i,m=0;
char ch[2];
if((fp=fopen("data.txt","rb"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp)) if(fread(&stu[m],LEN,1,fp)==1) m++;
fclose(fp);
if(m==0) {printf("no record!\n");return;}
printf("please input the number:");
scanf("%d",&snum);
for(i=0;i<m;i++)
if(snum==stu[i].num)/*查找輸入的學號是否在記錄中*/
{ printf("find the student,show?(y/n)");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)
{
printf("number name elective experiment required sum\t\n");
printf(FORMAT,DATA);/*將查找出的結果按指定格式輸出*/
break;
}
}
if(i==m) printf("can not find the student!\n");/*未找到要查找的信息*/
}

void modify()/*自定義修改函數*/
{ FILE *fp;
int i,j,m=0,snum;
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1) m++;
if(m==0) {printf("no record!\n");
fclose(fp);
return;
}
printf("please input the number of the student which do you want to modify!\n");
scanf("%d",&snum);
for(i=0;i<m;i++)
if(snum==stu[i].num)/*檢索記錄中是否有要修改的信息*/
break;
printf("find the student!you can modify!\n");
printf("name:\n");
scanf("%s",stu[i].name);/*輸入名字*/
printf("\nelective:");
scanf("%lf",&stu[i].elec);/*輸入選修課成績*/
printf("\nexperiment:");
scanf("%lf",&stu[i].expe);/*輸入實驗課成績*/
printf("\nrequired course:");
scanf("%lf",&stu[i].requ);/*輸入必修課成績*/
stu[i].sum=stu[i].elec+stu[i].expe+stu[i].requ;
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(j=0;j<m;j++)/*將新修改的信息寫入指定的磁碟文件中*/
if(fwrite(&stu[j] ,LEN,1,fp)!=1)
{ printf("can not save!"); getch(); }
fclose(fp);
}

void insert()/*自定義插入函數*/
{ FILE *fp;
int i,j,k,m=0,snum;
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1) m++;
if(m==0) {printf("no record!\n");
fclose(fp);
return;
}
printf("please input position where do you want to insert!(input the number)\n");
scanf("%d",&snum);/*輸入要插入的位置*/
for(i=0;i<m;i++)
if(snum==stu[i].num)
break;
for(j=m-1;j>i;j--)
stu[j+1]=stu[j];/*從最後一條記錄開始均向後移一位*/
printf("now please input the new information.\n");
printf("number:");
scanf("%d",&stu[i+1].num);
for(k=0;k<m;k++)
if(stu[k].num==stu[i+1].num)
{
printf("the number is existing,press any to continue!");
getch();
fclose(fp);
return;
}
printf("name:\n");
scanf("%s",stu[i+1].name);
printf("\nelective:");
scanf("%lf",&stu[i+1].elec);
printf("\nexperiment:");
scanf("%lf",&stu[i+1].expe);
printf("\nrequired course:");
scanf("%lf",&stu[i+1].requ);
stu[i+1].sum=stu[i+1].elec+stu[i+1].expe+stu[i+1].requ;
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(k=0;k<=m;k++)
if(fwrite(&stu[k] ,LEN,1,fp)!=1)/*將修改後的記錄寫入磁碟文件中*/
{ printf("can not save!"); getch(); }
fclose(fp);
}

void total()
{ FILE *fp;
int m=0;
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1)
m++;/*統計記錄個數即學生個數*/
if(m==0) {printf("no record!\n");fclose(fp);return;}
printf("the class are %d students!\n",m);/*將統計的個數輸出*/
fclose(fp);
}

『伍』 c語言編程 實現簡單的學生成績管理系統

出密碼模塊外其他的都可以!我也想添個密碼的!
後來覺得沒用,先做好功能模塊再說!
密碼模塊設計不好的話,很容易被破解的!
#ifndef H_STUDENT_HH /*xxx如果沒有定義xxx*/
#define H_STUDENT_HH /*xxx定義xx*/

#include "stdio.h"
#include "string.h"
#include "malloc.h"

#define LEN sizeof(struct message_student) /*一個結構體數組元素的長度*/
#define numsubs 5 /*學科數目*/
typedef struct message_student /*結構體定義*/
{
char number[6];
char name[20];
char sex[4];
float subject[numsubs];
float score;
float average;
int index;
}student;

extern int numstus; /*學生數目*/
extern student *pointer; /*指向結構體數組*/
extern int lens;

int menu_select(); /*函數聲明*/
int openfile(student stu[]);
int findrecord(student stud[]);
int writetotext(student stud[]);
void welcome();
void display1();
void showtable();
void sort(student stu[]);
void deleterecord(student stu[],int i);
void addrecord(student stud[]);
void display(student stud[],int n1,int n2);
void amendrecord(student stud[]);
void count(student stud[]);
void sortnum(student stud[]);
void sortnum2(student stud[]);
void sortname(student stud[]);
void sortname2(student stud[]);
void sortcount(student stud[]);
void sortcount2(student stud[]);
void statistic(student stud[]);
void display1();

#endif

#include "stdio.h"
int menu_select()
{
char c;
printf("\n\n");
printf(" | 1. 增加學生記錄 5.統計信息 |\n");
printf(" | 2. 查詢學生記錄 6.打開文件 |\n");
printf(" | 3. 修改學生記錄 7.保存文件 |\n");
printf(" | 4. 學生紀錄排序 8.顯示記錄 |\n");
printf(" | 0.退出系統 |\n");
printf("\n\n");
printf("請選擇(0-8):");
c=getchar();
getchar();
return (c-'0');
}

#include "stdio.h"
int findrecord(student stud[]) /*查找信息*/
{
char str[2];
int i,num;
if(numstus==0)
{
printf("沒有可被查找的記錄\n");
return -1;
}
else
{
printf("以何種方式查找?\n1.學號\t2.姓名\t3.名次\n");
gets(str);
if(str[0]=='1') /*按學號查找*/
{
printf("請輸入學號:");
gets(str);
for(i=0;i<=numstus;i++)
if(strcmp(str,stud[i].number)==0)
{
display(stud,i,i);
break;
}
else continue;
}
else if(str[0]=='2') /*按姓名查找*/
{
printf("請輸入姓名:");
gets(str);
for(i=0;i<=numstus;i++)
if(strcmp(str,stud[i].name)==0)
{
display(stud,i,i);
break;
}
else continue;
}
else if(str[0]=='3') /*按名次查找*/
{
printf("請輸入名次:");
scanf("%d",&num);
getchar();
for(i=0;i<=numstus;i++)
if(num==stud[i].index)
{
display(stud,i,i);
break;
}
else continue;
}
if(i>numstus)
{
printf("沒有查找所要的信息。\n");
return -1;
}
return i;
}
}

#include"stdio.h"
int openfile(student stu[])
{
int i=0,j;
FILE *fp;
char filename[20],str[2];
if(numstus!=0)
{
printf("已經有記錄存在,是否保存?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
writetotext(stu);
}
printf("請輸入文件名:");
gets(filename);
numstus=0;
if((fp=fopen(filename,"rb+"))==NULL)
{
printf("無法打開該文件\n");
return(-1);
}
fscanf(fp,"%d",&numstus);
fgetc(fp);
while(i<numstus)
{
fscanf(fp,"%s",stu[i].number);
fscanf(fp,"%s",stu[i].name);
fscanf(fp,"%s",stu[i].sex);
for(j=0;j<numsubs;j++)
fscanf(fp,"%f",&stu[i].subject[j]);
fscanf(fp,"%f",&stu[i].score);
fscanf(fp,"%f",&stu[i].average);
fscanf(fp,"%d",&stu[i].index);
i++;
}
fclose(fp);
printf("文件讀取成功\n");
printf("是否顯示紀錄?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
display(stu,0,numstus-1);
return(0);
}
#include "stdio.h"
void sort(student stud[])
{
int i,j=0;
char str[5];
student *p;
p=stud;
if(numstus==0)
{
printf("沒有可供查詢的記錄!");
}
while(1)
{
for(i=0;;i++)
{
printf(" 請輸入查詢方式:");
printf("(直接輸入回車則結束查詢操作)\n");
printf("1.按照學號\t");
printf("2.按照姓名\t");
printf("3.按照名次\n");
gets(str);
if(strlen(str)==0) break;
if(str[0]=='1')
{
printf("請輸入排序次序:\n");
printf("1.升序排列\t");
printf("2.降序排列\n");
gets(str);
if(str[0]=='1')
sortnum2(p);
else
sortnum(p);
display(stud,0,numstus-1);
}
else if(str[0]=='2')
{
printf("請輸入排序次序:\n");
printf("1.升序排列\t");
printf("2.降序排列\n");
gets(str);
if(str[0]=='1')
sortname2(p);
else
sortname(p);
display(stud,0,numstus-1);
}
else if(str[0]=='3')
{
printf("請輸入排序次序:\n");
printf("1.升序排列\t");
printf("2.降序排列\n");
gets(str);
if(str[0]=='1')
sortcount2(p);
else
sortcount(p);
display(stud,0,numstus-1);
}
else printf("請輸入1~3");
printf("是否退出排序?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y') break;
}
return;
}
}
void sortnum(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(strcmp(stud[j+1].number,stud[j].number)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortnum2(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(strcmp(stud[j].number,stud[j+1].number)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortname(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(strcmp(stud[j+1].name,stud[j].name)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortname2(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(strcmp(stud[j].name,stud[j+1].name)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortcount(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(stud[j+1].index>stud[j].index)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortcount2(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(stud[j].index>stud[j+1].index)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
#include"stdio.h"
void statistic(student stud[]) /*新增功能,輸出統計信息*/
{
int i,j=0,k=0;
char c1,str[2];
float average[numsubs],sum=0;
if(numstus==0)
printf("沒有可被查找的記錄\n");
else
{
while(1)
{
printf("下面將統計考試成績\n");
printf("請選擇你要統計哪科的成績 1.A\t2.B\t3.C\t4.D\t5.E\n");
c1=getchar();
printf("\t一共有個%d記錄\n",numstus); /*總共記錄數*/
switch(c1)
{
case '1':
for(i=0;i<numstus;i++) /*循環輸入判斷*/
{
sum+=stud[i].subject[0];
if(stud[k].subject[0]>stud[i].subject[0]) k=i;
if(stud[j].subject[0]<stud[i].subject[0]) j=i;
}
average[0]=sum/numstus;
printf("\t科目A的最高分:\n"); /*最高分*/
printf("\t\t學號:%s 姓名:%s 分數:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[0]);
printf("\t科目A的最低分是:\n"); /*最低分*/
printf("\t\t學號:%s 姓名:%s 分數:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[0]);
printf("\t科目A的平均分是 %5.2f\n",average[0]); /*平均分*/
break;
case '2':
for(i=0;i<numstus;i++) /*循環輸入判斷*/
{
sum+=stud[i].subject[1];
if(stud[k].subject[1]>stud[i].subject[1]) k=i;
if(stud[j].subject[1]<stud[i].subject[1]) j=i;
}
average[1]=sum/numstus;
printf("\t科目B的最高分:\n"); /*最高分*/
printf("\t\t學號:%s 姓名:%s 分數:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[1]);
printf("\t科目B的最低分是:\n"); /*最低分*/
printf("\t\t學號:%s 姓名:%s 分數:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[1]);
printf("\t科目B的平均分是 %5.2f\n",average[1]); /*平均分*/
break;
case '3':
for(i=0;i<numstus;i++) /*循環輸入判斷*/
{
sum+=stud[i].subject[2];
if(stud[k].subject[2]>stud[i].subject[2]) k=i;
if(stud[j].subject[2]<stud[i].subject[2]) j=i;
}
average[2]=sum/numstus;
printf("\t科目C的最高分:\n"); /*最高分*/
printf("\t\t學號:%s 姓名:%s 分數:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[2]);
printf("\t科目C的最低分是:\n"); /*最低分*/
printf("\t\t學號:%s 姓名:%s 分數:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[2]);
printf("\t科目C的平均分是 %5.2f\n",average[2]); /*平均分*/
break;
case '4':
for(i=0;i<numstus;i++) /*循環輸入判斷*/
{
sum+=stud[i].subject[3];
if(stud[k].subject[3]>stud[i].subject[3]) k=i;
if(stud[j].subject[3]<stud[i].subject[3]) j=i;
}
average[3]=sum/numstus;
printf("\t科目D的最高分:\n"); /*最高分*/
printf("\t\t學號:%s 姓名:%s 分數:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[3]);
printf("\t科目D的最低分是:\n"); /*最低分*/
printf("\t\t學號:%s 姓名:%s 分數:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[3]);
printf("\t科目D的平均分是 %5.2f\n",average[3]); /*平均分*/
break;
case '5':
for(i=0;i<numstus;i++) /*循環輸入判斷*/
{
sum+=stud[i].subject[4];
if(stud[k].subject[4]>stud[i].subject[4]) k=i;
if(stud[j].subject[4]<stud[i].subject[4]) j=i;
}
average[4]=sum/numstus;
printf("\t科目E的最高分:\n"); /*最高分*/
printf("\t\t學號:%s 姓名:%s 分數:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[4]);
printf("\t科目E的最低分是:\n"); /*最低分*/
printf("\t\t學號:%s 姓名:%s 分數:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[4]);
printf("\t科目E的平均分是 %5.2f\n",average[4]); /*平均分*/
break;
default:printf("輸入錯誤!請輸入1~5之間的數\n");
}
sum=0;
getchar();
printf("是否繼續進行統計?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y') ;
else break;
}
}
}

#include"stdio.h"
int writetotext(student stud[]) /*將所有記錄寫入文件*/
{
int i=0,j;
FILE *fp;
char filename[20];
printf("輸入文件名稱:");
gets(filename);
fp=fopen(filename,"w");
fprintf(fp,"%d\n",numstus);
while(i<numstus)
{
fprintf(fp,"%s %s %s ",stud[i].number,stud[i].name,stud[i].sex);
for(j=0;j<numsubs;j++)
fprintf(fp,"%f ",stud[i].subject[j]);
fprintf(fp,"%f %f %d ",stud[i].score,stud[i].average,stud[i].index);
i++;
}
fclose(fp);
printf("已成功存儲!\n");
display(stud,0,numstus-1);
numstus=0;
return 0;
}

#include"stdio.h"
void welcome()
{
printf("\t*************************************************************\n");
printf("\t\t\t\t歡迎進入學生成績管理系統\t\t\t\t\t\t\t\t 曉 歡迎使用!\n");
printf("\t*************************************************************\n");
printf("\t\t\t\t\t\t本系統由「曉」一組親情製作\n\n");
printf("\t\t\t\t\t\t製作人員列表: \n");
printf("\t\t\t\t\t\t吳彥兵 黃進 汪紅波\n\t\t\t\t\t\t劉玉蕭 楊超 章耀\n");
printf("輸入回車進入菜單欄:\n");
printf("\n\n");
getchar();
}

void showtable()
{
printf("-------------------------------------------------------------------------------\n");
printf("學號\t姓名\t性別\tA\tB\tC\tD\tE 總分 平均分 名次\n");
printf("-------------------------------------------------------------------------------\n");
}

void display(student stud[],int n1,int n2)
{
int i;
showtable(); /*顯示表頭*/
for(i=n1;i<=n2;i++)
printf("%s\t%s\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f %.1f %.1f %d\t\n",stud[i].number,stud[i].name,stud[i].sex,stud[i].subject[0],stud[i].subject[1],stud[i].subject[2],stud[i].subject[3],stud[i].subject[4],stud[i].score,stud[i].average,stud[i].index);
/*通過循環輸出數據*/

}
void display1()
{
printf("\t\t本系統由曉一組親情製作\n\n");
printf("\t\t製作人員列表: \n");
printf("\t\t\t\t\t\t吳彥兵 黃進 汪紅波\n\t\t\t\t\t\t劉玉蕭 楊超 章耀\n");
printf("\t\t\t=========歡迎下次使用=========");
printf("\n\n");
getchar();
}

#include"stdio.h"
#include<string.h>
void amendrecord(student stud[])
{
char str[5]; /*供用戶輸入*/
int i=-1,j;

if(numstus==0) /*沒有記錄返回*/
printf("沒有可供修改的記錄!");
while(i<0)
{
i=findrecord(stud);
if(i>=0)
{
printf("要刪除這個學生的信息嗎?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
{
deleterecord(stud,i);
count(stud);
}
else
{
printf("確定要修改這個學生的信息嗎?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
{

printf("下面請重新輸入學生的信息:\n");
printf("請輸入學號:");
gets(stud[i].number);
printf("請輸入姓名:");
gets(stud[i].name);
printf("請輸入性別(男/女 1/0):");
gets(str);
if(str[0]=='0')
strcpy(stud[i].sex,"女");
else
strcpy(stud[i].sex,"男");
stud[i].score=0;
printf("請按順序輸入成績:");
for(j=0;j<numsubs;j++)
{
scanf("%f",&stud[i].subject[j]);
stud[i].score+=stud[i].subject[j];
}
getchar();
stud[i].average=stud[i].score/numsubs;
}
count(stud);
}
display(stud,0,numstus-1);
}
printf("是否繼續進行其他修改?(y/n)\n");
gets(str);
if(str[0]=='y'||str[0]=='Y')
i=-1;
else i=1;
}
}

void deleterecord(student stu[],int i) /*刪除信息*/
{
int j;

while(i>=0)
{
for(j=i;j<numstus;j++)
stu[j]=stu[j+1];
numstus--;
printf("刪除成功!\n");

}
}

void count(student stud[])
{
int i,j;
for(i=0;i<numstus;i++)
{
stud[i].index=1;
for(j=0;j<numstus;j++)
if(stud[j].score>stud[i].score)
stud[i].index++;
}
}

#include "stdio.h"
void addrecord(student stud[])
{
int i=0,j,num;
char str[5];
if(numstus!=0)
{
printf("已有記錄存在是否覆蓋?(y/n)\n");
gets(str);
if(str[0]=='Y'||str[0]=='y')
i=0;
else i=numstus;
}

printf("請輸入增加的學生信息條目數:");
scanf("%d",&num);
if(i==0)
numstus=num;
else numstus+=num;
if(numstus>lens)
{
lens+=50;
pointer=(student *)realloc(pointer,lens*LEN);
}
printf("請輸入學生信息:\n");
for(;i<numstus;i++)
{
getchar();
printf("請輸入學號:");
gets(pointer[i].number);
printf("請輸入姓名:");
gets(pointer[i].name);
printf("請輸入性別(男/女 1/0):");
gets(pointer[i].sex);
if(pointer[i].sex[0]=='0') strcpy(pointer[i].sex,"女");
else strcpy(pointer[i].sex,"男");
printf("請輸入各科成績:(按ABCDE的順序):");
stud[i].score=0;
for(j=0;j<numsubs;j++)
{
scanf("%f",&stud[i].subject[j]); /*計算總分*/
stud[i].score+=stud[i].subject[j];
}
stud[i].average=stud[i].score/numsubs; /*計算平均分*/
}
count(stud); /*附名次*/
display(stud,0,numstus-1);
getchar();
}
#include "stdio.h"
int numstus;
int lens;
student *pointer;
void main()
{
int i=1;
char str[2];
lens=100;
pointer=(student *)malloc(lens*LEN); /*分配內存*/
numstus=0;
welcome(); /*歡迎界面*/
while(i>0)
{
i=menu_select(); /*控制菜單*/
switch(i)
{
case 1:addrecord(pointer);break; /*增加學生信息*/
case 2:findrecord(pointer);break; /*查詢學生信息*/
case 3:amendrecord(pointer);break; /*修改學生信息*/
case 4:sort(pointer);break; /*學生信息排序*/
case 5:statistic(pointer);break; /*統計信息*/
case 6:openfile(pointer);break; /*打開文件*/
case 7:writetotext(pointer);break; /*保存文件*/
case 8:display(pointer,0,numstus-1);break; /*顯示記錄*/
case 0:
if(numstus!=0) printf("是否保存當前記錄?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
writetotext(pointer);
i=-1;break; /*退出系統*/
default:printf("請輸入數字0~8:\n");i=1; /*輸入錯誤*/
}
}
printf("\t\t======歡迎再次使用本系統======= \n");
display1();
}

『陸』 C語言 順序線性表 實現學生成績管理系統

/***************************頭文件*********************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/***************************常量***********************************/
#define MENU_NUM 10
#define N 3
/****************************結構體********************************/
typedef struct s1
{
char no[10] ; //學號由10個字元組成
char name[15] ; //學生姓名
float score[N] ; //各門課成績
float sum ; //總分
float average ; //平均分
struct s1 *next ; //指向後繼結點的指針
}STUDENT; //定義結構體類型
/********************************全局變數*************************/
struct s1 * head=NULL; //鏈表頭結點
/********************************函數聲明*************************/
void InputData( STUDENT * ptr ); //錄入信息
void PrintMenu( ); //顯示菜單
int MenuSelect( ); //選擇菜單項
void Init( ); //初始化
void create( ); //創建鏈表
void print( ) ; //列印鏈表數據
void Delete( ); //刪除指定學號的記錄數據
void append(); //追加一個數據到鏈表尾部
void computer(); //計算鏈表中所有人的總分和平均分
/***********************************主函數********************************/
void main()
{
int key;
while(1) {
key=MenuSelect();
switch(key)
{
case 1:
Init(); //初試化鏈表。也就是若鏈表不為空則釋放鏈表中所有數據,將head置為空(NULL)
break;
case 2:
create(); //創建鏈表,輸入數據
break;
case 3:
Delete(); //刪除一個指定學號的記錄數據
break;
case 4:
print(); //列印鏈表中所有數據
break;
case 5:
computer(); //計算鏈表中所有人的總分和平均分
break;
case 6:
append(); //追加一個數據到鏈表的尾部
break;
case 7:
Init(); //釋放鏈表
exit(0);
}
}
}
/*****************************************************************
*函數名:PrintMenu
*
*描 述:顯示操作菜單*
*
*入口參數:無
*
*出口參數:無
******************************************************************/
void PrintMenu( )
{
int i;
char * menu[]={
"-----------------------------------------------",
"| 基於指針和鏈表的學生成績管理系統 |",
"| 1. 初始化鏈表 |",
"| 2. 創建鏈表 |",
"| 3. 刪除指定學號的記錄 |",
"| 4. 列印學生成績信息 |",
"| 5. 計算學生的總分和平均分 |",
"| 6. 插入一條學生記錄 |",
"| 7. 退出 |",
"-----------------------------------------------",
};
printf("\n\n");
for (i=0;i<MENU_NUM;i++)
printf("%s\n",menu[i]);
printf("\n輸入要進行的操作(1-7):");
}
/*****************************************************************
*函數名:MenuSelect
*
*描 述:選擇菜單選項,返回選擇的選項
*
*入口參數:無
*
*出口參數:整型數據
******************************************************************/
int MenuSelect( )
{
int key;
PrintMenu( );
scanf("%d",&key);
return key;
}
/*****************************************************************
*函數名:Init
*
*描 述:初始化單鏈表。也就是釋放鏈表中的所有數據
*
*入口參數:無
*
*出口參數:無
******************************************************************/
void Init( )
{
STUDENT *p,*ptr; //定義兩個臨時指針變數p,ptr
p=head;
ptr=head; //將兩個臨時變數指向頭指針head ;
while(ptr!=NULL)
{
ptr=ptr->next; //ptr指向下一個結構數據
free(p); //釋放p所指向的結構數據的內存
p=ptr; //將p指向ptr所指向的數據
}
head=NULL; //將head指向NULL
}
/*****************************************************************
*函數名:create
*
*描 述:創建單鏈表
*
*入口參數:無
*
*出口參數:無
******************************************************************/
void create( )
{
STUDENT *pt, *pth=NULL; //定義兩個指針變數:pt指向即將申請新的數據內存,pth指向當前數據
while(1)
{
pt=(STUDENT *)malloc(sizeof(STUDENT)); //讓pt指向新申請的內存空間
InputData(pt); //輸入數據,存放到pt所指向的結構數據。注意讓pt的next指向NULL
if (strcmp(pt->no,"@")==0)
{
free(pt); //釋放pt所指向的內存空間
break; //退出循環
}
else if (head==NULL)
{
pth=pt;
head=pt; //將頭指針head和pth指向pt
}
else
{
pth->next=pt; //將pth的next指向pt;
pth=pt; //將pth指向pt;
}
}
}
/*****************************************************************
*函數名:print
*
*描 述:列印單鏈表中所有數據
*
*入口參數:無
*
*出口參數:無
******************************************************************/
void print( )
{
int i=0;
STUDENT *p; //第一個指針p
p=head; //將p指向head
printf("\n");
printf("******************************STUDENT******************************\n");
printf("|rec| 學號 | 姓名 | 成績1| 成績2| 成績3|總成績| 平均成績|\n");
printf("|---|----------|------------|------|------|------|------|---------|\n");
//列印表頭
while (p!=NULL)
{
printf("|%3d|%10s|%-12s|%6.1f|%6.1f|%6.1f|%6.2f|%9.1f|\n",
++i,p->no,p->name,p->score[0],p->score[1],p->score[2],
p->sum,p->average); //列印p所指向的結構中的所有數據。注意列印數據間的分隔線
p=p->next; //將p指向p的下一個結構數據
}
printf("********************************END********************************\n");
//列印表尾
}
/*****************************************************************
*函數名:Delete
*
*描 述:刪除指定學號的記錄
*
*入口參數:無
*
*出口參數:無
******************************************************************/
void Delete( )
{
STUDENT *p,*pth; //定義兩個指針p,pth
char no[11]; //定義一個整數no(用來存儲輸入的學號)
printf("輸入要刪除學生的學號:");
scanf("%s",no); //用輸入語句輸入一個學號存儲到no中
p=head;pth=head; //將p和pth都指向頭指針
if (strcmp(p->no,no)==0) //也就是若頭指針指向的數據需要刪除
{
head=head->next; //將head指針指向head的下一個數據;
free(p); //釋放p所指向的數據
}
else
{
p=p->next; //將p指向p的下一個數據
while ( p!=NULL)
{
if (strcmp(p->no,no)==0) //找到了要刪除的數據
{
pth->next=p->next; //將pth的next指向p的next
free(p); //釋放p
break; //退出循環
}
else
{
pth=pth->next; //將pth指向pth的next 或 將pth指向p
p=p->next; //將p指向p的next
}
}
}
}
/*****************************************************************
*函數名:append
*
*描 述:增加學生記錄
*
*入口參數:無
*
*出口參數:無
******************************************************************/
void append()
{
STUDENT *p,*pth; //定義兩個指針變數p,pth
pth=head; //將pth指向head
while ( pth->next!=NULL)
{
pth=pth->next; //ptr指向ptr的next
}
p=(STUDENT *)malloc(sizeof(STUDENT)); //將p指向新申請的內存空間
InputData(p);
p->next=NULL; //數據數據存儲到p所指向的內存空間,注意將p的next置為NULL
pth->next=p; //將ptr的next指向p
}
/*****************************************************************
*函數名:InputData
*
*描 述:輸入學生信息
*
*入口參數:指針
*
*出口參數:無
******************************************************************/
void InputData( STUDENT *ptr )
{
int i;
printf("輸入學號:");
scanf("%s",ptr->no);
if (strcmp(ptr->no,"@")==0 )
return;
printf("輸入姓名:");
scanf("%s",ptr->name);
for(i=0;i<3;i++)
{
printf("輸入成績:");
scanf("%f",&ptr->score[i]);
}
ptr->sum=0;
ptr->average=0;
ptr->next=NULL; //不要忘記這一步
}
/*****************************************************************
*函數名:computer
*
*描 述:計算學生總成績和平均成績
*
*入口參數:無
*
*出口參數:無
******************************************************************/
void computer()
{
STUDENT *p;
p=head;
for(;p;p=p->next)
{
p->sum=p->score[0]+p->score[1]+p->score[2];
p->average=(p->score[0]+p->score[1]+p->score[2])/3;
}
}

『柒』 用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;
}

『捌』 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語言實現學生成績管理系統

#include "stdio.h"
#include "time.h"
#include "stdlib.h"
#include"string.h"
#define N 100
void zhuomian();
void csh(struct stu *a,int n);
void csh1(struct stu *a,int n);
void input(struct stu *a,int n);
void output(struct stu *a,int n);
void npaixu(struct stu *a,int n);
void spaixu(struct stu *a,int n);
void Cpaixu(struct stu *a,int n);
void Apaixu(struct stu *a,int n);
void Dpaixu(struct stu *a,int n);
void shousu(struct stu *a,int n);
void shanchu(struct stu *a,int n);
void xiugai(struct stu *a,int n);
void baocun(struct stu *a,int n);
void qu(struct stu *a,int n);
void tuichu();
char ymi[8]="12345678";
static int m=0;
struct stu
{
char name[20];
char num[20];
char sex;
int age;
float score[3];
float sum;
float averge;
};
void main()
{
int i,a,c;
int f=0,m=0;
char mi[20];
struct stu b[N];
do
{
printf("\n\n\n");
printf("\t* * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("\t* *\n");
printf("\t* 學生管理系統 *\n");
printf("\t* *\n");
printf("\t* 歡迎使用!! *\n");
printf("\t* *\n");
printf("\t* * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("\t註:輸入密碼的長度小於20位數,否擇自動登陸!\n");
printf("\t請輸入管理員密碼:");
for(i=0;i<20;i++)
{
mi[i]=getch();
printf("*");
if(mi[i]=='\x0d')
{
mi[i]='\0';
break;
}
}
printf("\n\t請稍後,正在登陸進入系統");
for(i=0;i<15;i++)
{
printf(".");
_sleep(250);
}
if(strcmp(mi,ymi)==0)
{
f=1;
printf("\n\t密碼正確,馬上進入系統!\n");
for(i=0;i<10;i++)
{
printf("\t");
_sleep(150);
}
break;
}
else
{
system("cls");
printf("\n密碼錯誤,請重新輸入!\n");
m++;
}
}while(m<3);
if(f==0)
{
printf("你已經連續3次輸入錯誤,任意鍵自動退出\n");
exit(0);
}
system("cls");
while (1)
{
zhuomian();
scanf("%d",&a);
getchar();
switch(a)
{
case 1:
{
system("cls");
csh(b,N);
}break;
case 2:
{
do
{
system("cls");
printf("\t\t\t* * * * * * * * * * * * * * * * * *\n");
printf("\t\t\t*<1>按學號排列!! *\n");
printf("\t\t\t*<2>按總分排列!! *\n");
printf("\t\t\t*<3>按C語言排序!! *\n");
printf("\t\t\t*<4>按Access排序!! *\n");
printf("\t\t\t*<5>按Dreamweaver排序!! *\n");
printf("\t\t\t*<0>返回上一層! *\n");
printf("\t\t\t*請選擇(0~5): *\n");
printf("\t\t\t* * * * * * * * * * * * * * * * * *\n");
scanf("\t\t\t%d",&c);
switch(c)
{
case 1:
{
system("cls");
npaixu(b,N);
output(b,N);
printf("任意鍵退出....");
getch();
}break;
case 2:
{
system("cls");
spaixu(b,N);
output(b,N);
printf("任意鍵退出....");
getch();
}break;
case 3:
{
system("cls");
Cpaixu(b,N);
output(b,N);
printf("任意鍵退出....");
getch();
}break;
case 4:
{
system("cls");
Apaixu(b,N);
output(b,N);
printf("任意鍵退出....");
getch();
}break;
case 5:
{
system("cls");
Dpaixu(b,N);
output(b,N);
printf("任意鍵退出....");
getch();
}break;
case 0:system("cls");break;
default:system("cls");break;
}
}while(c!=0);
}break;
case 3:
{
system("cls");
shousu(b,N);
}break;
case 4:
{
system("cls");
output(b,N);
printf("任意鍵退出....");
getch();
}break;
case 5:
{
system("cls");
input(b,N);
printf("增加記錄完畢!!\n");
}break;
case 6:
{
system("cls");
shanchu(b,N);
}break;
case 7:
{
system("cls");
xiugai(b,N);
}break;
case 8:
{
baocun(b,N);
}break;
case 9:
{
qu(b,N);
}break;
case 0:tuichu();break;
default:printf("不存在,請選擇(0~9)!! \n");break;
}
}
}
void zhuomian()
{
system("cls");
printf("\n\n\n");
printf("\t\t+--------------------------------------------+\n");
printf("\t\t| 學生成績管理系統 |\n");
printf("\t\t+--------------------------------------------+\n");
printf("\t\t| 1、初始化或追加一條記錄 |\n");
printf("\t\t+--------------------------------------------+\n");
printf("\t\t| 2、按排序輸出 |\n");
printf("\t\t| 3、收索記錄 |\n");
printf("\t\t| 4、瀏覽記錄(不排序) |\n");
printf("\t\t+--------------------------------------------+\n");
printf("\t\t| 5、插入記錄 6、刪除記錄 |\n");
printf("\t\t| 7、修改記錄 |\n");
printf("\t\t+--------------------------------------------+\n");
printf("\t\t| 8、保存記錄 9、讀取記錄 |\n");
printf("\t\t| 0、退出 |\n");
printf("\t\t+--------------------------------------------+\n");
printf("\t\t請選擇(0~9):");
}
void csh(struct stu *a,int n)
{
int i,c=0;
int h=0;
for(i=m;i>0;i--)
{
a[i]=a[i+1];
m--;
}
printf("初始化完畢!是否增加新記錄(1/0)!");
scanf("%d",&c);
if(c==1)
{
for(i=m;i<n;i++)
{
printf("請輸入學號:\n");
scanf(" %s",a[i].num);
printf("姓名:\n");
scanf(" %s",a[i].name);
printf("性別(b/g):\n");
scanf(" %c",&a[i].sex);
printf("年齡:\n");
scanf("%d",&a[i].age);
a[i].sum=0;
printf("C語言的成績:\n");
scanf("%f",&a[i].score[0]);
printf("Access的成績:\n");
scanf("%f",&a[i].score[1]);
printf("Dreamweaver的成績:\n");
scanf("%f",&a[i].score[2]);
a[i].sum=a[i].sum+a[i].score[0]+a[i].score[1]+a[i].score[2];
a[i].averge=a[i].sum/3;
m++;
printf("請輸入1繼續0結束!!\n");
scanf("%d",&h);
if(h==1)
continue;
else
break;
}
}
}
void input(struct stu *a,int n)
{
int i;
int h=0;

for(i=m;i<n;i++)
{
printf("請輸入學號:\n");
scanf(" %s",a[i].num);
printf("姓名:\n");
scanf(" %s",a[i].name);
printf("性別(b/g):\n");
scanf(" %c",&a[i].sex);
printf("年齡:\n");
scanf("%d",&a[i].age);
a[i].sum=0;
printf("C語言的成績:\n");
scanf("%f",&a[i].score[0]);
printf("Access的成績:\n");
scanf("%f",&a[i].score[1]);
printf("Dreamweaver的成績:\n");
scanf("%f",&a[i].score[2]);
a[i].sum=a[i].sum+a[i].score[0]+a[i].score[1]+a[i].score[2];
a[i].averge=a[i].sum/3;
m++;
printf("請輸入1繼續0結束!!\n");
scanf("%d",&h);
if(h==1)
continue;
else
break;
}
}
void output(struct stu *a,int n)
{
int i;
int j;
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("學號\t姓名\t性別\t年齡\tc語言\tAccess\tDreamweaver\t總分\t平均分\n");
for(i=0;i<m;i++)
{
printf("%s\t",a[i].num);
printf("%s\t",a[i].name);
printf(" %c\t",a[i].sex);
printf("%d\t",a[i].age);
for(j=0;j<3;j++)
{
printf("%.1f\t ",a[i].score[j]);

}
printf("\t%.1f\t %.1f",a[i].sum,a[i].averge);
printf("\n");
}
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
}
void npaixu(struct stu *a,int n)
{
int i,j;
struct stu temp;
for(i=1;i<=m-1;i++)
{
for(j=0;j<=m-i-1;j++)
{
if(strcmp(a[j].num,a[j+1].num)>0)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
void spaixu(struct stu *a,int n)
{
int i,j;
struct stu temp;
for(i=1;i<=m-1;i++)
{
for(j=0;j<=m-i-1;j++)
{
if(a[j].sum<a[j+1].sum)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
void Cpaixu(struct stu *a,int n)
{
int i,j;
struct stu temp;
for(i=1;i<=m-1;i++)
{
for(j=0;j<=m-i-1;j++)
{
if(a[j].score[0]<a[j+1].score[0])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
void Apaixu(struct stu *a,int n)
{
int i,j;
struct stu temp;
for(i=1;i<=m-1;i++)
{
for(j=0;j<=m-i-1;j++)
{
if(a[j].score[1]<a[j+1].score[1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
void Dpaixu(struct stu *a,int n)
{
int i,j;
struct stu temp;
for(i=1;i<=m-1;i++)
{
for(j=0;j<=m-i-1;j++)
{
if(a[j].score[2]<a[j+1].score[2])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}

void shousu(struct stu *a,int n)
{
char snum[20];
int i,j,d=0;
do
{
printf("請輸入你要查找的學號\n");
scanf("%s",snum);
for(i=0;i<m;i++)
{
if(strcmp(a[i].num,snum)==0)
{
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("學號\t姓名\t性別\t年齡\tc語言\tAccess\tDreamweaver\t總分\t平均分\n");
printf("%s\t",a[i].num);
printf("%s\t",a[i].name);
printf(" %c\t",a[i].sex);
printf("%d\t",a[i].age);
for(j=0;j<3;j++)
{
printf("%.1f\t ",a[i].score[j]);

}
printf("\t%.1f\t %.1f",a[i].sum,a[i].averge);
printf("\n");
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("收索成功\n");
break;
}

}
if(i==m)
{
printf("你輸入的學號不存在!\n");
}
printf("是否繼續查詢?(1/0)\n");
scanf("%d",&d);
system("cls");
}while(d==1);
}
void shanchu(struct stu *a,int n)
{
int c=0;
int i,j,d;
char snum[20];
do
{
printf("請輸入要刪除的學號\n");
scanf("%s",snum);
for(i=0;i<n;i++)
{
if(strcmp(a[i].num,snum)==0)
{
printf("學號\t姓名\t性別\t年齡\tc語言\tAccess\tDreamweaver\t總分\t平均分\n");
printf("%s\t",a[i].num);
printf("%s\t",a[i].name);
printf(" %c\t",a[i].sex);
printf("%d\t",a[i].age);
for(j=0;j<3;j++)
{
printf("%.1f\t ",a[i].score[j]);
}
printf("\t%.1f\t %.1f",a[i].sum,a[i].averge);
printf("\n");
printf("是否刪除此記錄(1/0)\n");
scanf("%d",&c);
if(c==1)
{
a[i]=a[i+1];
m--;
printf("刪除成功!\n");break;
}
else
break;
}
}
if(i==n)
{
printf("你輸入的學號不存在!\n");
}
if(c==1)
{
printf("是否繼續刪除1繼續0退出(1/0)!\n");
scanf("%d",&d);
system("cls");
}
}while(d==1);
}
void xiugai(struct stu *a,int n)
{
int i,j,c=0,d,f=0;
char snum[20];
float xscore[3];
char xn[20];
do
{
printf("請輸入要修改的學號\n");
scanf("%s",snum);
for(i=0;i<m;i++)
{
if(strcmp(a[i].num,snum)==0)
{
printf("學號\t姓名\t性別\t年齡\tc語言\tAccess\tDreamweaver\t總分\t平均分\n");
printf("%s\t",a[i].num);
printf("%s\t",a[i].name);
printf(" %c\t",a[i].sex);
printf("%d\t",a[i].age);
for(j=0;j<3;j++)
{
printf("%.1f\t ",a[i].score[j]);
}
printf("\t%.1f\t %.1f",a[i].sum,a[i].averge);
printf("\n");
printf("是否修改此記錄(1/0)\n");
scanf("%d",&c);
if(c==1)
{
do
{
system("cls");
printf("\t\t請選者你要修改的記錄,0返回上級菜單\n");
printf("\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("\t* <1> c語言 <2> Access *\n");
printf("\t* <3> Dreamweaver <4> 姓名 *\n");
printf("\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
scanf("%d",&d);
switch(d)
{
case 1:
{
printf("請輸入修改的成績\n");
scanf("%f",&xscore[0]);
a[i].score[0]=xscore[0];
printf("修改成功!\n");
printf("任意鍵返回上級菜單....");
getch();
}break;
case 2:
{
printf("請輸入修改的成績\n");
scanf("%f",&xscore[1]);
a[i].score[1]=xscore[1];
printf("修改成功!\n");
printf("任意鍵返回上級菜單....");
getch();
}break;
case 3:
{
printf("請輸入修改的成績\n");
scanf("%f",&xscore[2]);
a[i].score[2]=xscore[2];
printf("修改成功!\n");
printf("任意鍵返回上級菜單....");
getch();
}break;
case 4:
{
printf("\t\t請輸入修改的姓名\n");
scanf("\t\t%s",xn);
strcpy(a[i].name,xn);
printf("修改成功!\n");
printf("任意鍵返回上級菜單....");
getch();
}break;
case 0:break;
default:printf("\t\t不存在,請選擇(1~4)!! \n");break;
}
}while(d!=0);break;
}
}
}
if(i==m)
{
printf("你輸入的學號不存在!是否繼續修改(1/0)!\n");
scanf("%d",&f);
}
}while(f==1);
}

void baocun(struct stu *a,int n)//保存記錄
{
int i,c=0;
FILE* fp;
system("cls");
output(a,n);
printf("是否保存改記錄(1/0)");
scanf("%d",&c);
if(c==1)
{
if((fp=fopen("d:\zhang.txt","w+"))==NULL)
printf("無發打開\n");
else
{
fprintf(fp,"學號\t姓名\t性別\t年齡\tc語言\tAccess\tDreamweaver\t總分\t平均分\n");
for(i=0;i<m;i++)
{
fprintf(fp,"%s\t",a[i].num);
fprintf(fp,"%s\t",a[i].name);
fprintf(fp,"%c\t",a[i].sex);
fprintf(fp,"%d\t",a[i].age);
fprintf(fp,"%.1f\t",a[i].score[0]);
fprintf(fp,"%.1f\t",a[i].score[1]);
fprintf(fp,"%.1f\t",a[i].score[2]);
fprintf(fp,"%.1f\t",a[i].averge);
fprintf(fp,"%.1f\t",a[i].sum);
fprintf(fp,"\n");
}
fclose(fp);
printf("保存成功!\n請稍後,系統自動返回!!\n");
for(i=0;i<10;i++)
{
printf("\t");
_sleep(150);
}
}
}
}
void qu(struct stu *a,int n)
{
int i;
FILE* fp;
system("cls");
if((fp=fopen("d:\zhang.txt","r"))==NULL)
printf("不能打開此文件\n");
fseek(fp,58L,0);
while(!feof(fp))
{
fscanf(fp,"%s\t",a[m].num);
fscanf(fp,"%s\t",a[m].name);
fscanf(fp,"%c\t",&a[m].sex);
fscanf(fp,"%d\t",&a[m].age);
fscanf(fp,"%f\t",&a[m].score[0]);
fscanf(fp,"%f\t",&a[m].score[1]);
fscanf(fp,"%f\t",&a[m].score[2]);
fscanf(fp,"%f\t",&a[m].averge);
fscanf(fp,"%f\t",&a[m].sum);
m++;
}
fclose(fp);
printf("讀取成功!\n請稍後,系統自動返回!!\n");
for(i=0;i<10;i++)
{
printf("\t");
_sleep(150);
}
}
void tuichu()
{
system("cls");
printf("\n\n");
printf("\t\t* * * * * * * * * * * * * * * * * * * * *\n");
printf("\t\t* 歡迎使用學生管理系統,任意鍵退出! *\n");
printf("\t\t* * * * * * * * * * * * * * * * * * * * *\n");
exit(0);
}雖然只有50分,但我也給你啦 !我剛做好的呢!因為我們老師也叫我們做!覺得滿意吧!!

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