導航:首頁 > 源碼編譯 > 學生信息錄入系統源碼

學生信息錄入系統源碼

發布時間:2023-05-07 00:52:47

❶ c語言學生成績管理系統1000行源代碼

/*首次使用,新建score.in文件,在裡面打入0
可用程序
#include<stdio.h>
FILE *fin
main()
{
fin=fopen("score.in","r");
fprintf(fin,"0");
return 0;
}
完成
*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<time.h>
#define n 999
FILE *fin;
main()
{
int a[n]={0},ori=0,i=0,b=0,add[n]={0},con=0,orix[n]={0},t=0,te[n]={0},TRUEt,ixi,fx,abc=0,sum,TURE,xx;
long long f[n]={0},tex[n]={0};
printf("\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t學生成績管理系統\n\t\t\t\t\t\t Please wait...");
Sleep(2000);system("cls");
int xp,xi;
fin=fopen("score.in","r+");
fscanf(fin,"%d",&xp);
i=xp;
for(xi=1;xi<=xp;xi++)
{fscanf(fin,"%d%d%d",&f[xi],&a[xi],&te[xi]);te[xi]--;
printf("Id:%lld score:%d ranking:%d\n",f[xi],a[xi],te[xi]+1);
add[xi]=xi;orix[xi]=a[xi];
}
fclose(fin);
int TRUE1;
pe:
while(1)
{ TRUE1=1;i++;
printf("Id(輸入-1:刪除,輸入-2:修改成績,輸入-3:刪除所有內容,輸入-4:保存到score.in並退出):");
scanf("%lld",&f[i]);
for(sum=1;sum<i;sum++)
if(f[sum]==f[i])
{system("cls");for(con=1;con<=i;con++) {if(a[con]==0)continue;printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}TRUE1=0;i--;printf("Error with two same id.\n");continue;}
if(TRUE1==0)
continue;
if(f[i]==-3)
{int r;
for(r=0;r<n;r++)
{
a[r]=0;ori=0;i=0;b=0;add[r]=0;con=0;orix[r]=0;t=0;te[r]=0;abc=0;
f[r]=0;tex[r]=0;
}
system("cls");
goto pe;
}
if(f[i]==-2)
{TURE=0;i--;
system("cls");
for(con=1;con<=i;con++)
{if(a[con]==0)continue; printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}
printf("修改學號_____________號的分數.\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b",f[con],a[con],te[con]+1);
scanf("%d",&xx);
for(sum=1;sum<=i;sum++)
if(f[sum]==xx)
{
TURE=1;
printf("\n修改為___________.\b\b\b\b\b\b\b\b\b\b\b\b");
scanf("%d",&a[sum]);
printf("\n修改成功!將在下一次輸入後更新名次。\n\n");
continue;
}
if(TURE==0)
printf("No id is %d\n",xx);
continue;
}
if(f[i]==-4)
{
i--;
fin=fopen("score.in","r+");
fprintf(fin,"%d\n",i);
for(xi=1;xi<=i;xi++)fprintf(fin,"%d %d %d\n",f[xi],a[xi],te[xi]+1);
for(xi=i+1;xi<=xp;xi++)fprintf(fin," \n");
fclose(fin);
return 0;
}
if(f[i]==-1)
{TRUEt=0;
system("cls");
i--;
for(con=1;con<=i;con++){if(a[con]==0)continue;printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}
printf("刪除學號_____________號.\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
scanf("%lld",&fx);
for(con=1;con<=i;con++)
if(f[con]==fx)
{TRUEt=1;abc++;
f[con]=0;
a[con]=0;
tex[abc]=te[con];
for(ixi=1;ixi<=i;ixi++)
if(te[ixi]>te[con])
te[ixi]--;
te[con]=0;
break;}
system("cls");
for(con=1;con<=i;con++){
if(a[con]==0)continue;
printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}
if(TRUE==0)
printf("No Id is %lld\n",fx);
continue;
}
system("cls");
for(con=1;con<i;con++)
{if(a[con]==0)continue; printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}
printf("Id:%lld score:",f[i]);
scanf("%d",&ori);system("cls");
a[i]=ori;add[i]=i;orix[i]=a[i];
system("cls");
for(b=1;b<=i;b++)
for(con=i;con>=b;con--)
if(orix[con]>orix[con-1])
{t=orix[con];orix[con]=orix[con-1];orix[con-1]=t;
t=add[con];add[con]=add[con-1];add[con-1]=t;}
for(con=1;con<=i;con++) te[add[con]]=con;
for(con=1;con<=abc;con++)
for(ixi=1;ixi<=i;ixi++)
if(te[ixi]>tex[con])
te[ixi]--;
if(te[i]==te[i-1])te[i]=0;
for(con=1;con<=i;con++)
{if(a[con]==0)continue;printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}
}
return 0;
}
//求採納

❷ 學生信息管理系統C++源代碼

#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#define INIT_SIZE 10
#define INCRE_SIZE 10
#define SUBJECT_NUM 3
#define LEN 3

void show_Start();

void show_Table();

void addRecord();

void Info_delete();
void deleteRecord();
void delete_Num(int);
void delete_Name(char tarName[]);

void Info_modify();
void modifyRecord();
void modify_Num(int);
void modify_Name(char[]);

void Info_query();
void queryRecord();
void query_Num(int);
void query_Name(char[]);

void display();

void quit();

void menu_CMD();

char *subject[SUBJECT_NUM] = {"高代","數分","C語言"};

struct STUDENT
{
int num;
char name[20];
char sex;
float score[SUBJECT_NUM];
};

//struct STUDENT stu[LEN + 1];

//STUDENT *record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);

int static stuNum = 0;
//先暫時定義三個學生吧...

STUDENT *record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);;

int main()
{
//record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);
//STUDENT *record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);

/*
record[1].num = 1001;
strcpy(record[1].name,"Jason");
record[1].sex = 'M';
record[1].score[0] = 85.0;
record[1].score[1] = 90.0;
record[1].score[2] = 95.0;

record[2].num = 1002;
strcpy(record[2].name,"Jerry");
record[2].sex = 'M';
record[2].score[0] = 85.0;
record[2].score[1] = 90.0;
record[2].score[2] = 95.0;

record[3].num = 1003;
strcpy(record[3].name,"Jessie");
record[3].sex = 'F';
record[3].score[0] = 85.0;
record[3].score[1] = 90.0;
record[3].score[2] = 95.0;
*/

/*
Info_modify();
int key;
cout<<"請輸入您的選擇 : ";
cin>>key;

if(key == 1)
{
int targetNum;
cout<<"請輸入您欲修改的學生的學號 : ";
cin>>targetNum;

modify_Num(targetNum);
cout<<endl;

display();
}

if(key == 2)
{
char targetName[20];
cout<<"請輸入您欲修改學生的姓名 : ";
cin>>targetName;

modify_Name(targetName);
cout<<endl;

display();
}

if(key == 3)
{
exit(0);
}
*/

