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

學生成績管理系統的代碼

發布時間: 2021-01-05 15:26:49

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

暈,你自己不可以弄么?再說要弄一起鬼才能運行,知道工程么?
頭文件:student.h
#ifndef H_STUDENT_HH
#define H_STUDENT_HH

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

#define INITIAL_SIZE 100
#define INCR_SIZE 50
#define NUM_SUBJECT 5
struct student_info
{
char number[15];
char name[20];
char gender[4];
float score[NUM_SUBJECT];
float sum;
float average;
int index;
};
typedef struct student_info StuInfo;
extern int numStus;
extern StuInfo* records;
extern char savedTag;
extern int arraySize;
extern char* subject[];

void handle_menu(void);
int menu_select(void);
void addRecord(void);
void modifyRecord(void);
void display(void);
void queryInfo(void);
void removeRecord(void);
void sortInfo(void);
int saveRecords(void);
int loadRecords(void);
void newRecords(void);
void quit(void);
void showTable(void);
int findRecord(char* target,int targetType,int from);
int getIndex(float sum);
void Record(StuInfo* src,StuInfo* dest);
#endif // H_STUDENT_HH

各個文件:
主界面student.c

#include "student.h"
int numStus=0;
StuInfo *records=NULL;
char savedTag=0;
int arraySize;
char* subject[]={"語文","數學","英語","物理","化學"};

int main()
{
records=(StuInfo*)malloc(sizeof(StuInfo)*INITIAL_SIZE);
if(records==NULL)
{
printf("momory fail!");
exit(-1);
}
arraySize=INITIAL_SIZE;
printf("\n");
printf("\t****************************************\n");
printf("\t* 這是一個 *\n");
printf("\t* 學生成績管理程序 *\n");
printf("\t* 可以多學生成績進行管理 *\n");
printf("\t* 歡迎使用管理程序 *\n");
printf("\t****************************************\n");
printf("\n");

handle_menu();
}

void handle_menu(void)
{
for( ; ; ){
switch(menu_select())
{
case 0:
addRecord();
break;
case 1:
modifyRecord();
break;
case 2:
display();
break;
case 3:
queryInfo();
break;
case 4:
removeRecord();
break;
case 5:
sortInfo();
break;
case 6:
saveRecords();
break;
case 7:
loadRecords();
break;
case 8:
newRecords();
break;
case 9:
quit();
}
}
}

int menu_select()
{
char s[2];
int cn=0;
printf("\n");
printf("\t0. 增加學生信息\n");
printf("\t1. 修改學生信息\n");
printf("\t2. 顯示學生信息\n");
printf("\t3. 查詢學生信息\n");
printf("\t4. 刪除學生信息\n");
printf("\t5. 對學生信息進行排序\n");
printf("\t6. 保存學生信息至記錄文件\n");
printf("\t7. 從記錄文件讀取學生信息\n");
printf("\t8. 新建學生信息文件\n");
printf("\t9. 結束運行\n");
printf("\n\t左邊數字對應功能選擇,請選擇0-9: ");

for(; ;)
{
gets(s);

cn=atoi(s);

if(cn==0&&(strcmp(s,"0")!=0)) cn=11;

if(cn<0||cn>9) printf("\n\t輸入錯誤,重選0-9: ");
else break;
}
return cn;
}

void newRecords(void)
{
char str[5];
if(numStus!=0)
{
if(savedTag==1)
{
printf("現在已經有記錄,選擇處理已有記錄的方法。\n");
printf("是否保存原來的記錄?(Y/N)");
gets(str);
if(str[0]!='n'&&str[0]!='N')
saveRecords();
}
}

numStus=0;
addRecord();
}

void quit(void)
{
char str[5];
if(savedTag==1)
{
printf("是否保存原來的記錄? (Y/N)");
gets(str);
if(str[0]!='n'&&str[0]!='N')
saveRecords();
}
free(records);
exit(0);
}

排序模塊sort.c

#include"student.h"
void sortInfo(void)
{
char str[5];
int i,j;
StuInfo tmps;
if(numStus==0)
{
printf("沒有可供排序的記錄!");
return;
}
printf("請輸入您希望進行的排序方式:\n");
printf("1.按學號進行升序排序\n");
printf("2.按學號進行降序排序\n");
printf("3.按名稱進行升序排序\n");
printf("4.按名稱進行降序排序\n");
printf("5.按名次進行升序排序\n");
printf("6.按名次進行降序排序\n");
printf("7.按錯了,我並不想進行排序\n");
gets(str);

if(str[0]<'1'||str[0]>'6')return;

for(i=0;i<numStus-1;i++)
{
for(j=i+1;j<numStus;j++)
{
if((str[0]=='1' && strcmp(records[i].number,
records[j].number)>0)||
(str[0]=='2' && strcmp(records[i].number,
records[j].number)<0)||
(str[0]=='3' && strcmp(records[i].name,
records[j].name)>0)||
(str[0]=='4' && strcmp(records[i].name,
records[j].name)<0)||
(str[0]=='5' &&
records[i].index>records[j].index)||
(str[0]=='6' &&
records[i].index<records[j].index))
{
Record(&records[i],&tmps);
Record(&records[j],&records[i]);
Record(&tmps,&records[j]);
}
}
}
printf("排序已經完成\n");
savedTag=1;
}

保存數據模塊:
save_load.c

#include "student.h"
int saveRecords()
{
FILE *fp;
char fname[30];
if(numStus==0)
{
printf("沒有記錄可存");
return -1;
}
printf("請輸入要存的文件名(直接回車選擇文件stu_info):");
gets(fname);
if(strlen(fname)==0)
strcpy(fname,"stu_info");
if((fp=fopen(fname,"wb"))==NULL)
{
printf("不能存入文件!\n");
return -1;
}
printf("\n存文件…\n");
fwrite(records,sizeof(StuInfo)*numStus,1,fp);
fclose(fp);
printf("%d條件記錄已經存入文件,請繼續操作。\n",numStus);
savedTag = 0;
return 0;
}

