資源簡介
自己實現的C語言學生管理系統,帶文本數據庫,寫了對文本文件的操作。
創建學生數據庫(文件)
向數據庫中錄入內容
顯示指定文件(數據庫)中的內容
按照總分進行排序
向數據庫中增加一條學生記錄
刪除一條學生記錄
修改指定學生的記錄
查找指定學生的記錄
排序(子菜單,按照任意字段進行排序)
查詢及格或不及格學生信息
更換數據庫
退出學生管理系統

代碼片段和文件信息
#include
#include
#include?
struct?student
{
int?num;???????????/*學號*/
char?name[20];?????/*姓名*/
char?sax[4];
int?score[3];??????/*三門課成績*/
int?sum;
};
FILE?*fp=NULL;
student?*stu;
/************************************************************************************************/
void?createFile()
{
char?namedb1[100];
printf(“\n\n\t請輸入數據庫名稱:“);
scanf(“%s“namedb1);
strcat(namedb1“.data“);
fp=fopen(namedb1“w“);
fclose(fp);
system(“dir?*.data“);
printf(“??數據庫創建成功...!\n“);
}
/************************************************************************************************/
void?input(int?*hchar?namedb1[])//向數據庫中錄入內容?a?追加??
{
int?i=0j;
int?N=-1;
j=*h;
stu=new?student[40];
while(N?!=0)
{
printf(“請輸入第%d學生信息:\n“i+1);
while(N?!=2)
{
printf(“請輸入學生學號:“);
scanf(“%d“&stu[i].num);
for(j=i+1;j>=0;j--)
{
if(?stu[j].num?==?stu[j-1].num)
{
printf(“???學號重復,請重新輸入...!\n“);
N=0;
break;
}
else
{
N=2;
}
}
}
printf(“請輸入學生姓名:“);
scanf(“%s“stu[i].name);
printf(“請輸入學生性別:“);
scanf(“%s“stu[i].sax);
printf(“請輸入學生的三門課程:\n“);
for(j=0;j<3;j++)
{
int?temp=-1;
printf(“第%d門成績的分數為(0-100):“j+1);?
scanf(“%d“&stu[i].score[j]);
while(temp!=1)
{
if(stu[i].score[j]<0?||?stu[i].score[j]>100)
{
printf(“輸入錯誤,請重新輸入第%d門成績:\n“j+1);
scanf(“%d“&stu[i].score[j]);
temp=0;
}
else
{
temp=1;
}
}
}
stu[i].sum=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
printf(“\n\n“);
i++;
printf(“???是否繼續輸入:1.繼續??0.退出并保存\n“);
scanf(“%d“&N);
if(N==1)
{
system(“cls“);
}
}
fp=fopen(namedb1“w“);
for(j=0;j {
fprintf(fp“學號:%10d?姓名:%8s?性別:%2s?三門課程成績:%4d?%4d?%4d?總分:%4d\n“stu[j].numstu[j].namestu[j].saxstu[j].score[0]stu[j].score[1]stu[j].score[2]stu[j].sum);
}
printf(“輸入完畢!按0鍵返回主菜單!\n“);?
fclose(fp);
*h=i;
}
/************************************************************************************************/
void?output(int?*hchar?namedb1[])//顯示指定文件(數據庫)中的內容
{
int?ij;
j=*h;
fp=fopen(namedb1“r“);
stu=new?student[j];
for(i=0;i {
fscanf(fp“學號:%10d?姓名:%8s?性別:%2s?三門課程成績:%4d?%4d?%4d?總分:%4d\n“&stu[i].numstu[i].namestu[i].sax&stu[i].score[0]&stu[i].score[1]&stu[i].score[2]&stu[i].sum);
}
for(i=0;i {
printf(“學號:%10d?姓名:%8s?性別:%2s?三門課程成績:%4d?%4d?%4d?總分:%4d\n“stu[i].numstu[i].namestu[i].saxstu[i].score[0]stu[i].score[1]stu[i].score[2]stu[i].sum);
}
printf(“\n當前學生人數為%d名...\n“j);
printf(“\n\n“);
fclose(fp);
}
/************************************************************************************************/
int?count(char?namedb1[])//統計
{
FILE?*fp2;
//int?N=1;
student?*stu1;
fp2=fopen(namedb1“r“);
stu1=new?student[10];
int?i=0;
while(!feof(fp2))
{
fscanf(fp2“學號:%10d?姓名:%8s?性別:%2s?三門課程成績:%4d?%4d?%
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2011-09-22?13:06??studen_huangpeixiong\
?????文件?????????154??2010-12-07?14:41??studen_huangpeixiong\12.data
?????目錄???????????0??2011-09-22?13:06??studen_huangpeixiong\Debug\
?????文件??????225338??2010-12-09?10:50??studen_huangpeixiong\Debug\student.exe
?????文件??????295520??2010-12-09?10:50??studen_huangpeixiong\Debug\student.ilk
?????文件???????61948??2010-12-09?10:50??studen_huangpeixiong\Debug\student.obj
?????文件??????225956??2010-12-09?10:24??studen_huangpeixiong\Debug\student.pch
?????文件??????566272??2010-12-09?10:50??studen_huangpeixiong\Debug\student.pdb
?????文件???????33792??2010-12-09?10:51??studen_huangpeixiong\Debug\vc60.idb
?????文件???????53248??2010-12-09?10:50??studen_huangpeixiong\Debug\vc60.pdb
?????文件????????1386??2010-12-09?10:51??studen_huangpeixiong\stu.data
?????文件???????26721??2012-01-14?11:55??studen_huangpeixiong\student.cpp
?????文件????????3413??2010-12-09?10:21??studen_huangpeixiong\student.dsp
?????文件?????????520??2010-12-09?10:52??studen_huangpeixiong\student.dsw
?????文件???????41984??2010-12-09?10:52??studen_huangpeixiong\student.ncb
?????文件???????48640??2010-12-09?10:52??studen_huangpeixiong\student.opt
?????文件?????????743??2010-12-09?10:50??studen_huangpeixiong\student.plg
- 上一篇:二叉樹非遞歸遍歷源碼
- 下一篇:udp 泛洪攻擊vc++源碼
評論
共有 條評論