show_Start();

menu_CMD();

return 0;

}

//修改完後還應該顯示
void show_Start()
{
//cout<<endl;
cout<<" **************************************** "<<endl;
cout<<" 這是一個 "<<endl;
cout<<" 學生成績管理系統 "<<endl;
cout<<" 可以對學生成績進行管理 "<<endl;
cout<<" 歡迎大家使用 "<<endl;
cout<<" Made by Jason "<<endl;
cout<<" **************************************** "<<endl;
}

// 顯示表頭信息,即是 : 學號,姓名,性別,高代,數分,C語言.
void show_Table()
{
cout<<"學號"<<"\t"<<"姓名"<<"\t"<<"性別";
cout<<"\t"<<subject[0]<<"\t"<<subject[1]<<"\t"<<subject[2];
cout<<endl;
}

void menu_CMD()
{
int key;
while(1)
{
cout<<"1. 增加學生信息"<<endl;
cout<<"2. 刪除學生信息"<<endl;
cout<<"3. 修改學生信息"<<endl;
cout<<"4. 查詢學生信息"<<endl;
cout<<"5. 顯示學生信息"<<endl;
cout<<"6. 退出"<<endl;
cout<<"請輸入您的選擇 : ";
cin>>key;
while(1)
{
if((key < 1)||(key > 6))
{
int key;
cout<<"您的輸入有誤,請重新輸入!"<<endl;
cout<<"請選(1 - 5) : ";
cin>>key;
}
else
{
break;
}
}
switch(key)
{
case 1:
addRecord();
break;
case 2:
deleteRecord();
break;
case 3:
modifyRecord();
break;
case 4:
queryRecord();
break;
case 5:
display();
break;
case 6:
quit();
break;
}

}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

//增加學生信息
void addRecord()
{

if(stuNum == 0)
{
cout<<"原來沒有記錄,現在建立新表!"<<endl;
stuNum++;
}
else
{
cout<<"現在在當前表的末尾添加新的信息!"<<endl;
stuNum++;
}

//如果數組空間不夠,重新申請空間
if(stuNum > INIT_SIZE)
{
cout<<"內存空間不夠,現在重新申請新的內存空間!"<<endl;
record = (STUDENT*)realloc(record,(INIT_SIZE + INCRE_SIZE)*sizeof(STUDENT));
cout<<"空間申請完成!"<<endl;
}

cout<<"您現在要添加一組新的信息,您確定嗎?"<<endl;
cout<<"請輸入您的選擇(Y/N) : ";
char choi;
cin>>choi;
if((choi == 'Y')||(choi == 'y'))
{
cout<<"請輸入學號 : ";
cin>>record[stuNum].num;
cout<<"請輸入姓名 : ";
cin>>record[stuNum].name;
cout<<"請輸入性別(M為男,F為女) : ";
cin>>record[stuNum].sex;

int i;
for(i = 0;i < SUBJECT_NUM;i++)
{
cout<<"請輸入"<<subject[i]<<"的成績 : ";
cin>>record[stuNum].score[i];
}
}

if((choi == 'N')||(choi == 'n'))
{
cout<<"退出添加新學生信息!"<<endl;
cout<<endl;
}

cout<<"現在已經有"<<stuNum<<"條學生的信息了!"<<endl;
cout<<endl;
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//刪除信息 晚上完成...

//顯示deleteRecord的表頭信息
void Info_delete()
{
cout<<"請輸入刪除方式 : "<<endl;
cout<<"1. 按學號刪除"<<endl;
cout<<"2. 按姓名刪除"<<endl;
cout<<"3. 退出刪除"<<endl;
}

//刪除學生的信息,包含兩個子函數
void deleteRecord()
{
int key;
cout<<endl;
Info_delete();
cout<<"請輸入您的選擇 : ";
cin>>key;

if(key == 1)
{
int targetNum;
cout<<"請輸入您欲刪除學生的學號 : ";
cin>>targetNum;

//按學號刪除
delete_Num(targetNum);
cout<<endl;
}

if(key == 2)
{
char targetName[20];
cout<<"請輸入您欲刪除學生的姓名 : ";
cin>>targetName;

//按姓名刪除
delete_Name(targetName);
cout<<endl;
}

if(key == 3)
{
while(1)
{
menu_CMD();

}
}
}

//按學號刪除學生信息
//只用完成刪除操作,而不必輸出. 輸出的操作可以在主菜單中進行

void delete_Num(int tarNum)
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(record[i].num == tarNum)
{
//刪除還要分兩種情況討論
//1. 欲刪除的學生信息是最後一位
//2. 欲刪除的學生信息不是最後一位

//第一種情況,欲刪除的學生是最後一位
if(i = stuNum)
{
cout<<"您所要刪除的學生信息是 : "<<endl;
show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"
<<record[i].score[0]<<record[i].score[1]<<"\t"<<record[i].score[2];
cout<<endl;

cout<<endl<<"刪除後學生信息表為 : "<<endl;
show_Table();
for(int i = 1;i <= stuNum - 1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
//顯示信息應該放在後面
/*
stuNum--;
cout<<"現在還剩下"<<stuNum<<"條學生的信息";
cout<<endl;
*/
}

//2.第二種情況,欲刪除的學生不是最後一位
if(i != stuNum)
{

cout<<"您所要刪除的學生信信息是 : "<<endl;
show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"
<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];

for(int j = i+1;j <= stuNum;j++)
{
record[j-1] = record[j];
}

//接著完成輸出

cout<<endl;
cout<<"刪除後學生信息表為 : "<<endl;
show_Table();
for(int i = 1;i <= stuNum-1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
/*
stuNum--;
cout<<"現在還剩下"<<stuNum<<"條學生的信息";
cout<<endl;
*/
}

stuNum--;
cout<<"現在還是剩下"<<stuNum<<"條學生的信息";
cout<<endl;
}
}
}

/*

//方法同上
void delete_Name(char tarName[])
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(strcmp(record[i].name,tarName) == 0)
{
//刪除還要分兩種情況討論
//1. 欲刪除的學生信息是最後一位
//2. 欲刪除的學生信息不是最後一位

//第一種情況 : 欲刪除學生是最後一位
if(i = stuNum)
{
cout<<"您所要刪除的學生信息是 : "<<endl;
show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"
<<record[i].score[0]<<record[i].score[1]<<"\t"<<record[i].score[2];
cout<<endl;

cout<<endl<<"刪除後學生信息表為 : "<<endl;
show_Table();
for(int i = 1;i <= stuNum - 1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
}

//第二種情況 : 欲刪除學生不是最後一位
if(i != stuNum)
{

cout<<"您所要刪除的學生信信息是 : "<<endl;
show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"
<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];

//整體往前 前移一位
for(int j = i+1;j <= stuNum;j++)
{
record[j-1] = record[j];
}
cout<<endl;

//接著完成輸出
cout<<"刪除後學生信息表為 : "<<endl;
show_Table();
for(int i = 1;i <= stuNum-1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}

cout<<endl;
}
}

}

}

*/

void delete_Name(char tarName[])
{
int i;
for(i = 1;i <= stuNum;i++)
{

//刪除還要分兩種情況討論
//1. 欲刪除的學生信息是最後一位
//2. 欲刪除的學生信息不是最後一位

//當欲刪除的學生是最後一位,直接輸出前面LEN-1位學生的信息

if(strcmp(record[i].name,tarName) == 0)
{
if(i == stuNum)
{
cout<<"您所要刪除的學生信息是 : "<<endl;
show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"
<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];

cout<<endl;

cout<<"刪除後學生信息表為 : "<<endl;
show_Table();
for(int i = 1;i <= stuNum-1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
/*
stuNum--;
cout<<"現在還剩下"<<stuNum<<"條學生的信息";
cout<<endl;
*/
}

//當欲刪的學生不是最後一位,整體往前前移一位
if(i != stuNum)
{
cout<<"您所要刪除的學生信息是 : "<<endl;

show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t";
cout<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];
cout<<endl;

//整體往前前移一位
for(int j = i+1;j <= stuNum;j++)
{
record[j-1] = record[j];
}

//然後輸出
cout<<endl;
cout<<"刪除後學生信息表為 : "<<endl;

show_Table();
for(int i = 1;i <= stuNum-1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
/*
stuNum--;
cout<<"現在還剩下"<<stuNum<<"條學生的信息";
cout<<endl;
*/
}

stuNum--;
cout<<"現在還剩下"<<stuNum<<"條學生的信息";
cout<<endl;
}
}
}

/*****************************************************************************
******************************************************************************/

//顯示modifyRecord的表頭信息
void Info_modify()
{
cout<<"請輸入修改方式 : "<<endl;
cout<<"1. 按學號修改"<<endl;
cout<<"2. 按姓名修改"<<endl;
cout<<"3. 退出修改"<<endl;
}

//查詢學生的成績,當然裡麵包括兩個子函數
void modifyRecord()
{
int key;
cout<<endl;
Info_modify();
cout<<"請輸入您的選擇 : ";
cin>>key;

//按學號修改
if(key == 1)
{
int targetNum;
cout<<"請輸入您欲修改的學生的學號 : ";
cin>>targetNum;

modify_Num(targetNum);
cout<<endl;

//display();
}

//按姓名修改
if(key == 2)
{
char targetName[20];
cout<<"請輸入您欲修改學生的姓名 : ";
cin>>targetName;

modify_Name(targetName);
cout<<endl;

//display();
}

//退出修改
if(key == 3)
{
while(1)
{
menu_CMD();
}
}
}

//按學號修改
void modify_Num(int tarNum)
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(record[i].num == tarNum)
{
cout<<endl<<"請修改該學生的信息"<<endl;
cout<<"請輸入該學生的學號 : ";
cin>>record[i].num;
cout<<"請輸入該學生的姓名 : ";
cin>>record[i].name;
cout<<"請輸入該學生的性別 : ";
cin>>record[i].sex;
cout<<"請輸入"<<subject[0]<<"的成績 : ";
cin>>record[i].score[0];
cout<<"請輸入"<<subject[1]<<"的成績 : ";
cin>>record[i].score[1];
cout<<"請輸入"<<subject[2]<<"的成績 : ";
cin>>record[i].score[2];
}
}
}

