C語言學(xué)生信息管理系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)
本文實(shí)例為大家分享了C語言學(xué)生信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
#include"stdio.h" //標(biāo)準(zhǔn)的輸入輸出函數(shù)文件頭部說明
#include"math.h" // 數(shù)學(xué)函數(shù)頭部說明
#include"string.h"
#include"stdlib.h" //通過該函數(shù)頭部里的函數(shù),改變控制臺(tái)的背景和顏色
#include"windows.h" //頭文件聲明,下文用到了改變控制臺(tái)的寬度和高度
#define M 100 //宏定義說明
struct student{ //結(jié)構(gòu)體定義并聲明
char name[25]; //姓名
char num[25]; //學(xué)號(hào)
char credit[20]; //身份證號(hào)
char native[35]; //籍貫
char tel[25]; //手機(jī)號(hào)
int special; //專業(yè)
int banji; //班級(jí)
int math,yy,wl,cyy,pe; //數(shù)學(xué)、英語、物理、C語言、體育
double ave;}; //平均分
//****************************************函數(shù)的聲明********************************************
void input(struct student stu[M]); //輸入函數(shù)
void output(struct student stu[M]); //各類用戶自定義函數(shù)的聲明
void lookfor(struct student stu[M]); //查詢函數(shù)
void modify(struct student stu[M]); //修改函數(shù)
void order(struct student stu[M]); //排序函數(shù)
void delete_student(struct student stu[M]); //刪除函數(shù)
void xuehao(struct student stu[M]);
void xingming(struct student stu[M]);
void fileread(struct student stu[M]);
void filewrite(struct student stu[M]);
void yanshi(char *p); //延時(shí)函數(shù)說明
//**********************************************************************************************
int count=0;
struct student t;
int main()
{
int choice,sum;
struct student stu[M];
system("mode con:cols=400 lines=30000"); //調(diào)節(jié)控制臺(tái)的寬度和高度
system("color 0b"); //調(diào)節(jié)控制臺(tái)的背景和字體顏色
point1:
sum=0;
yanshi("\t\t\t\t\t\t\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3歡迎你使用學(xué)生信息管理系統(tǒng)\3\3\3\3\3\3\3\3\3\3\n");
do {
printf("\t\t\t\t\t\t\t\t-------------------------------------------------\n");
printf("\t\t\t\t\t\t\t\t+ 學(xué)生信息管理系統(tǒng) +\n");
printf("\t\t\t\t\t\t\t\t-------------------------------------------------\n");
printf("\t\t\t\t\t\t\t\t\t\t ***************\n");
printf("\t\t\t\t\t\t\t\t\t\t 1、添加學(xué)生信息\n");
printf("\t\t\t\t\t\t\t\t\t\t 2、瀏覽學(xué)生信息\n");
printf("\t\t\t\t\t\t\t\t\t\t 3、查詢學(xué)生信息\n");
printf("\t\t\t\t\t\t\t\t\t\t 4、修改學(xué)生信息\n");
printf("\t\t\t\t\t\t\t\t\t\t 5、刪除學(xué)生信息\n");
printf("\t\t\t\t\t\t\t\t\t\t 6、排列學(xué)生信息\n");
printf("\t\t\t\t\t\t\t\t\t\t 7、讀取文件學(xué)生\n"); //從文件讀取
printf("\t\t\t\t\t\t\t\t\t\t 8、保存到文件\n"); //保存到文件
printf("\t\t\t\t\t\t\t\t\t\t 9、退出系統(tǒng)\n");
printf("\t\t\t\t\t\t\t\t\t\t ***************\n");
printf("請(qǐng)輸入你的選擇\n");
scanf("%d",&choice);
fflush(stdin); //清除輸入緩沖區(qū)
if (choice>9||choice<=0)
{
sum++;
if (sum>=5)
{
printf("輸入錯(cuò)誤次數(shù)過多,程序?qū)⒅匦麻_始\n");
system("pause"); //程序暫停
system("cls"); //清屏語句
goto point1;
}
}
switch (choice) //根據(jù)選擇,調(diào)用不同的函數(shù)來完成不同的任務(wù)
{
case 1:input(stu);break;
case 2:output(stu);break;
case 3:lookfor(stu);break;
case 4:modify(stu);break;
case 5:delete_student(stu);break;
case 6:order(stu);break;
case 7:fileread(stu);break;
case 8:filewrite(stu);;break;
case 9:printf("感謝你使用學(xué)生信息管理系統(tǒng),請(qǐng)關(guān)掉程序!!!\n");system("pause");break;
default:printf("無效的選擇!!!請(qǐng)重新輸入!!!\n");break;
}
}while (choice!=9);
printf("the program is over!!!\n");
return 0;
}
void input(struct student stu[M]) //自定義輸入函數(shù)
{
int len,size;
system("cls");
printf("請(qǐng)?zhí)砑右斎雽W(xué)生的信息\n");
do {
printf("請(qǐng)輸入由11位數(shù)字組成的學(xué)生學(xué)號(hào)\n"); //do-while循環(huán)應(yīng)用,提示輸入位數(shù)為一確定數(shù)
scanf("%s",&stu[count].num);
len=strlen(stu[count].num);
}while(len!=11);
printf("請(qǐng)輸入同學(xué)的姓名\n");
scanf("%s",stu[count].name);
do {
printf("請(qǐng)輸入由18位數(shù)字組成的學(xué)生身份證號(hào)\n"); //同上
scanf("%s",&stu[count].credit);
size=strlen(stu[count].credit);
}while(size!=18);
printf("請(qǐng)輸入學(xué)生的籍貫\n");
scanf("%s",&stu[count].native);
printf("請(qǐng)輸入學(xué)生的手機(jī)號(hào)碼\n");
scanf("%s",&stu[count].tel);
printf("請(qǐng)輸入所需要的專業(yè)代號(hào):1、計(jì)算機(jī)科學(xué) 2、通信工程 3、網(wǎng)絡(luò)工程\n"); //采用如此方法解決了專業(yè)輸入難問題
scanf("%d",&stu[count].special);
printf("請(qǐng)輸入對(duì)應(yīng)的學(xué)生班級(jí)號(hào)碼:1、1301 2、1302 \n");
scanf("%d",&stu[count].banji);
do {
printf("請(qǐng)依次輸入不大于100的學(xué)生各科成績\n");
scanf("%d%d%d%d%d",&stu[count].math,&stu[count].yy,&stu[count].wl,&stu[count].cyy,&stu[count].pe);
}while(stu[count].math>100||stu[count].yy>100||stu[count].wl>100||stu[count].cyy>100||stu[count].pe>100); //同上同上
stu[count].ave=(stu[count].math+stu[count].yy+stu[count].wl+stu[count].cyy+stu[count].pe)/5.0; //求出平均值
count++;
}
void output(struct student stu[M]) //自定義輸出函數(shù)
{
int j;
system("cls");
if (count==0)
{
printf("當(dāng)前已存學(xué)生信息為0個(gè)\n");
return;
}
for (j=0;j<count;j++)
{
printf("學(xué)號(hào)\t\t 姓名\t\t身份證號(hào)\t籍貫\t手機(jī)號(hào)\t\t專業(yè)\t\t班級(jí)\t數(shù)學(xué)\t英語\t物理\tC語言\t體育\t平均分\n");
for (j=0;j<count;j++){ //for循環(huán)控制輸出的個(gè)數(shù)
printf("%s\t",stu[j].num);
printf("%s\t",stu[j].name);
printf("%s\t",stu[j].credit);
printf("%s\t",stu[j].native);
printf("%s\t",stu[j].tel);
if (stu[j].special==1)
printf("計(jì)算機(jī)科學(xué)\t");
else if (stu[j].special==2)
printf("通信工程\t");
else
printf("網(wǎng)絡(luò)工程\t");
printf("%d\t",stu[j].banji);
printf("%d\t",stu[j].math);
printf("%d\t",stu[j].yy);
printf("%d\t",stu[j].wl);
printf("%d\t",stu[j].cyy);
printf("%d\t",stu[j].pe);
printf("%.1lf\t\n",stu[j].ave);}
}
}
void lookfor(struct student stu[M]) //自定義查詢學(xué)生信息函數(shù)
{
int j,flag=0;
char xh[25];
system("cls");
if (count==0)
{
printf("當(dāng)前已存學(xué)生信息為0個(gè),無法查詢!!!\n");
return;
}
else
{
printf("請(qǐng)輸入你想要查看的同學(xué)學(xué)號(hào)\n");
scanf("%s",&xh);
fflush(stdin);
for (j=0;j<count;j++)
{
if (strcmp(stu[j].num,xh)==0) //通過字符函數(shù)對(duì)已存入的學(xué)生信息進(jìn)行比較,找出要查看的學(xué)生
{
printf("學(xué)號(hào)\t\t姓名\t\t身份證號(hào)\t籍貫\t手機(jī)號(hào)\t\t專業(yè)\t\t班級(jí)\t數(shù)學(xué)\t英語\t物理\tC語言\t體育\t平均分\n");
printf("%s\t",stu[j].num);
printf("%s\t",stu[j].name);
printf("%s\t",stu[j].credit);
printf("%s\t",stu[j].native);
printf("%s\t",stu[j].tel);
if (stu[j].special==1)
printf("計(jì)算機(jī)科學(xué)\t");
else if (stu[j].special==2)
printf("通信工程\t");
else
printf("網(wǎng)絡(luò)工程\t");
printf("%d\t",stu[j].banji); //考慮一個(gè)對(duì)齊的因數(shù)
printf("%d\t",stu[j].math);
printf("%d\t",stu[j].yy);
printf("%d\t",stu[j].wl);
printf("%d\t",stu[j].cyy);
printf("%d\t",stu[j].pe);
printf("%.1lf\t",stu[j].ave);
}
}
if (j==count)
printf("很抱歉,沒有你所需要的學(xué)生信息\n");
}
}
void modify(struct student stu[M]) //自定義修改函數(shù)
{
int j,flag=0,course;
char xh[25];
system("cls");
if (count==0)
{
printf("當(dāng)前已存學(xué)生信息為0個(gè),無法修改!!!\n");
return;
}
else
{
printf("請(qǐng)輸入你想要修改的同學(xué)學(xué)號(hào)\n");
scanf("%s",&xh);
fflush(stdin);
for (j=0;j<count;j++)
if (strcmp(stu[j].num,xh)==0) //同上
{
printf("你確定要修改學(xué)生的信息嗎???如果不確定的話,請(qǐng)關(guān)掉本程序吧!!!\n");
printf("選擇課程: 1、數(shù)學(xué) 2、英語 3、物理 4、C語言 5、體育\n");
scanf("%d",&course);
printf("請(qǐng)輸入你想要修改后的學(xué)生成績\n");
switch(course)
{
case 1:scanf("%d",&stu[j].math);break;
case 2:scanf("%d",&stu[j].yy);break; //switch控制語句
case 3:scanf("%d",&stu[j].wl);break;
case 4:scanf("%d",&stu[j].cyy);break;
case 5:scanf("%d",&stu[j].pe);break;
default:printf("無效的選擇!!!請(qǐng)重新輸入!!!\n");break;
}
}
}
}
void delete_student(struct student stu[M]) //自定義刪除函數(shù)
{
int choice;
system("cls");
if (count==0)
{
printf("當(dāng)前已存學(xué)生信息為0個(gè),無法刪除!!!\n");
return;
}
else
{
printf("請(qǐng)選擇你所要?jiǎng)h除的方式:1、學(xué)號(hào) 2、姓名(如果你的姓名是中文,那么無法刪除,請(qǐng)選擇學(xué)號(hào)刪除) 3、取消\n");
scanf("%d",&choice);
switch(choice) //switch語句對(duì)用戶要?jiǎng)h除的方式進(jìn)行選擇
{
case 3:return;break;
case 2:xingming(stu);break; //用戶自定義函數(shù)之間的套用
case 1:xuehao(stu);break;
default:printf("無效的選擇!!!請(qǐng)重新輸入!!!\n");break;
}
}
}
void order(struct student stu[M]) //排序函數(shù)的定義
{
int j,k,choice,index;
system("cls");
printf("請(qǐng)輸入你想要進(jìn)行排序的方式(所有排序的方式均是降序)!!!\n");
printf("1、數(shù)學(xué) 2、英語 3、物理 4、C語言 5、體育 6、平均分\n");
scanf("%d",&choice);
switch (choice)
{
case 1:for (j=0;j<count;j++)
{ index=j;
for (k=j+1;k<count;k++)
if (stu[k].math>stu[index].math)
{t=stu[k];stu[k]=stu[index];stu[index]=t;}
};break;
case 2:for (j=0;j<count;j++)
{ index=j;
for (k=j+1;k<count;k++)
if (stu[k].yy>stu[index].yy)
{stu[k]=stu[index];} //整個(gè)為排序部分,采用了所謂的選擇排序的方法
};break;
case 3:for (j=0;j<count;j++)
{ index=j;
for (k=j+1;k<count;k++)
if (stu[k].wl>stu[index].wl)
{t=stu[k];stu[k]=stu[index];stu[index]=t;}
};break;
case 4:for (j=0;j<count;j++)
{ index=j;
for (k=j+1;k<count;k++)
if (stu[k].cyy>stu[index].cyy)
{t=stu[k];stu[k]=stu[index];stu[index]=t;}
};break;
case 5:for (j=0;j<count;j++)
{ index=j;
for (k=j+1;k<count;k++)
if (stu[k].pe>stu[index].pe)
{t=stu[k];stu[k]=stu[index];stu[index]=t;}
};break;
case 6:for (j=0;j<count;j++)
{ index=j;
for (k=j+1;k<count;k++)
if (stu[k].ave>stu[index].ave)
{t=stu[k];stu[k]=stu[index];stu[index]=t;} //強(qiáng)制類型轉(zhuǎn)換符號(hào)只能用于有操作數(shù),根據(jù)賦值運(yùn)算中的類型轉(zhuǎn)換問題可知
};break;
default:printf("無效的選擇!!!請(qǐng)重新輸入!!!\n");break;
}
}
void xuehao(struct student stu[M]) //自定義通過學(xué)號(hào)方式刪除學(xué)生信息函數(shù)
{
int j,index=0,k=count;
char xh[25];
system("cls");
printf("請(qǐng)輸入你想要?jiǎng)h除的同學(xué)學(xué)號(hào)\n");
scanf("%s",xh);
fflush(stdin);
for (j=0;j<count;j++)
{ if (strcmp(stu[j].num,xh)==0)
{
for (j=index;j<count;j++)
stu[j]=stu[j+1];
count--;
if (count<k)
printf("你已經(jīng)刪除成功\n");
}
index++;}
if (j==count)
printf("抱歉!!!沒有你所需要?jiǎng)h除的學(xué)生信息!*_*!\n");
}
void xingming(struct student stu[M]) //自定義通過姓名方式刪除學(xué)生信息函數(shù)
{
int flag=0,j,k=count;
char xm[25];
system("cls");
printf("請(qǐng)輸入你想要?jiǎng)h除的同學(xué)姓名\n");
scanf("%s",xm);
fflush(stdin);
for (j=0;j<count;j++)
{
if (strcmp(stu[j].num,xm)==0)
{
for (j=flag-1;j<count;j++)
stu[j]=stu[j+1];
count--;
if (count<k)
printf("你已經(jīng)刪除成功\n");
}
flag++;}
if (j==count)
printf("抱歉!!!沒有你所需要?jiǎng)h除的學(xué)生信息!*_*!\n");
}
void yanshi(char *p) //延時(shí)函數(shù)的定義
{
while (1)
{
if (*p!=0)
printf("%c",*p++);
else
break;
Sleep(100); //延時(shí)控制間斷語句
}
}
void filewrite(struct student stu[M]) //寫入文件函數(shù)定義
{
int j=0;
char c;
FILE *fp;
printf("請(qǐng)選擇是否要存入已輸入的學(xué)生信息:'y'還是'n'???\n");
scanf("%c",&c);
fflush(stdin);
while(c!='y'&&c!='n'){
if (c!='y'&&c!='n')
printf("輸入錯(cuò)誤,請(qǐng)重新輸入\n");
printf("以下操作將會(huì)覆蓋已存儲(chǔ)的數(shù)據(jù),確定請(qǐng)輸入'y'或'n'???\n");
scanf("%c",&c);
fflush(stdin);
}
if (c=='y')
{
if((fp=fopen("d:\\stu.dat","wb"))==NULL)
{
printf("文件打開錯(cuò)誤,程序無法進(jìn)行\(zhòng)n");
exit(0);
}
for(j=0;j<count;j++)
{fwrite(&stu[j],sizeof(struct student),1,fp);
}
fclose(fp);
if(count==0)
printf("沒有文件,無法保存\n");
else
printf("數(shù)據(jù)存儲(chǔ)完畢\n");
system("pause");
}
else
return;
}
void fileread(struct student stu[M]) //讀取文件信息函數(shù)定義
{
int j=0;
char c;
FILE *fp;
system("cls");
printf("請(qǐng)選擇是否要存入已輸入的學(xué)生信息:'y'還是'n'???\n");
scanf("%c",&c);
fflush(stdin);
while(c!='y'&&c!='n'){
if (c!='y'&&c!='n')
printf("輸入錯(cuò)誤,請(qǐng)重新輸入\n");
printf("以下操作將會(huì)覆蓋已存儲(chǔ)的數(shù)據(jù),確定請(qǐng)輸入'y'或'n'???\n");
scanf("%c",&c);
fflush(stdin);
}
if (c=='y')
{
if((fp=fopen("d:\\stu.dat","rb"))==NULL)
{
printf("文件打開錯(cuò)誤,程序無法進(jìn)行\(zhòng)n");
exit(0);
}
fread(&stu[j],sizeof(struct student),1,fp);
count=0;
count++;
j++;
while(fread(&stu[j],sizeof(struct student),1,fp))
{
j++;
count++;
}
fclose(fp);
printf("數(shù)據(jù)讀取完畢!!!\n");
system("pause");
}
else
return;
}
更多學(xué)習(xí)資料請(qǐng)關(guān)注專題《管理系統(tǒng)開發(fā)》。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 學(xué)生信息管理系統(tǒng)C語言版
- C語言實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)(單鏈表)
- C語言數(shù)據(jù)結(jié)構(gòu)之學(xué)生信息管理系統(tǒng)課程設(shè)計(jì)
- C語言單鏈表版學(xué)生信息管理系統(tǒng)
- C語言版學(xué)生信息管理系統(tǒng)
- C語言學(xué)生信息管理系統(tǒng)小項(xiàng)目
- C語言數(shù)組實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)設(shè)計(jì)
- C語言實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)(文件版)
- C語言使用鏈表實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
- C語言實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)開發(fā)
相關(guān)文章
淺談c++性能測(cè)試工具之計(jì)算時(shí)間復(fù)雜度
有時(shí)候除了測(cè)量算法的具體性能指數(shù),我們也會(huì)希望測(cè)試出算法的時(shí)間復(fù)雜度,以便我們對(duì)待測(cè)試的算法的性能有一個(gè)更加直觀的了解。本文將介紹c++性能測(cè)試工具之計(jì)算時(shí)間復(fù)雜度。2021-06-06
C/C++?Qt數(shù)據(jù)庫與SqlTableModel組件應(yīng)用教程
SqlTableModel?組件可以將數(shù)據(jù)庫中的特定字段動(dòng)態(tài)顯示在TableView表格組件中,這篇文章將主要介紹SqlTableModel組件一些常用的操作,需要的朋友可以參考一下2021-12-12
C++實(shí)現(xiàn)LeetCode(34.在有序數(shù)組中查找元素的第一個(gè)和最后一個(gè)位置)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(34.在有序數(shù)組中查找元素的第一個(gè)和最后一個(gè)位置),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07
淺談C++中對(duì)象的復(fù)制與對(duì)象之間的相互賦值
這篇文章主要介紹了淺談C++中對(duì)象的復(fù)制與對(duì)象之間的相互賦值,是C語言入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-09-09
C/C++惡意代碼盤點(diǎn)之文件自動(dòng)刪除
惡意代碼的分類包括計(jì)算機(jī)病毒、蠕蟲、木馬等,有些技術(shù)經(jīng)常用到,有的也是必然用到。今天我們就分享一下文件自動(dòng)刪除,感興趣的可以了解一下2022-09-09