int loadRecords(void)
{
FILE *fp;
char fname[30];
char str[5];

if(numStus!=0&&savedTag==0)
{
printf("請選擇您是要覆蓋現有記錄(Y),還是將");
printf("讀取的記錄添加到現有記錄之後(n)?\n");
printf("直接按回車則覆蓋現有記錄\n");
gets(str);

if(str[0]=='n'||str[0]=='N')
{//將讀取的記錄添加到現有記錄之後
savedTag=1;
}
else
{
if(savedTag==1)
{//覆蓋現有記錄
printf("讀取文件將會更改原來的記錄,");
printf("是否保存原來的記錄?(Y/n)");
gets(str);
if(str[0]!='n' && str[0]!='N')
saveRecords();
}
numStus=0;
}
}
printf("請輸入要讀取的文件名(直接按回車選擇文件stu_info):");
gets(fname);
if(strlen(fname)==0)
strcpy(fname,"stu_info");
if((fp=fopen(fname,"rb"))==NULL)
{
printf("打不開文件!請重新選接\n");
return -1;
}
printf("\n取文件…\n");
while(!feof(fp))
{
//現在的數組空間不足,需要重新申請空間
if(numStus>=arraySize)
{
records=realloc(records,(arraySize+
INCR_SIZE)*sizeof(StuInfo));
if(records==NULL)
{
printf("memory failed!");
exit(-1);
}
arraySize=arraySize+INCR_SIZE;
}
if(fread(&records[numStus],
sizeof(StuInfo),1,fp)!=1)break;
//按照addRecord函數的方法,更新名次
records[numStus].index=
getIndex(records[numStus].sum);numStus++;
}
fclose(fp);
printf("現在共有%d條記錄。",numStus);
return 0;
}

查詢模塊:
que_remv_modi.c

#include "student.h"

int findRecord(char* target,int targetType,int from)
{
int i;
for (i=from;i<numStus;i++)
{
if (( targetType==0&& strcmp(target,records[i].number)==0)||
(targetType==1 &&strcmp (target,records[i].name)==0 )||
(targetType==2 && atoi(target)==records[i].index))
return i;
}
return -1;

}

void queryInfo (void)
{
char str[5];
char target[20];
int type;
int count;
int i,j;
if (numStus==0)
{
printf ("沒有可供查詢的記錄!");
return;
}
while(1)
{
printf ("請輸入查詢的方式:(直接輸入回車則結束查詢)\n");
printf ("1. 按學號\n");
printf ("2.按姓名\n");
printf ("3.按名次\n");
gets(str);
if (strlen(str)==0)
break;
if (str[0]=='1')
{ printf ("請輸入欲查詢的學生的學號:");
gets(target);
type=0;

}
else if (str[0]=='2')
{
printf("請輸入欲查詢的學生的姓名:");
gets(target);
type=1;

}
else
{
printf ("請輸入欲查詢的學生的名次:");
gets(target);
type=2;
}
i= findRecord(target,type,0);
if(i==1)
{
//列印查詢到的學生的成績
showTable();
}
count = 0;
while (i !=-1)
{
count++;
printf("%s\t%s\t%s",records[i].number,
records[i].name,records[i].gender);
for (j=0;j<NUM_SUBJECT;j++)
printf ("\t%.lf",records[i].score[j]);
printf ("\t%.lf\t%.lf\t%d\n",
records[i].sum,records[i].average,
records[i].index);
i = findRecord(target,type,i+1);
}

if (count==0)
printf ("沒有符合條件的學生!\n");
else
printf ("一共找到了%d名學生的信息 \n\n",count);

}
}