//按姓名修改
void modify_Name(char tarName[])
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(strcmp(record[i].name,tarName) == 0)
{
cout<<endl<<"請修改該學生的信息 : "<<endl;
cout<<"請輸入該學生的學號 : ";
cin>>record[i].num;
cout<<"請輸入該學生的姓名 : ";
cin>>record[i].name;
cout<<"請輸入該學生的性別 : ";
cin>>record[i].sex;
cout<<"請輸入"<<subject[0]<<"的成績 : ";
cin>>record[i].score[0];
cout<<"請輸入"<<subject[1]<<"的成績 : ";
cin>>record[i].score[1];
cout<<"請輸入"<<subject[2]<<"的成績 : ";
cin>>record[i].score[2];
}
}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

//顯示queryRecord的表頭信息
void Info_query()
{
cout<<"請輸入查詢方式 : "<<endl;
cout<<"1. 按學號查詢"<<endl;
cout<<"2. 按姓名查詢"<<endl;
cout<<"3. 退出查詢"<<endl;
}

//查詢學生信息queryRecord
void queryRecord()
{
int key;
cout<<endl;
Info_query();
cout<<"請輸入您的選擇 : ";
cin>>key;

if(key == 1)
{
int targetNum;
cout<<"請輸入您欲查詢學生的學號 : ";
cin>>targetNum;

query_Num(targetNum);
cout<<endl;
}

if(key == 2)
{
char targetName[20];
cout<<"請輸入您欲查詢學生的學號 : ";
cin>>targetName;

query_Name(targetName);
cout<<endl;
}

//退出查詢,退回到主菜單吧...
if(key == 3)
{
while(1)
{
menu_CMD();
}
}
}

//按學號查詢
void query_Num(int tarNum)
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(record[i].num == tarNum)
{
//如果表中有該學生信息的話,僅用輸出該學生的信息即可.
//輸出該學生的信息
cout<<"該學生的信息如下 : "<<endl;

//顯示表頭信息
show_Table();

//顯示該學生具體的信息
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
cout<<"\t"<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];
cout<<endl;
}
}
}

//按姓名查詢
void query_Name(char tarName[])
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(strcmp(record[i].name,tarName) == 0)
{
cout<<"該學生的信息如下 : "<<endl;

show_Table();

cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
cout<<"\t"<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];
cout<<endl;
}
}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

//先顯示所有學生的信息吧
//顯示record里所有學生的成績
void display()
{
show_Table();
int i,j;
for(i = 1;i <= stuNum;i++)
{
//cout<<"學號"<<"\t"<<"姓名"<<"\t"<<"性別";
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
cout<<endl;
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

//退出
void quit()
{
char choi;
cout<<"您確定要退出嗎?"<<endl;
cout<<"請輸入您的選擇(Y/N) : ";
cin>>choi;
if((choi == 'Y')||(choi == 'y'))
{
cout<<"現在退出學生信息管理系統"<<endl;
exit(0);
}
//如果不是退出,則接著退回到主界面
else
{
cout<<endl;
menu_CMD();
}

}

這個是原創的... 在C-Free 4.0里跑過,可以正常運行
你可以試著跑一下,如果有什麼問題可以和我聯系

❸ 學生信息管理系統源代碼

void Sort(student *&head, char type,char maxOrMin)
{
/*參數說明:
type=='1' 按 語文 排列
type=='2' 按 數學 排列
type=='3' 按 英語 排列
type=='4' 按 總分 排列
type=='5' 按 平均分 排列
type=='6' 按 座號 排列
*/
student *pHead,*pH;
pHead=pH=head;
int len=GetLength(head);
float *array=new float[len];
int i;
int x=0;

float num=0;

while(head)
{
Count(head);
if(type=='1')
{
num=head->chinaNum;
}
else if(type=='2')
{
num=head->mathNum;
}
else if(type=='3')
{
num=head->englishNum;
}
else if(type=='4')
{
num=head->result;
}
else if(type=='5')
{

num=head->average;
}
else if(type=='6')
{
num=head->num;
}
array[x]=num;
x++;
head=head->next;
}

head=pHead;
if(maxOrMin=='1')
{
for( i=1; i<len; i++)
{
for(int j=0; j<len-i; j++)
{
if(array[j]<array[j+1])
{
float num;
num=array[j];
array[j]=array[j+1];
array[j+1]=num;
}
}
}
}
else
{
for( i=1; i<len; i++)
{
for(int j=0; j<len-i; j++)
{
if(array[j]>array[j+1])
{
float num;
num=array[j];
array[j]=array[j+1];
array[j+1]=num;
}
}
}
}

int pos=1;

for(i=0; i<len; i++)
{
head=pHead;
while(head)
{
if(type=='1')
{
num=head->chinaNum;
}
else if(type=='2')
{
num=head->mathNum;
}
else if(type=='3')
{
num=head->englishNum;
}
else if(type=='4')
{
num=int(head->result);
}
else if(type=='5')
{
num=int(head->average);
}
else if(type=='6')
{
num=int(head->num);
}

int n=0;
if(int(array[i])==int(num))
{

if(int(array[i])!=int(array[i+1]))
{
if(n==0)
{
n=pos;
}
head->pos=pos;
pos++;
}
else
{

head->pos=n;
}
}
head=head->next;
}
}
head=pH;
delete []array;
}

void Count(student *&head)
{
head->result=head->chinaNum+head->englishNum+head->mathNum;
head->average=head->result/3;
}

void DeleteAll(student* &head)
{
student *cp,*np;

cp=head;
while(cp)
{
np=cp->next;
delete cp;
cp=np;
}
head=NULL;
}

void ChaXun(string str,student *head)
{
Sort(head,'4','1');
cout<<"歡迎使用查詢功能"<<endl<<endl;
cout<<"請輸入你要按什麼查詢 1->一般查詢 2->查找最多 3->查找最少"<<endl;
string s;
cin>>s;
while(s[0]!='1'&&s[0]!='2'&&s[0]!='3')
{
cout<<"你輸入錯誤,請重新輸入."<<endl;
cin>>s;
}

if(s[0]=='1')
{
cout<<"按什麼查詢?"<<endl;
cout<<"1->姓名 2->座號 3->語文成績 4->數學成績 "
<<"5->英語成績 6->總分 7->平均分 8->排名"<<endl;
cin>>str;

while(str[0]!='1' && str[0]!='2' &&
str[0]!='3' && str[0]!='4' &&
str[0]!='5' && str[0]!='6' &&
str[0]!='7' && str[0]!='8' )
{
cout<<"你輸入錯誤,請重新輸入."<<endl;
cin>>str;
}
char findStr[30];
cout<<"請輸入要查找的關鍵字或關鍵數:"<<endl;
cin>>findStr;
switch(str[0])
{

case '1':
Find(head,findStr,'1');
break;
case '2':
Find(head,findStr,'2');
break;
case '3':
Find(head,findStr,'3');
break;
case '4':
Find(head,findStr,'4');
break;
case '5':
Find(head,findStr,'5');
break;
case '6':
Find(head,findStr,'6');
break;
case '7':
Find(head,findStr,'7');
break;
case '8':
Find(head,findStr,'8');
break;
}
}
else if(s[0]=='2')
{
cout<<"請輸入要按什麼查詢?"<<endl;
cout<<"1->語文成績 2->數學成績 "
<<"3->英語成績 4->總分 5->平均分 6->排名"<<endl;
string s;
cin>>s;
switch(s[0])
{
case '1':
FindMaxOrMin(head,'1','1');
break;
case '2':
FindMaxOrMin(head,'2','1');
break;
case '3':
FindMaxOrMin(head,'3','1');
break;
case '6':
FindMaxOrMin(head,'6','1');
break;
case '5':
FindMaxOrMin(head,'5','1');
break;
default:
FindMaxOrMin(head,'4','1');
break;
}
}
else if(s[0]=='3')
{
cout<<"請輸入要按什麼查詢?"<<endl;
cout<<"1->語文成績 2->數學成績 "
<<"3->英語成績 4->總分 5->平均分 6->排名"<<endl;
string s;
cin>>s;
switch(s[0])
{
case '1':
FindMaxOrMin(head,'1','2');
break;
case '2':
FindMaxOrMin(head,'2','2');
break;
case '3':
FindMaxOrMin(head,'3','2');
break;
case '6':
FindMaxOrMin(head,'6','2');
break;
case '5':
FindMaxOrMin(head,'5','2');
break;
default:
FindMaxOrMin(head,'4','2');
break;
}
}
}

void ZengJia(string str, student* &head)
{
student *pNew=new student;
cout<<"歡迎使用增加功能"<<endl<<endl;
cout<<"請輸入新學生的名字 :"<<endl;
cin>>pNew->name;
cout<<"請輸入新學生的座號 :"<<endl;
cin>>pNew->num;
cout<<"請輸入他的語文分數 :"<<endl;
cin>>pNew->chinaNum;
cout<<"請輸入他的數學分數"<<endl;
cin>>pNew->mathNum;
cout<<"請輸入他的英語分數"<<endl;
cin>>pNew->englishNum;

cout<<"插入記錄的 (1->最前面 2->最後面)"<<endl;
cin>>str;
while(str[0]!='1' && str[0]!='2')
{
cout<<"你輸入錯誤,請重新輸入."<<endl;
cout<<"插入記錄的 (1->最前面 2->最後面)"<<endl;
cin>>str;
}
if(str[0]=='1')
{
InsertFront(head,pNew);
}
else if(str[0]=='2')
{
InsertRear(head,pNew);
}
cout<<"新學生增加成功."<<endl;

}

void ShanChu(string str, student *&head)
{
char delStr[30];
cout<<"歡迎使用刪除功能"<<endl<<endl;
cout<<"1->查詢刪除 2->全部刪除"<<endl;
cin>>str;
while(str[0]!='1' && str[0]!='2')
{
cout<<"輸入錯誤,請重新輸入."<<endl;
cin>>str;
}
if(str[0]=='1')
{
cout<<"請輸入要刪除的關鍵字"<<endl;
cin>>delStr;
cout<<"1->刪除第一條找到的記錄 2->刪除所有找到的記錄"<<endl;
cin>>str;
while(str[0]!='1'&&str[0]!='2')
{
cout<<"你輸入錯誤,請重新輸入."<<endl;
cin>>str;
}
cout<<"你真的要刪除嗎? 1->刪除 2->取消"<<endl;
string s;
cin>>s;
if(str[0]=='1')
{
if(str[0]=='1')
{
Delete(head,delStr,1);

}
else
{
Delete(head,delStr,2);
}
}
else
{
cout<<"你已經取消刪除了."<<endl;
}
}
else
{
cout<<"你真的要刪除全部數據嗎?這樣會使你的數據全部丟失哦."<<endl;
cout<<"1->全部刪除 2->取消刪除"<<endl;
cin>>str;
if(str[0]=='1')
{
DeleteAll(head);
}
else
{
cout<<"你已經取消刪除了."<<endl;
}
}

}

void PaiMing(string str, student* head)
{
string s;
cout<<"歡迎使用排名功能"<<endl<<endl;
cout<<"排名選擇: 1->升序 2->降序"<<endl;
cin>>s;
cout<<"請輸入要按什麼排名?"<<endl;
cout<<"1->語文成績 2->數學成績 3->英語成績 "
<<"4->總分 5->平均分 6->座號"<<endl;

cin>>str;

while(str[0]!='1' && str[0]!='2' &&
str[0]!='3' && str[0]!='4' &&
str[0]!='5' && str[0]!='6' )
{
cout<<"你輸入錯誤,請重新輸入."<<endl;
cin>>str;
}
cout<<"姓名:"<<setw(8)<<"座號:"<<setw(10)
<<"語文分數:"<<setw(10) <<"數學分數:"
<<setw(10)<<"英語分數:"<<setw(8)<<"總分數:"
<<setw(8)<<"平均分:"<<setw(6)<<"名次:"<<endl<<endl;
if(s[0]=='2')
{
switch(str[0])
{

case '1':
Sort(head,'1','1');
break;
case '2':
Sort(head,'2','1');
break;
case '3':
Sort(head,'3','1');
break;
case '4':
Sort(head,'4','1');
break;
case '5':
Sort(head,'5','1');
break;
case '6':
Sort(head,'6','1');
break;
}
}
else
{

switch(str[0])
{

case '1':
Sort(head,'1','2');
break;
case '2':
Sort(head,'2','2');
break;
case '3':
Sort(head,'3','2');
break;
case '4':
Sort(head,'4','2');
break;
case '5':
Sort(head,'5','2');
break;
case '6':
Sort(head,'6','2');
break;
}

}
ShowList(head);
return ;
}

void XianShi(string str, student *head)
{
Sort(head,'4','1');

string s;
cout<<"歡迎使用顯示功能"<<endl;
cout<<"1->顯示全部記錄 2->顯示記錄數目"<<endl;
cin>>s;
if(s[0]=='2')
{
cout<<"記錄的數目是:"<<GetLength(head)<<endl;
}
else
{
ShowList(head);
}
}

void XuiGai(string str, student *&head)
{
string s;
student *std;
cout<<"歡迎使用修改功能"<<endl;

cout<<"請輸入你要按什麼查詢"<<endl;
cout<<"1->姓名 2->座號 3->語文成績 4->數學成績 "
<<"5->英語成績 "<<endl;
cin>>str;

while(str[0]!='1' && str[0]!='2' &&
str[0]!='3' && str[0]!='4' &&
str[0]!='5' )
{
cout<<"你輸入錯誤,請重新輸入."<<endl;
cin>>str;
}
char findStr[30];
cout<<"請輸入要查找的關鍵字或關鍵數:"<<endl;
cin>>findStr;
switch(str[0])
{

case '1':
std=Find(head,findStr,'1');
Reword(std);
break;
case '2':
std=Find(head,findStr,'2');
Reword(std);
break;
case '3':
std=Find(head,findStr,'3');
Reword(std);
break;
case '4':
std=Find(head,findStr,'4');
Reword(std);
break;
case '5':
std=Find(head,findStr,'5');
Reword(std);
break;
}
Write(head);
if(std!=NULL)
{
cout<<"修改成功."<<endl;
}
}

int Run()
{

bool isLoad=false;
student* head=NULL;
student *pNew=new student;
head=Read();
SetTitle(false);
if(head!=NULL)
{ Sort(head,'5','1');
Count(head);

}
string str;
SetTitle(false);

cout<<" 歡迎使用學生管理系統 "<<endl<<endl;

cout<<" 1->用戶登陸 2->退出程序 "<<endl;
cin>>str;
if(str[0]=='2')
{
AboutMe();
return 0;
}
else
{
isLoad=Enter('1');
system("cls");

if(isLoad==true)
{
SetTitle(true);
cout<<" 恭喜,您輸入的密碼正確.可以對本系統的進行任何操作."<<endl;
}
else
{
cout<<" Sorry,您輸入的密碼錯誤.你不能修改本系統的任何內容."<<endl;
}
}
begin:
cout<<endl<<endl;
cout<<" 歡迎使用學生管理系統 "<<endl<<endl;
cout<<" 1->增加功能 2-查詢功能"<<endl;
cout<<" 3->刪除功能 4-排名功能"<<endl;
cout<<" 5->顯示功能 6-修改功能"<<endl;
cout<<" 7->用戶設置 8-退出程序"<<endl;
cout<<"請輸入您的選擇: "<<endl;
cin>>str;

while(str[0]!='8')
{
if(isLoad==true && head!=NULL)
{
cout<<endl<<endl;
if(str[0]=='1')
{
ZengJia(str, head);
Sort(head,'4','1');
Write(head);
}
else if(str[0]=='2')
{
ChaXun(str,head);
}
else if(str[0]=='3')
{
ShanChu(str,head);
Sort(head,'4','1');
Write(head);
}
else if(str[0]=='4')
{
PaiMing(str,head);
}
else if(str[0]=='5')
{
XianShi(str,head);
}
else if(str[0]=='6')
{
XuiGai(str,head);
Write(head);
}
else if(str[0]=='7')
{
cout<<"歡迎使用用戶修改功能"<<endl;
isLoad=Enter('2');
}
else if(str[0]=='8')
{
AboutMe();
return 0;
}
else
{
cout<<"你輸入錯誤,請重新輸入."<<endl;
goto begin;
}
}
else if(isLoad==false && head!=NULL)
{
if(str[0]=='2')
{
ChaXun(str,head);
}
else if(str[0]=='4')
{
PaiMing(str,head);
}
else if(str[0]=='5')
{
XianShi(str,head);
}

else
{
cout<<"你不是管理員,不能進行此項功能."<<endl;
cout<<"你只能進行 查詢功能 顯示功能 排名功能"<<endl;

}
}
else if( head==NULL && isLoad==true)
{
cout<<"系統檢查到你沒有任何記錄,不能進行任何操作,只能增加記錄."<<endl;
ZengJia(str, head);
Write(head);
head=Read();

}
else if( head==NULL && isLoad==false)
{
cout<<"因為你沒有登陸,系統又檢查到你沒有任何記錄,你不能進行任何操作."<<endl;
}

cout<<endl<<endl;
cout<<"按任何鍵繼續進行操作."<<endl;
getchar();
getchar();
system("cls");
goto begin;
}

AboutMe();

return 0;
}

void SetTitle(bool isLoad)
{

HWND hwnd=GetForegroundWindow();

if(isLoad==false)
{
SetWindowText(hwnd," 學生管理系統(沒有登陸)");

}
else
{
SetWindowText(hwnd," 學生管理系統(已經登陸)");
}

system("color a");
}

void AboutMe()
{

char*pStr= " ┃ \n"
" ┃ \n"
" ┏━━━━┻━━━━┓ \n"
" ┃ 關於作者 ┃ \n"
" ┏━━━━┻━━━━━━━━━┻━━━━┓\n"
" ┃ ┃\n"
" ┃ Aauthor:********** ┃\n"
" ┃ QQ: ********* ┃\n"
" ┃ E-mail:********@**.com ┃\n"
" ┃ ┃\n"
" ┗━━━━━━━━━━━━━━━━━━━┛\n";
system("cls");

srand(time(0));
for(int i=0; i<strlen(pStr); i++)
{
if(pStr[i]!=' ')
{
Sleep(20);
}
cout<<pStr[i];
}
cout<<"Good-bye ."<<endl;
cout<<endl<<endl<<endl<<endl;
}
int main()
{
Run();
return 0;
}

❹ 學生基本信息管理系統C++源代碼

#include<iostream>
#include<iomanip>
#include<string>

usingnamespacestd;

typedefstructstudent{
unsignedm_id;
stringm_name;
unsignedm_age;
stringm_sex;
stringm_address;
stringm_contact;
stringm_dormitory;
structstudent*m_next;
}student;

classCStudent{
private:
student*head;
public:
CStudent(){
head=newstudent;
head->m_id=0;
head->m_name="noname";
head->m_next=NULL;
}
~CStudent(){
student*p=head,*q;
while(p){
q=p;
p=q->m_next;
deleteq;
}
}
studentreaddata(intmodel);//model=1:不讀取學號,2:不讀取姓名,其他,讀取所有信息
voidentering();
boolinsert(conststudent&astu);
student*findid(unsignedid)const;
student*findname(conststring&name)const;
student*findsex(conststring&sex)const;
student*finddormitory(conststring&dormitory)const;
unsignedboys()const;
unsignedgirls()const;
unsignedheadcount()const;
booleraseid();
boolerasename();
boolmodifyid();
boolmodifyname();
voidShow()const;
voidquery()const;
voidfriendstatistics(constCStudent&aclss);
voidfrienderase(CStudent&aclss);
voidfriendmodify(CStudent&aclss);
};

stringreadstring(){
stringstr;
while(cin.get()!=' ');
cin>>str;
returnstr;
}

studentCStudent::readdata(intmodel){
studenttmp;
if(model!=1){cout<<"學號:";cin>>tmp.m_id;}
if(model!=2){cout<<"姓名:";tmp.m_name=readstring();}
cin>>tmp.m_age;
cout<<"性別:";
tmp.m_sex=readstring();
cout<<"住址:";
tmp.m_address=readstring();
cout<<"聯系方式:";
tmp.m_contact=readstring();
cout<<"寢室:";
tmp.m_dormitory=readstring();
returntmp;
}

voidCStudent::entering(){
studenttmp;
cout<<"學號(0toreturn):";
cin>>tmp.m_id;
while(tmp.m_id){
if(findid(tmp.m_id)==NULL){
cout<<"姓名:";
tmp.m_name=readstring();
cout<<"年齡:";
cin>>tmp.m_age;
cout<<"性別:";
tmp.m_sex=readstring();
cout<<"住址:";
tmp.m_address=readstring();
cout<<"聯系方式:";
tmp.m_contact=readstring();
cout<<"寢室:";
tmp.m_dormitory=readstring();
insert(tmp);
}
elsecout<<"重復的學號:"<<tmp.m_id<<endl;
cout<<"學號(0toreturn):";
cin>>tmp.m_id;
}
}

student*CStudent::findid(unsignedid)const{
student*p;
for(p=head;p->m_next;p=p->m_next)
if(p->m_next->m_id==id)returnp;
returnNULL;
}

student*CStudent::findname(conststring&name)const{
student*p;
for(p=head;p->m_next;p=p->m_next)
if(p->m_next->m_name==name)returnp;
returnNULL;
}


student*CStudent::findsex(conststring&sex)const{
student*p;
for(p=head;p->m_next;p=p->m_next)
if(p->m_next->m_sex==sex)returnp;
returnNULL;
}

student*CStudent::finddormitory(conststring&dormitory)const{
student*p;
for(p=head;p->m_next;p=p->m_next)
if(p->m_next->m_dormitory==dormitory)returnp;
returnNULL;
}

boolCStudent::insert(conststudent&astu){
student*newnode,*p=head;
if(p->m_next==NULL){
p->m_next=newstudent(astu);
p->m_next->m_next=NULL;
returntrue;
}
while(p->m_next){
if(p->m_next->m_id==astu.m_id){
cout<<"重復的學號,插入失敗! ";
returnfalse;
}
if(p->m_next->m_id>astu.m_id){
newnode=newstudent(astu);
newnode->m_next=p->m_next;
p->m_next=newnode;
returntrue;
}
p=p->m_next;
}
p->m_next=newstudent(astu);
p->m_next->m_next=NULL;
returntrue;
}

unsignedCStudent::boys()const{
unsignedcnt=0;
student*p;
for(p=head->m_next;p;p=p->m_next)
if(p->m_sex=="男")++cnt;
returncnt;
}

unsignedCStudent::girls()const{
unsignedcnt=0;
student*p;
for(p=head->m_next;p;p=p->m_next)
if(p->m_sex=="女")++cnt;
returncnt;
}

unsignedCStudent::headcount()const{
unsignedcnt=0;
student*p;
for(p=head->m_next;p;p=p->m_next,++cnt);
returncnt;
}

boolCStudent::eraseid(){
student*q,*p;
unsignedid;
cout<<"輸入要刪除的學號:";
cin>>id;
p=findid(id);
if(p==NULL){
cout<<"沒有找到學號是""<<id<<""的學生,刪除失敗! ";
returnfalse;
}
q=p->m_next;
p->m_next=q->m_next;
deleteq;
returntrue;
}
boolCStudent::erasename(){
student*q,*p;
stringname;
cout<<"輸入要刪除人的姓名:";
name=readstring();
p=findname(name);
if(p==NULL){
cout<<"沒有找到姓名是""<<name<<""的學生,刪除失敗! ";
returnfalse;
}
q=p->m_next;
p->m_next=q->m_next;
deleteq;
returntrue;
}

boolCStudent::modifyid(){
studenttmp,*p;
unsignedid;
cout<<"輸入要修改的學號:";
cin>>id;
p=findid(id);
if(p==NULL){
cout<<"沒有找到學號是""<<id<<""的學生,修改失敗! ";
returnfalse;
}
tmp=readdata(1);
tmp.m_id=id;
*p=tmp;
returntrue;
}

boolCStudent::modifyname(){
student*p,tmp;
stringname;
cout<<"輸入要修改人的姓名:";
name=readstring();
p=findname(name);
if(p==NULL){
cout<<"沒有找到姓名是""<<name<<""的學生,修改失敗! ";
returnfalse;
}
tmp=readdata(2);
tmp.m_name=name;
*p=tmp;
returntrue;
}

intmenu(){
intchoice;
do{
system("cls");
cout<<" **************************** ";
cout<<" *學生基本信息管理系統* ";
cout<<" *==========================* ";
cout<<" *1、錄入學生信息* ";
cout<<" *2、顯示學生信息* ";
cout<<" *3、查詢學生信息* ";
cout<<" *4、添加學生信息* ";
cout<<" *5、統計學生信息* ";
cout<<" *6、刪除學生信息* ";
cout<<" *7、修改學生信息* ";
cout<<" *0、退出管理系統* ";
cout<<" **************************** ";
cout<<" 請選擇:";
cin>>choice;
}while(choice<0||choice>7);
returnchoice;
}

voidshow(student*p){
cout<<p->m_id<<""<<p->m_name<<""<<p->m_age<<"";
cout<<p->m_sex<<""<<p->m_address<<"";
cout<<p->m_contact<<""<<p->m_dormitory<<endl;
}

voidCStudent::Show()const{
student*p;
cout<<"---------------------------------------------------------- ";
for(p=head->m_next;p;p=p->m_next)show(p);
cout<<"---------------------------------------------------------- ";
system("pause");
}

voidCStudent::query()const{
intselect;
unsignedid;
stringname;
student*p;
cout<<"1、按學號查詢 2、按姓名查詢 0、返回 ";
cin>>select;
switch(select){
case1:cout<<"請輸入學號:";cin>>id;
if(p=findid(id))show(p->m_next);
break;
case2:cout<<"請輸入姓名:";name=readstring();
if(p=findname(name))show(p->m_next);
break;
case0:return;
default:cout<<"選擇錯誤。 ";
}
system("pause");
}

voidstatistics(constCStudent&a){
unsignedtotal=a.headcount();
unsignedboys=a.boys();
unsignedgirls=a.girls();
cout<<"學生總數:"<<total<<"人。 ";
cout<<"其中,男生:"<<boys<<"名。";
cout<<"女生:"<<girls<<"名。 ";
system("pause");
}

voiderase(CStudent&a){
intselect;
unsignedid;
stringname;
student*p,*q;
cout<<"1、按學號刪除 2、按姓名刪除 0、返回 ";
cin>>select;
switch(select){
case1:cout<<"請輸入學號:";cin>>id;
if(p=a.findid(id)){
q=p->m_next;
p->m_next=q->m_next;
deleteq;
cout<<"成功刪除"<<id<<"的信息。 ";
}
break;
case2:cout<<"請輸入姓名:";name=readstring();
if(p=a.findname(name)){
q=p->m_next;
p->m_next=q->m_next;
deleteq;
cout<<"成功刪除"<<name<<"的信息。 ";
}
break;
case0:return;
default:cout<<"選擇錯誤。 ";
}
system("pause");
}

voidmodify(CStudent&a){
intselect;
cout<<"1、按學號修改 2、按姓名修改 0、返回 ";
cin>>select;
switch(select){
case1:if(a.modifyid())cout<<"修改成功。 ";break;
case2:if(a.modifyname())cout<<"修改成功。 ";break;
case0:return;
default:cout<<"選擇錯誤。 ";
}
system("pause");
}

intmain(){
CStudenta;
intan;
do{
an=menu();
switch(an){
case1:a.entering();break;
case2:a.Show();break;
case3:a.query();break;
case4:a.entering();break;
case5:statistics(a);break;
case6:erase(a);break;
case7:modify(a);break;
case0:break;
default:cout<<"選擇錯誤。 ";break;
}
}while(an);
return0;
}

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

方法一:

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

❻ 學生管理系統源代碼c++

#include <iostream.h>
#include <string.h>
#include "h1.h"
void menu();
void clear()
{
cin.clear();
cin.ignore();
}
void stu::init_name_grade() //輸入學生姓名、班級
{
cout<<"請輸入學生姓名:";
cin>>name;
clear();
cout<<"請輸入學生班級號:";
cin>>grade;
clear();
}

void stu::init_first() //輸入學生第一學期成績
{
cout<<"學生"<<name<<"第一學期成績"<<endl;
cout<<"請輸入英語成績:";
cin>>first.english;
clear();
cout<<"請輸入數學成績:";
cin>>first.math;
clear();
first.total=first.english+first.math;
first.aver=first.total/2;
}

void stu::init_second() //輸入學生第二學期成績
{
cout<<"學生"<<name<<"第二學期成績"<<endl;
cout<<"請輸入英語成績:";
cin>>second.english;
clear();
cout<<"請輸入數學成績:";
cin>>second.math;
clear();
second.total=second.english+second.math;
second.aver=second.total/2;
}

void stu::show_first() //顯示學生第一學期成績
{
cout<<"學生姓名:"<<name<<endl;
cout<<"學生班級:"<<grade<<endl;
cout<<"學生第一學期英語成績:"<<first.english<<endl;
cout<<"學生第一學期數學成績:"<<first.math<<endl;
cout<<"學生第一學期總成績:"<<first.total<<endl;
cout<<"學生第一學期平均成績:"<<first.aver<<endl;
}

void stu::show_second() //顯示學生第二學期成績
{
cout<<"學生姓名:"<<name<<endl;
cout<<"學生班級:"<<grade<<endl;
cout<<"學生第二學期英語成績:"<<second.english<<endl;
cout<<"學生第二學期數學成績:"<<second.math<<endl;
cout<<"學生第二學期總成績:"<<second.total<<endl;
cout<<"學生第二學期平均成績:"<<second.aver<<endl;
}

void stu::show_grade() //顯示學生所有學期成績
{
cout<<"學生姓名:"<<name<<endl;
cout<<"學生班級:"<<grade<<endl;
cout<<"學生第一學期英語成績:"<<first.english<<endl;
cout<<"學生第一學期數學成績:"<<first.math<<endl;
cout<<"學生第一學期總成績:"<<first.total<<endl;
cout<<"學生第一學期平均成績:"<<first.aver<<endl;
cout<<"學生第二學期英語成績:"<<second.english<<endl;
cout<<"學生第二學期數學成績:"<<second.math<<endl;
cout<<"學生第二學期總成績:"<<second.total<<endl;
cout<<"學生第二學期平均成績:"<<second.aver<<endl;
}

stu_info::stu_info() //stu_info的構造函數
{
num=0;
}

void stu_info::add_name_grade() //添加學生信息(班級、姓名)到數組中
{
int choose;
do
{
per[num].init_name_grade();
num++;
cout<<"繼續輸入學生信息嗎?(0:退出,任意數字鍵繼續...)";
cin>>choose;
clear();
}while(choose!=0);
}

void stu_info::add_first(int gra) //添加第一學期成績
{
for(int i=0;i<num;i++)
{
if(per[i].grade==gra)
{
per[i].init_first();
}
}
}

void stu_info::add_second(int gra) //添加第二學期成績
{
for(int i=0;i<num;i++)
{
if(per[i].grade==gra)
{
per[i].init_second();
}
}
}

void stu_info::query_aver(int gra,int term) //按班級、學期及平均分排序顯示學生成績
{
stu temp[100];
stu t;
int sum=0;
for(int i=0;i<num;i++)
{
if(per[i].grade==gra)
{
temp[sum]=per[i];
sum++;
}
}
for(int j=0;j<sum-1;j++)
{
for(int k=sum-1;k>j;k--)
{
if(term==1)
{
if(temp[k].first.aver>temp[k-1].first.aver)
{
t=temp[k];
temp[k]=temp[k-1];
temp[k-1]=t;
}
}
else if(term==2)
{
if(temp[k].second.aver>temp[k-1].second.aver)
{
t=temp[k];
temp[k]=temp[k-1];
temp[k-1]=t;
}
}
else
{
cout<<"該學期不存在!"<<endl;
return;
}
}
}
for( i=0;i<sum;i++)
{
if(term==1)
{
temp[i].show_first();
}
else
{
temp[i].show_second();
}
}
}

void stu_info::modify(int gra,char name[10]) //按班級、姓名查詢學生信息並修改學生信息
{
for(int i=0;i<num;i++)
{
if(per[i].grade==gra&&strcmp(per[i].name,name)==0)
{
per[i].init_name_grade();
per[i].init_first();
per[i].init_second();
return;
}
else
{
cout<<"該學生不存在!"<<endl;
}
}
}

void stu_info::query(int gra,char name[10]) //按班級、姓名查詢學生信息並輸出
{
for(int i=0;i<num;i++)
{
if(per[i].grade==gra&&strcmp(per[i].name,name)==0)
{
per[i].show_grade();
return;
}
else
{
cout<<"該學生不存在!"<<endl;
}
}
}

void stu_info::query_grade(int gra) //按班級輸出該班全部學生成績
{
cout<<gra<<"班級學生的成績如下:"<<endl;
for(int i=0;i<num;i++)
{
if(per[i].grade==gra)
{
per[i].show_grade();
}
}
}

void stu_info::show_fail(int grade,int term,int course)
{
cout<<"不及格名單如下:"<<endl;
for(int i=0;i<num;i++)
{
if(per[i].grade==grade)
{
if(term==1)
{
if(course==1)
{
if(per[i].first.english<60)
{
cout<<per[i].name<<endl;
}
}else if(course==2)
{
if(per[i].first.math<60)
{
cout<<per[i].name<<endl;
}
}
}
else if(term==2)
{
if(course==1)
{
if(per[i].second.english<60)
{
cout<<per[i].name<<endl;
}
}else if(course==2)
{
if(per[i].second.math<60)
{
cout<<per[i].name<<endl;
}
}
}
else
{
cout<<"該學期不存在!"<<endl;
return;
}
}
}
}

void main()
{
stu_info people;
int grade;
int term;
int choose;
int course;
char name[10];
while(1)
{
menu();
cin>>choose;
clear();
switch(choose)
{
case 1:
people.add_name_grade();break;
case 2:
cout<<"請輸入班級號:";
cin>>grade;
clear();
cout<<"請輸入學期:";
cin>>term;
clear();
if(term==1)
people.add_first(grade);
else
people.add_second(grade);
break;
case 3:
cout<<"請輸入班級號:";
cin>>grade;
clear();
cout<<"請輸入學生姓名:";
cin>>name;
clear();
people.modify(grade,name);
break;
case 4:
cout<<"請輸入班級號:";
cin>>grade;
clear();
cout<<"請輸入學期:";
cin>>term;
clear();
people.query_aver(grade,term);
break;
case 5:
cout<<"請輸入班級號:";
cin>>grade;
clear();
people.query_grade(grade);
break;
case 6:
cout<<"請輸入班級號:";
cin>>grade;
clear();
cout<<"請輸入學期:";
cin>>term;
clear();
cout<<"請輸入課程號(1:english,2:math):";
cin>>course;
people.show_fail(grade,term,course);
break;
case 7:
cout<<"請輸入班級號:";
cin>>grade;
clear();
cout<<"請輸入學生姓名:";
cin>>name;
clear();
people.query(grade,name);
break;
case 8:return;
default:cout<<"選擇錯誤,請重新選擇!"<<endl;
}
}
}

void menu()
{
cout<<" 請選擇操作"<<endl;
cout<<"-------------------------------------------------------------"<<endl;
cout<<" 1、輸入學生姓名、班級"<<endl;
cout<<" 2、按學期、班級錄入學生成績"<<endl;
cout<<" 3、修改學生成績"<<endl;
cout<<" 4、按班級平均分對學生成績排序"<<endl;
cout<<" 5、按班級輸出學生的成績單"<<endl;
cout<<" 6、按科目輸出不及格學生名單"<<endl;
cout<<" 7、查詢學生成績單"<<endl;
cout<<" 8、退出系統"<<endl;
}
這上面是實現功能,下面是類的定義和聲明 希望對你有用

struct term
{
int english;
int math;
int aver;
int total;
};
class stu
{
char name[10];
int grade;
struct term first;
struct term second;
public:
friend class stu_info;
void init_name_grade();
void init_first();
void init_second();
void show_grade();
void show_first();
void show_second();
};
class stu_info
{
stu per[100];
int num;
public:
stu_info();
void add_name_grade();
void add_first(int gra);
void add_second(int gra);
void query_aver(int gra,int term);
void modify(int gra,char name[10]);
void query(int gra,char name[10]);
void query_grade(int gra);
void show_fail(int grade,int term,int course);
};

閱讀全文

與學生信息錄入系統源碼相關的資料

熱點內容
如何在vps上搭建自己的代理伺服器 瀏覽:742
nginxphp埠 瀏覽:401
內臟pdf 瀏覽:150
怎麼看雲伺服器架構 瀏覽:83
我的世界國際服為什麼登不進伺服器 瀏覽:994
微盟程序員老婆 瀏覽:928
intellij創建java 瀏覽:110
java連接odbc 瀏覽:38
啟動修復無法修復電腦命令提示符 瀏覽:359
手機編程是什麼 瀏覽:98
山東移動程序員 瀏覽:163
蘇州java程序員培訓學校 瀏覽:477
單片機液晶驅動 瀏覽:854
魔拆app里能拆到什麼 瀏覽:131
新預演算法的立法理念 瀏覽:144
wdcpphp的路徑 瀏覽:134
單片機p0口電阻 瀏覽:926
瀏覽器中調簡訊文件夾 瀏覽:594
五菱宏光空調壓縮機 瀏覽:69
為什麼app佔用幾百兆 瀏覽:680