/**********************
*刪除指定的記錄
***********************/
void removeRecord(void)
{char str[5];
char target[20];
int type;
int i,j;
int tmpi;

if(numStus==0)
{printf("沒有可供刪除的記錄!");
return;
}
while(1)
{
printf("請輸入如何找到欲刪除的記錄的方式;");
printf("(直接輸入回車則結果移除操作)\n");
printf("1.按學號\n");
printf("2.按姓名\n");
printf("3.按名次\n");
gets(str);
if(strlen(str)==0)break;
if(str[0]=='1')
{printf("請輸入學生的學號;");
gets(target);
type=0;
}
else if(str[0]=='2')
{printf("請輸入學生的姓名");
gets(target);
type=1;
}
else
{printf("請輸入學生的名次;");
gets(target);
type=2;
}
i=findRecord(target,type,0);
if(i==-1) printf("沒有符合條件的學生!\n");
while (i!=-1)
{showTable();
printf("%s\t%s\t%s",records[i].number,records[i].name,records[i].gender);
for(j=0;j<NUM_SUBJECT;j++)
printf("\t%.1f",records[i].score[j]);
printf("\t%.1f\t%.1f\t%d\n",records[i].sum,records[i].average,records[i].index);
printf("確定要刪除這個學生的信息嗎?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
{numStus--;
tmpi=records[i].index;
//將後面的記錄前移
for(j=i;j<numStus;j++)
{
Record(&records[j+1],&records[j]);
}
//將名次排在被刪記錄後面的記錄名次減1
for(j=0;j<numStus;j++)
{if(records[j].index>tmpi)
records[j].index--;
}}
//去下一個符合條件的記錄
i=findRecord(target,type,i+1);
}}
savedTag = 1;
}
/********************************************
* 將src指向的一條記錄復制給dest指向的記錄
*********************************************/
void Record(StuInfo* src, StuInfo* dest)
{
int j;
strcpy(dest->number,src->number);
strcpy(dest->name,src->name);
strcpy(dest->gender,src->gender);
for (j=0; j<NUM_SUBJECT; j++)
{
dest->score[j] = src->score[j];
}
dest->sum = src->sum;
dest->average = src->average;
dest->index = src->index;
}

/*********************************
* 修改指定學生的信息
**********************************/

void modifyRecord(void)
{
char str[5];
char target[20];
int type;
int i,j;
int tmpi;
float sum,mark;
int count=0; // 總分大於sum的人數

if(numStus==0)
{
printf("沒有可供修改的記錄!");
return;
}

while(1) {
printf("請輸入如何找到欲修改的記錄的方式: ");
printf(" (直接輸入回車則結束移除操作) \n");
printf("1. 按學號\n ");
printf("2. 按姓名\n ");
printf("3. 按名次\n ");
gets(str);
if(strlen(str)==0) break;

if(str[0]=='1')
{
printf("請輸入該學生的學號: ");
gets(target);
type=0;
} else if(str[0]=='1')
{
printf("請輸入該學生的姓名: ");
gets(target);
type=1;
} else
{
printf("請輸入該學生的名次: ");
gets(target);
type=2;
}

i=findRecord(target,type,0);
if(i==-1) printf("沒有符合條件的學生! \n");

while(i != -1)
{
showTable();
printf("%s\t%s\t%s",records[i].number,records[i].name,records[i].gender);
for(j=0;j<NUM_SUBJECT;j++)
printf("\t%.1f",records[i].score[j]);
printf("\t%.1f\t%.1f\t%d\n",records[i].sum,records[i].average,records[i].index);
printf("確定要修改這個學生的信息嗎?(y/n)");
gets(str);
if (str[0]=='y' || str[0]=='Y')
{
tmpi=records[i].index;
printf("下面請輸入該學生的信息: \n");
printf("請輸入學號: ");
gets(records[i].number);
printf("請輸入姓名: ");
gets(records[i].name);
printf("請輸入性別 (0為女,1為男): ");
gets(str);
if (str[0]=='0')
strcpy(records[i].gender," 女 ");
else
strcpy(records[i].gender," 男 ");
sum=0;
for(j=0;j<NUM_SUBJECT;j++ )
{
printf("請輸入%s成績: ",subject[j]);
gets(str);
mark=(float)atof(str);
records[i].score[j]=mark;
sum+=mark;
}
records[i].sum=sum;
records[i].average=sum/NUM_SUBJECT;

// 將原來名次排被修改記錄之後,而其sum小於等於
// 修改後記錄的sum的記錄的名次減1
// 將原來名次排在被修改記錄之前或相同,而其sum
// 大於修改後記錄的sum的記錄的名次增1
count = 0;
for (j=0;j<numStus;j++)
{
if(j==i) continue;
if(records[j].index>tmpi && records[j].sum>sum)
records[j].index--;
else if(records[j].index<=tmpi && records[j].sum<sum)
records[j].index++;
if (records[j].sum>sum)
count++;
}
records[i].index=count+1;
}
i=findRecord(target,type,i+1);
}
}
savedTag = 1;
}

增加學生信息模塊:
add_disp.c

#include "student.h"
void showTable(void)
{
int j;
printf("學號\t姓名\t性別");
for(j=0;j<NUM_SUBJECT;j++)
printf("\t%s",subject[j]);
printf("\t總分\t平均分\t名次\n");
}

void display(void)
{
int i,j;
if(numStus==0)
{
printf("沒有可供顯示的記錄!");
return;
}
showTable();
for(i=0;i<numStus;i++)
{
printf("%s\t%s\t%s",records[i].number,records[i].name,records[i].gender);
for(j=0;j<NUM_SUBJECT;j++)
printf("\t%.1f",records[i].score[j]);
printf("\t%.1f\t%.1f\t%d\n",records[i].sum,records[i].average,records[i].index);
if(i%20==0&&i!=0)
{
printf("輸入任一字元後繼續...\n");
getch();
printf("\n");
showTable();
}
}
}

int getIndex(float sum)
{
int i;
int count=0;

for(i=0;i<numStus;i++)
{
if(records[i].sum<sum)
{
records[i].index++;
}
else if(records[i].sum>sum)
{
count++;
}
}
return count+1;
}

void addRecord(void)
{
char str[10];
int i,j;
float mark,sum;
if(numStus==0)
printf("原來沒有記錄,現在建立新表\n");
else
printf("下面在當前表的末尾增加新的信息\n");
while(1)
{
printf("你將要添加一組信息,確定嗎?(Y/N)");
gets(str);
if (str[0]=='n' || str[0]=='N')
break;
if(numStus>=arraySize)
{
records=realloc(records,(arraySize+INCR_SIZE)*sizeof(StuInfo));
if(records == NULL)
{
printf("memory failed!");
exit(-1);
}
arraySize=arraySize+INCR_SIZE;
}
printf("請輸入學號:");
gets(records[numStus].number);
printf("請輸入姓名:");
gets(records[numStus].name);
printf("請輸入性別(0為女,1為男):");
gets(str);
if(str[0]=='0')
strcpy(records[numStus].gender,"女");
else
strcpy(records[numStus].gender,"男");
sum=0;
for(j=0;j<NUM_SUBJECT;j++)
{
printf("請輸入%s成績:",subject[j]);
gets(str);
mark=(float)atof(str);
records[numStus].score[j]=mark;
sum+=mark;
}
records[numStus].sum=sum;
records[numStus].average=sum/NUM_SUBJECT;
records[numStus].index=getIndex(sum);
numStus++;

}
printf("現在一共有%d條信息\n",numStus);
savedTag=1;
}

void dispaly(void)
{
int i ,j;
if(numStus==0)
{
printf("沒有可供顯示的記錄!");
return;
}
showTable();
for(i=0;i<numStus;i++)
{
printf("%s\t%s\t%s",records[i].number,records[i].name,records[i].gender);
for(j=0;j<NUM_SUBJECT;j++)
printf("\t%.1f\t%.1f\t%d\n",records[i].sum,records[i].average,records[i].index);
if(i%20==0&&i!=0)
{
printf("輸入任一字元後繼續...\n");
getch();
printf("\n\n");
showTable();
}
}

}

② 求 學生成績管理系統源代碼

姓名簡拼成績錄入系統

③ 學生成績管理系統代碼

#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
class student
{ private:
char name[20]; //姓名
double cpro,english,math,sport,law,hbpro,computer;//課程
int order, number; //名次,學號
public:
student(){}
student(char n[20],int nu,double cc,double eng,double ma,double sp,double l,double hb,double com)
{strcpy(name,n);
number=nu;
cpro=cc; english=eng;math=ma;sport=sp;law=l;hbpro=hb;computer=com;
}
friend void main();
};

void main()
{
cout<<" 歡迎進入**學生成績管理系統**!"<<endl;

cout<<" ******************************************"<<endl;
cout<<" **** 學生成績管理系統 ****"<<endl;
cout<<" ******************************************"<<endl;
cout<<" **************************"<<endl;
cout<<" **0、輸入數據 **"<<endl;
cout<<" **1、增加數據 **"<<endl;
cout<<" **2、修改數據 **"<<endl;
cout<<" **3、按姓名查詢 **"<<endl;
cout<<" **4、按學號查詢 **"<<endl;
cout<<" **5、輸出所有學生的成績 **"<<endl;
cout<<" **6、退出系統 **"<<endl;
cout<<" **************************"<<endl;
cout<<" 選擇0-6數字進行操作"<<endl;

char p;char w;
student *s[50]; //指針對象,最多存50個學生數據
ofstream *file[50]; //負責對文件插入操作
int i=0;
int j=0;
int flag=0;
do //flag判斷輸入是否有效
{
cin>>p;
if((p>='0'&&p<='6'))
flag=1;
else
cout<<" 指令錯誤!請重新輸入:"<<endl;
}while(flag==0);
do{
switch(p) //接收功能選項
{
case '0': //輸入數據
{
char c;
char name[20];int number;double cpro,english,math,sport,law,hbpro,computer;
do{
cout<<" 請輸入姓名:";
cin>>name;
cout<<endl<<" 請輸入學號:";
cin>>number;
cout<<" 請輸入C++成績:";
cin>>cpro;
cout<<endl<<" 請輸入英語成績:";
cin>>english;
cout<<endl<<" 請輸入數學成績:";
cin>>math;
cout<<endl<<" 請輸入體育成績:";
cin>>sport;
cout<<endl<<" 請輸入網路基礎成績:";
cin>>law;
cout<<endl<<" 請輸入C語言成績:";
cin>>hbpro;
cout<<endl<<" 請輸入資料庫成績:";
cin>>computer;
cout<<endl;
file[j]=new ofstream("D:\document",ios::ate);
*file[j]<<" 姓名 "<<name<<" 學號 "<<number<<" C++成績 "<<cpro
<<" 英語成績 "<<english<<" 數學成績 "<<math<<" 體育成績 "
<<sport<<" 網路基礎成績 "<<law<<" C成績 "<<hbpro<<" 資料庫成績 "<<computer<<endl;
j++;
s[i]=new student(name, number,cpro,english,math,sport,law,hbpro,computer);
i++;
cout<<" 數據輸入成功,想繼續輸入嗎(y/n):";
cin>>c;
cout<<endl;
do
{
if(c!='y'&&c!='n')
{
cout<<" 指令錯誤!請重新輸入!"<<endl<<" ";
cin>>c;
}
else
flag=1;
}while(flag==0);
}while(c=='y');
break;
}

case '1': //增加數據
{
char name[20];
int number;double cpro,english,math,sport,law,hbpro,computer;
char c;
do
{
cout<<" 請輸入您要增加的學生的姓名:";
cin>>name;
cout<<endl<<" 請輸入學號:";
cin>>number;
cout<<endl<<" 請輸入C++成績:";
cin>>cpro;
cout<<endl<<" 請輸入英語成績:";
cin>>english;
cout<<endl<<" 請輸入數學成績:";
cin>>math;
cout<<endl<<" 請輸入體育成績:";
cin>>sport;
cout<<endl<<" 請輸入網路基礎成績:";
cin>>law;
cout<<endl<<" 請輸入C語言成績:";
cin>>hbpro;
cout<<endl<<" 請輸入資料庫成績:";
cin>>computer;
cout<<endl;

file[j]=new ofstream("d:\document",ios::ate);
*file[j]<<" 姓名 "<<name<<" 學號 "<<number<<" C++成績 "<<cpro<<" 英語成績 "<<english<<" 數學成績 "<<math<<" 體育成績 "<<sport<<" 網路基礎成績 "<<law<<" C成績 "<<hbpro<<" 資料庫成績 "<<computer<<endl;
j++;
s[i]=new student(name, number, cpro,english,math,sport,law,hbpro,computer);
i++;
cout<<" 數據輸入成功,想繼續數入嗎(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令錯誤!請重新輸入!"<<endl<<" ";
cin>>c;
}
}while(c=='y');
break;
}

case '2': //修改數據
{
char name[20];int nu;double cc,eng,ma,sp,l,hb,com;flag=0;
char c;
if(i==0)
{
cout<<" 管理系統中沒有輸入數據!"<<endl;break;
}
do
{
cout<<" 請輸入您要修改的學生的姓名:";
cin>>name;
cout<<endl;
for(int h=0;h<i;h++) //h紀錄要修改學生的位置
{
if(strcmp(name,s[h]->name)==0)
{
flag=1;
cout<<" 請輸入新的學號:";
cin>>nu;
cout<<endl<<" 請輸入C++成績:";
cin>>cc;
cout<<endl<<" 請輸入英語成績:";
cin>>eng;
cout<<endl<<" 請輸入數學成績:";
cin>>ma;
cout<<endl<<" 請輸入體育成績:";
cin>>sp;
cout<<endl<<" 請輸入網路基礎成績:";
cin>>l;
cout<<endl<<" 請輸入C語言成績:";
cin>>hb;
cout<<endl<<" 請輸入資料庫成績:";
cin>>com;
cout<<endl;
s[h]->cpro=cc;
s[h]->english=eng;
s[h]->math=ma;
s[h]->sport=sp;
s[h]->law=l;
s[h]->hbpro=hb;
s[h]->computer=com;
s[h]->number=nu;
cout<<" 數據修改成功!"<<endl;
}
}
if(flag==0)
{
cout<<" 您要修改的學生本來就不存在!請檢查重新輸入!"<<endl;
}
cout<<" 想繼續修改嗎(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令錯誤!請重新輸入!"<<endl<<" ";
cin>>c;
}
}while(c=='y');
break;
}

case '3': //按姓名查詢
{
char n[20];int j=0;char c;
if(i==0)
{
cout<<" 管理系統中沒有輸入數據!"<<endl;break;
}
do{
int flag=0;
cout<<" 請輸入你要查詢的學生姓名:";
cin>>n;
cout<<endl;
for(int j=0;j<i;j++)
{
if(strcmp(n,(*s[j]).name)==0)
{
flag=1;
cout<<" 您要查詢的學生是:"<<(*s[j]).name<<endl;
cout<<(*s[j]).name<<"的成績是: "<<" C++: "<<(*s[j]).cpro<<" 英語: "<<(*s[j]).english<<" 數學:"<<(*s[j]).math<<" 體育:"<<(*s[j]).sport<<" 法律:"<<(*s[j]).law<<" C:"<<(*s[j]).hbpro<<" 資料庫 "<<(*s[j]).computer<<endl;
}
}
if(flag==0)
cout<<" 對不起!您要查詢的學生不存在!"<<endl;
cout<<" 您想繼續查詢嗎?(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令錯誤!請重新輸入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '4': //按學號查詢
{
int n,j=0;char c;
if(i==0){

cout<<" 管理系統中沒有輸入數據!"<<endl;break;
}
do{
int flag=0;
cout<<" 請輸入你要查詢的學生的學號:";
cin>>n;
cout<<endl;
for(int j=0;j<i;j++)
{
if(s[j]->number==n)
{
flag=1;
cout<<" 您要查詢的學生是:"<<(*s[j]).name<<endl;
cout<<(*s[j]).name<<"的成績是: "<<" C++:"<<(*s[j]).cpro<<" 英語:"<<(*s[j]).english<<" 數學:"<<(*s[j]).math<<" 體育:"<<(*s[j]).sport<<" 法律:"<<(*s[j]).law<<" C:"<<(*s[j]).hbpro<<" 資料庫 "<<(*s[j]).computer<<endl;
}
}
if(flag==0)
cout<<" 對不起!您要查詢的學生不存在!"<<endl;
cout<<" 您想繼續查詢嗎?(y/n):";
cin>>c;
cout<<endl;
if(c!='y'&&c!='n')
{
cout<<" 指令錯誤!請重新輸入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '5': //輸出
{
cout<<" 本系統所有學生數據如下:"<<endl;
if(i==0)
cout<<" 管理系統中沒有輸入數據!"<<endl;
cout<<" 姓名 學號 c++ 英語 數學 體育 網路基礎 C語言 資料庫 "<<endl;
for(int k=0;k<i;k++)
{
cout<<s[k]->name<<setw(7)<<s[k]->number<<setw(6)
<<(*s[k]).cpro<<setw(6)<<(*s[k]).english<<setw(6)
<<(*s[k]).math<<setw(6)<<(*s[k]).sport<<setw(7)
<<(*s[k]).law <<setw(10)<<(*s[k]).hbpro<<setw(10)<<(*s[k]).computer<<setw(10)<<endl;
}
break;
}
case'6'://退出
{exit(0); cout<<"Bye bye!"<<endl;}
}
cout<<" 您想繼續進行其他操作嗎?(y/n):";
int flag=0;
do
{
cin>>w;
cout<<endl;
if(w!='y'&&w!='n')
cout<<" 指令錯誤!請重新輸入!"<<endl;
else
flag=1;
}while(flag==0);
if(w=='y')
cout<<" 請輸入操作代碼:0 輸入數據"<<endl;
cout<<" 1 增加數據"<<endl;
cout<<" 2 修改數據"<<endl;
cout<<" 3 按姓名查詢"<<endl;
cout<<" 4 按學號查找"<<endl;
cout<<" 5 輸出所有學生成績"<<endl;
cout<<" 6 退出系統"<<endl;
cin>>p;
}while(w=='y');
}

④ 製作學生成績管理系統有什麼代碼

你可以看來看自這個文檔 下載下來 有你所有想要的 http://60.2.234.67/jwjg/yiqizhan/zlx/ZDshuoming/ZDsm.doc

⑤ 學生成績管理系統的代碼

實現了樓主要求功能,樓主可以參考一下,另外希望樓主採納哦,嘿嘿嘿~~~
唉,白寫這么多代碼了,你都不看的,以後不來網路嘍~~~
#include<iostream.h>
#include<stdio.h>
#include<iomanip.h>
#include<string.h>
#include<stdlib.h>
struct student
{
int number; //學號
char name[10]; //學生姓名
int common; //平時成績
int mid; //期中成績
int end; //期末成績
int sum; //總成績
}stud[50];
int menu() //菜單選項
{
char c;
cout<<"***************成績管理系統*****************"<<endl;
cout<<"輸入1輸入學生成績數據"<<endl;
cout<<"輸入2顯示學生成績數據"<<endl;
cout<<"輸入3查找學生成績數據"<<endl;
cout<<"輸入4顯示不合格學生數據"<<endl;
cout<<"輸入5排序並且評定獎學金獲得情況"<<endl;
cout<<"輸入0程序運行結束界面"<<endl;
cout<<"請輸入編號"<<endl;
cin>>c;
do
{
cout<<"***************成績管理系統*****************"<<endl;
cout<<"輸入1輸入學生成績數據"<<endl;
cout<<"輸入2顯示學生成績數據"<<endl;
cout<<"輸入3查找學生成績數據"<<endl;
cout<<"輸入4顯示不合格學生數據"<<endl;
cout<<"輸入5排序並且評定獎學金獲得情況"<<endl;
cout<<"輸入0程序運行結束界面"<<endl;
}while(c>'5'||c<'0');
system("cls");
return c-'0';
}
void input(int num) //輸入學生數據
{
int i;
cout<<"請輸入學生數據:"<<endl;
for(i=0;i<num;i++)
{
cout<<"學號 姓名 平時成績 期中成績 期末成績 "<<endl;
cin>>stud[i].number;
cin>>stud[i].name;
cin>>stud[i].common;
cin>>stud[i].mid;
cin>>stud[i].end;
}
}
void display(int num) //顯示輸入的數據
{
int i;
cout<<"輸入的數據為:"<<endl;
for(i=0;i<num;i++)
{
cout<<"學號 姓名 平時成績 期中成績 期末成績 總成績"<<endl;
stud[i].sum=stud[i].common+stud[i].mid+stud[i].end;
cout<<setw(4)<<stud[i].number<<setw(4)<<stud[i].name;
cout<<setw(4)<<stud[i].number<<setw(4)<<stud[i].mid;
cout<<setw(4)<<stud[i].end<<setw(4)<<stud[i].sum<<endl;
}
}
void charge(int num) //補考學生數據
{
int i;
for(i=0;i<num;i++)
{
if(stud[i].mid<60||stud[i].end<60||stud[i].common<60)
cout<<"需要補考學生數據"<<endl;
cout<<"學號:"<<stud[i].number<<"姓名"<<stud[i].sum<<endl;
}
}
void search(int num) //查詢一個學生的數據
{
int i;
int m;
cin>>m;
for(i=0;i<num;i++)
{
if(m==stud[i].number)
cout<<"學號"<<stud[i].number<<"姓名"<<stud[i].name<<endl;
else
cout<<"沒有該生信息"<<endl;
break;
}
}
void order(int num) //排序並且評出獲得獎學金的學生
{
int i,j,temp;
for(i=0;i<num-1;i++)
for(j=1;j<num;j++)
{
if(stud[i].sum<stud[j].sum)
{
temp=stud[i].sum;
stud[i].sum=stud[j].sum;
stud[j].sum=temp;
}
}
cout<<"1-2名為A等獎學金"<<endl;
cout<<"3-5名為B等獎學金"<<endl;
cout<<"6-9名為C等獎學金"<<endl;
for(i=0;i<num;i++)
{
cout<<"學生的名次為:"<<endl;
cout<<"第"<<i+1<<"名為:"<<stud[i].name<<endl;
if(i+1==2||i+1==1)
cout<<"A等獎學金"<<endl;
else
if(i+1<=5&&i+1>=3)
cout<<"B等獎學金"<<endl;
else
if(i+1<=9&&i+1>=6)
cout<<"C等獎學金"<<endl;
else
cout<<"沒有獲得獎學金"<<endl;
}
}
void main()
{
int num,n;
cout<<"請輸入學生的人數:";
cin>>num;
menu();
for(;;)
{
switch(n=menu())
{
case 1:
input(num);
break;
case 2:
display(num);
break;
case 3:
search(num);
break;
case 4:
charge(num);
break;
case 5:
order(num);
break;
default:
cout<<"歡迎使用O(∩_∩)O"<<endl;
break;
}
}
system("pause");
}

⑥ 學生成績管理系統的源代碼

#include "stdio.h"

/*定義學生結構體*/

struct Student

{

char ID[20];

char Name[20];

float Mark1;

float Mark2;

float Mark3;

float Average;

};

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

struct Student students[1000];

int num=0;

/*求平均值*/

float Avg(struct Student stu)

{

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

}

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

int Student_SearchByIndex(char id[])

{

int i;

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

{

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

{

return i;

}

}

return -1;

}

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

int Student_SearchByName(char name[])

{

int i;

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

{

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

{

return i;

}

}

return -1;

}

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

void Student_DisplaySingle(int index)

{

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

printf("-------------------------------------------------------------\n");

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

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

}

/*插入學生信息*/

void Student_Insert()

{

while(1)

{

printf("請輸入學號:");

scanf("%s",&students[num].ID);

getchar();

printf("請輸入姓名:");

scanf("%s",&students[num].Name);

getchar();

printf("請輸入成績:");

scanf("%f",&students[num].Mark1);

getchar();

printf("請輸入成績:");

scanf("%f",&students[num].Mark2);

getchar();

printf("請輸入成績:");

scanf("%f",&students[num].Mark3);

getchar();

students[num].Average=Avg(students[num]);

num++;

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

if (getchar()=='n')

{

break;

}

}

}

/*修改學生信息*/

void Student_Modify()

{

float mark1,mark2,mark3;

while(1)

{

char id[20];

int index;

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

scanf("%s",&id);

getchar();

index=Student_SearchByIndex(id);

if (index==-1)

{

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

}

else

{

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

Student_DisplaySingle(index);

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

printf("請輸入學號:");

scanf("%s",&students[index].ID);

getchar();

printf("請輸入姓名:");

scanf("%s",&students[index].Name);

getchar();

printf("請輸入成績:");

scanf("%f",&students[index].Mark1);

getchar();

printf("請輸入成績:");

scanf("%f",&students[index].Mark2);

getchar();

printf("請輸入成績:");

scanf("%f",&students[index].Mark3);

getchar();

students[index].Average=Avg(students[index]);

}

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

if (getchar()=='n')

{

break;

}

}

}

/*刪除學生信息*/

void Student_Delete()

{

int i;

while(1)

{

char id[20];

int index;

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

scanf("%s",&id);

getchar();

index=Student_SearchByIndex(id);

if (index==-1)

{

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

}

else

{

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

Student_DisplaySingle(index);

printf("是否真的要刪除?(y/n)");

if (getchar()=='y')

{

for (i=index;i<num-1;i++)

{

students[i]=students[i+1];

}

num--;

}

getchar();

}

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

if (getchar()=='n')

{

break;

}

}

}

/*按姓名查詢*/

void Student_Select()

{

while(1)

{

char name[20];

int index;

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

scanf("%s",&name);

getchar();

index=Student_SearchByName(name);

if (index==-1)

{

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

}

else

{

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

Student_DisplaySingle(index);

}

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

if (getchar()=='n')

{

break;

}

}

}

/*按平均值排序*/

void Student_SortByAverage()

{

int i,j;

struct Student tmp;

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

{

for (j=1;j<num-i;j++)

{

if (students[j-1].Average<students[j].Average)

{

tmp=students[j-1];

students[j-1]=students[j];

students[j]=tmp;

}

}

}

}

/*顯示學生信息*/

void Student_Display()

{

int i;

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

printf("-------------------------------------------------------------\n");

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

{

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

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

}

}

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

void IO_ReadInfo()

{

FILE *fp;

int i;

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

{

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

return;

}

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

{

num=-1;

}

else

{

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

{

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

}

}

fclose(fp);

}

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

void IO_WriteInfo()

{

FILE *fp;

int i;

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

{

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

return;

}

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

{

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

}

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

{

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

{

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

}

}

fclose(fp);

}

/*主程序*/

main()

{

int choice;

IO_ReadInfo();

while(1)

{

/*主菜單*/

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

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

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

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

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

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

printf("6. 退出\n");

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

scanf("%d",&choice);

getchar();

switch(choice)

{

case 1:

Student_Insert();

break;

case 2:

Student_Modify();

break;

case 3:

Student_Delete();

break;

case 4:

Student_Select();

break;

case 5:

Student_SortByAverage();

Student_Display();

break;

case 6:

exit();

break;

}

IO_WriteInfo();

}

}

⑦ 學生信息管理系統最簡單源代碼。

方法一:

1、創建抄一個c語言項目。然後右鍵頭文件,創建一個Stu的頭文件。

⑧ 學生成績管理系統的代碼是什麼

代碼如下:

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

printf("*");

printf(" ");

printf("1.Input record ");

printf("2.Caculate totel and average score of every course ");

printf("3.Caculate totel and average score of every student ");

printf("4.Sort in descending order by total score of every student ");

printf("5.Sort in ascending order by total score of every student ");

printf("6.Sort in ascending order by number ");

printf("7.Sort in ascending order by name ");

printf("8.Search by number ");

printf("9.Search by name ");

printf("10.Statistic analysis for every course ");

printf("11.List record ");

printf("12.Write to a file ");

printf("13.Read from a file ");

printf("0.Exit ");

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

printf("*");

printf(" ");

printf("Please enter your choice:");

printf(" ");

⑨ 求學生成績管理系統的源代碼

#include<stdio.h>
#include<stdlib.h>
#defineFILENAME"student.dat"
typedefenum{MAN,WOMAN}SEX;
typedefstructtagStudent
{
intnum; //學生的編號
charname[20]; //學生的姓名
SEX sex; //學生的性別
intage; //學生的年齡
charmajor[20]; //學生的專業
structtagStudent*next;//下一個節點的指針
}STUDENT,*PSTUDENT;
STUDENTg_head; //頭節點
//1.顯示菜單
voidShowMenu();
//2.獲取用戶選擇的菜單的編號
intGetMenuChoose();
//3.創建一個節點,它會返回一個新創建的學生信息節點的指針
PSTUDENTCreateStudent();
//4.把學生信息節點加入到鏈表中
intAddStudent(PSTUDENTpstu);
//5.返回指定編號學生節點的上一個節點的指針
PSTUDENTGetPrevAddr(intnum);
//6.顯示所有學生信息
voidShowAll();
//7.顯示信息數量
intShowStudentCount();
//8.修改學生信息,參數為要修改的學生的編號
voidModityStudent(intnum);
//9.獲取用戶的選擇
intQuestion(constchar*pstr);
//10.獲取用戶輸入的學生的編號
intGetInputNum();
//11.刪除編號為num的學生信息
voidDelStudent(intnum);
//12.刪除所有的學生信息
voidDelAll();
//13.把學生信息保存到文件當中
voidSaveToFile();
//14.從文件中讀取學生信息
voidLoadFromFile();
intmain()
{
intrunning=1;
while(running)
{
switch(GetMenuChoose())
{
case0:
running=0;
break;
case1:
// printf("你選擇了菜單1 ");
AddStudent(CreateStudent());
break;
case2:
// printf("你選擇了菜單2 ");
DelStudent(GetInputNum());
break;
case3:
printf("你選擇了菜單3 ");
break;
case4:
// printf("你選擇了菜單4 ");
ModityStudent(GetInputNum());
break;
case5:
// printf("你選擇了菜單5 ");
DelAll();
break;
case6:
// printf("你選擇了菜單6 ");
ShowAll();
break;
case7:
// printf("你選擇了菜單7 ");
ShowStudentCount();
break;
case8:
// printf("你選擇了菜單8 ");
LoadFromFile();
break;
case9:
// printf("你選擇了菜單9 ");
SaveToFile();
break;
}
system("pause");
}

return0;
}
//1.顯示菜單
voidShowMenu()
{
system("cls");
printf("-----------------------------學生管理系統-------------------------------- ");
printf(" 1.添加學生信息2.刪除某個學生信息3.顯示某個學生信息 ");
printf(" 4.修改學生信息5.刪除所有學生信息6.顯示所有學生信息 ");
printf(" 7.顯示信息數量8.讀取文件學生信息9.保存學生信息至文件 ");
printf(" 0.退出系統 ");
printf(" ------------------------------------------------------------------------- ");
}
//2.獲取用戶選擇的菜單的編號
intGetMenuChoose()
{
intnum;//保存用戶選擇的菜單編號
ShowMenu();
printf("請選擇菜單(0~9):");
while(1!=scanf("%d",&num)||num<0||num>9)
{
ShowMenu();
printf("選擇菜單錯誤,請重新選擇(0~9):");
fflush(stdin);//清空輸入緩沖區
}
returnnum;
}
//3.創建一個節點,它會返回一個新創建的學生信息節點的指針
PSTUDENTCreateStudent()
{
intsex;
PSTUDENTpstu=(PSTUDENT)malloc(sizeof(STUDENT));//在堆內存申請空間,存儲學生信息
if(!pstu)
{
printf("申請內存空間失敗! ");
returnNULL;
}
printf("請輸入學生的編號(整型):");
while(1!=scanf("%d",&pstu->num)||GetPrevAddr(pstu->num))
{
printf("學生編號輸入錯誤或已經存在,請重新輸入學生的編號(整型):");
fflush(stdin);
}
printf("請輸入學生的姓名(小於20字元):");
scanf("%20s",pstu->name);//(*pstu).name
printf("請選擇學生的性別(1.男2.女):");
while(1!=scanf("%d",&sex)||sex<1||sex>2)
{
printf("性別選擇錯誤,請重新選擇學生的性別(1.男2.女):");
fflush(stdin);
}
if(1==sex)
pstu->sex=MAN;
else
pstu->sex=WOMAN;
printf("請輸入學生的年齡(10~40):");
while(1!=scanf("%d",&pstu->age)||pstu->age<10||pstu->age>40)
{
printf("年齡輸入錯誤!請重新輸入學生的年齡(10~40):");
fflush(stdin);
}
printf("請輸入學生的專業(小於20字元):");
scanf("%20s",pstu->major);
pstu->next=NULL;
returnpstu;
}
//4.把學生信息節點加入到鏈表中
intAddStudent(PSTUDENTpstu)
{
PSTUDENTps=&g_head;
if(!pstu)
{
return0;
}
//判斷一下該學生信息是不是已經存在
if(GetPrevAddr(pstu->num))
{
printf("編號為%d的學生信息已經存在! ",pstu->num);
free(pstu);//釋放該節點內存空間
return0;
}
//while循環的作用是找到當前鏈表的最後一個節點
while(ps->next)
ps=ps->next;
//把新節點加入到最後那個節點的後面
ps->next=pstu;
pstu->next=NULL;
return1;
}
//5.返回指定編號學生節點的上一個節點的指針
PSTUDENTGetPrevAddr(intnum)
{
PSTUDENTpstu=&g_head;
while(pstu->next)
{
if(pstu->next->num==num)
returnpstu;
pstu=pstu->next;
}
returnNULL;
}
//6.顯示所有學生信息
voidShowAll()
{
PSTUDENTpstu=&g_head;
printf("-------------------------------------------------------------------- ");
printf("編號姓名性別年齡專業 ");
printf("-------------------------------------------------------------------- ");
while(pstu->next)
{
printf("%-8d",pstu->next->num);
printf("%-20s",pstu->next->name);
printf("%-6s",pstu->next->sex==MAN?"男":"女");
printf("%4d",pstu->next->age);
printf("%20s ",pstu->next->major);
pstu=pstu->next;//讓指針指向下一個節點
}
printf("-------------------------------------------------------------------- ");
}
//7.顯示信息數量
intShowStudentCount()
{
intcount=0;
PSTUDENTpstu=&g_head;
while(pstu->next)
{
++count;
pstu=pstu->next;
}
printf(" 當前共有%d位學生信息。 ",count);
returncount;
}
//8.修改學生信息,參數為要修改的學生的編號
voidModityStudent(intnum)
{
PSTUDENTpstu=GetPrevAddr(num);//獲取要修改的學生節點的上一個節點
intchoose;
if(!pstu)
{
printf("沒有編號為%d的學生信息。 ",num);
return;
}
pstu=pstu->next;//將要修改的學員節點的指針改為指向自己的
printf("當前學生的姓名為%s,",pstu->name);
if(Question("確定要修改嗎?"))
{
printf("請輸入學生的姓名(小於20字元):");
scanf("%20s",pstu->name);
}
printf("當前學生的性別為%s,",pstu->sex==MAN?"男":"女");
if(Question("確定要修改嗎?"))
{
printf("請輸入學生的性別(1.男2.女):");
while(1!=scanf("%d",&choose)||choose<1||choose>2)
{
printf("輸入錯誤,請重新輸入學生的性別(1.男2.女):");
fflush(stdin);
}
if(1==choose)
pstu->sex=MAN;
else
pstu->sex=WOMAN;
}
printf("當前學生的年齡為%d,",pstu->age);
if(Question("確定要修改嗎?"))
{
printf("請輸入學生的年齡(10~40):");
while(1!=scanf("%d",&pstu->age)||pstu->age<10||pstu->age>40)
{
printf("年齡輸入錯誤!請重新輸入學生的年齡(10~40):");
fflush(stdin);
}
}
printf("當前學生的專業為%s,",pstu->major);
if(Question("確定要修改嗎?"))
{
printf("請輸入學生的專業(小於20字元):");
scanf("%20s",pstu->major);
}
printf("修改完畢! ");
}
//9.獲取用戶的選擇
intQuestion(constchar*pstr)
{
charanswer;
printf("%s請選擇(yorn):",pstr);
while(1!=scanf("%c",&answer)||(answer!='y'&&answer!='n'))
{
printf("輸入錯誤!%s請重新選擇(yorn):",pstr);
fflush(stdin);//清空輸入緩沖區,C庫函數
}
if('y'==answer)
return1;
else
return0;
}
//10.獲取用戶輸入的學生的編號
intGetInputNum()
{
intnum;
printf("請輸入學生的編號(整型):");
while(1!=scanf("%d",&num))
{
printf("編號輸入錯誤!請重新輸入學生的編號(整型):");
fflush(stdin);
}
returnnum;
}
//11.刪除編號為num的學生信息
voidDelStudent(intnum)
{
PSTUDENTpstu,ptmp;
if(pstu=GetPrevAddr(num))
{
if(!Question("確定要刪除該學生信息嗎?"))
{
return;
}
ptmp=pstu->next;
pstu->next=ptmp->next;
free(ptmp);
printf("刪除了編號為%d的學生信息。 ",num);
}
else
{
printf("沒有找到編號為%d的學生信息。 ",num);
}
}
//12.刪除所有的學生信息
voidDelAll()
{
PSTUDENTpstu=g_head.next,ptmp;
intcount=0;
if(!Question("確定要刪除當前所有的學生信息嗎?"))
{
return;
}
while(pstu)
{
ptmp=pstu;
pstu=pstu->next;
free(ptmp);
++count;
}
printf("共刪除了%d位學生信息。 ",count);
g_head.next=NULL;
}
//13.把學生信息保存到文件當中
voidSaveToFile()
{
FILE*pf=fopen(FILENAME,"wb");
PSTUDENTpstu=&g_head;
inti=0,count=ShowStudentCount();
if(!pf)
{
printf("打開待寫入的文件失敗! ");
return;
}
if(!Question("確定要將當前學生信息保存到文件中嗎?"))
{
fclose(pf);
return;
}
fwrite(&count,1,sizeof(count),pf);//把學生信息的數量先寫入到文件頭
while(pstu->next)
{
fwrite(pstu->next,1,sizeof(STUDENT),pf);//把每位學生信息寫入文件
++i;
pstu=pstu->next;
}
fclose(pf);
if(i==count)
{
printf("成功的寫入了%d條學生信息。 ",count);
}
else
{
printf("應寫入%d條學生信息,實際寫入%d條學生信息。 ",count,i);
}
}
//14.從文件中讀取學生信息
voidLoadFromFile()
{
inti,count=0,repeat=0;
FILE*pf;
PSTUDENTpstu;
printf("提示:從文件中讀取學生信息會詢問是否清空當前學生信息(不清空表示合並所有信息)。 ");
if((pf=fopen(FILENAME,"rb"))==NULL)
{
printf("文件還沒有創建,請手工輸入學生信息並保存吧! ");
return;
}
DelAll();//刪除之前的所有學生信息,然後從文件中讀取
fread(&count,1,sizeofcount,pf);//獲取學生信息的數量
for(i=0;i<count;++i)
{
pstu=(PSTUDENT)malloc(sizeof(STUDENT));
fread(pstu,1,sizeof(STUDENT),pf);
if(!AddStudent(pstu))
{
++repeat;//保持有多少個和當前鏈表中相重復的學生信息
}
}
fclose(pf);
printf("文件讀取完畢!新增學生信息%d條。 ",count-repeat);
}

這個累死我了,我要財富值。。。為了這個不容易啊

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

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