資源簡(jiǎn)介
程序功能
(1)存取功能,能夠從磁盤上的文本文件讀取學(xué)生信息,并將內(nèi)存中的學(xué)生信息保存到磁盤上的文件中。學(xué)生信息包括學(xué)號(hào)、姓名、數(shù)學(xué)成績(jī)、英語(yǔ)成績(jī)、政治成績(jī)。
(2)查詢功能,分別能按學(xué)生學(xué)號(hào)和學(xué)生姓名進(jìn)行查找學(xué)生信息,根據(jù)提示輸入不同的數(shù)字,進(jìn)行不同的查找方式。
(3)學(xué)生成績(jī)統(tǒng)計(jì)功能,能夠統(tǒng)計(jì)學(xué)生的平均成績(jī)和總成績(jī)。
(4)插入功能,能夠插入學(xué)生信息,若新插入的學(xué)號(hào)應(yīng)經(jīng)存在系統(tǒng)中,會(huì)進(jìn)行提示,此時(shí)不允許在插入具有相同學(xué)號(hào)的學(xué)生信息。
(5)修改功能,先用學(xué)號(hào)或姓名關(guān)鍵字查找要修改的學(xué)生的信息,若找到,則可進(jìn)行修改。
(6)刪除功能,能夠刪除指定的學(xué)生信息。

代碼片段和文件信息
/*?File:StuManage.c
?*
?*?學(xué)生成績(jī)管理信息系統(tǒng)
?*?作者:阿龍
?*?使用時(shí)自己先建一個(gè)名為stumanage.txt的文件
?*?不然學(xué)生信息不能保存到磁盤上去的啊
?*/
#include?
#include?
#include?
#include?
#define?LEN?sizeof(struct?students)
/*定義結(jié)構(gòu)體,用來(lái)存放學(xué)生信息*/
struct?score
{
double?math;
double?english;
double?politics;
};
struct?students
{
char?num[12];
char?name[15];
struct?score?sco;
struct?students?*next;
};
/*開(kāi)始運(yùn)行程序時(shí),從stumanage.txt文件讀取學(xué)生信息到內(nèi)存中,并返回頭指針*/
struct?students?*InputMem(struct?students?*head)
{
FILE?*fp;
struct?students?*temp?=?NULL?*tail?=?NULL;
fp?=?fopen(“stumanage.txt“?“r+“);
if?(NULL?==?fp)
{
printf(“不能打開(kāi)文件\n“);
return?head;
}
while?(!feof(fp))
{
temp?=?(struct?students?*)malloc(LEN);
/*判斷是否申請(qǐng)到內(nèi)存空間,若沒(méi)有返回頭指針,否則跳過(guò)if繼續(xù)執(zhí)行*/
if?(NULL?==?temp)
{
printf(“沒(méi)有申請(qǐng)到足夠的內(nèi)存空間\n“);
return?head;
}
fread(temp?LEN?1?fp);
if?(head?==?NULL)
{
head?=?temp;
tail?=?temp;
}
else
{
tail->next?=?temp;
tail?=?temp;
}
}
temp->next?=?NULL;?/*將動(dòng)態(tài)鏈表最后節(jié)點(diǎn)的尾指針設(shè)為NULL*/
fclose(fp);
return?head;
}
/*退出時(shí)將內(nèi)存中的學(xué)生信息寫入到stumanage.txt文件中去*/
void?OutputMem(struct?students?*head)
{
FILE?*fp;
struct?students?*temp?=?NULL;
fp??=?fopen(“stumanage.txt“?“r+“);
if?(head?!=?NULL)
{
temp?=?head;
while?(temp->next?!=?NULL)
{
fwrite(temp?LEN?1?fp);
temp?=?temp->next;
}
}
fclose(fp);
}
/*程序運(yùn)行結(jié)束時(shí)釋放申請(qǐng)的內(nèi)存空間*/
void?DelMem(struct?students?*head)
{
struct?students?*temp?=?head;
if?(temp?!=NULL)
{
while?(temp->next?!=NULL)
{
head?=?temp->next;
free(temp);
temp?=?head;
}
free(head);
}
}
/*打印信息管理系統(tǒng)功能使用說(shuō)明*/
void?Instruction(void)
{
printf(“********************************************\n“);
printf(“??????????學(xué)生成績(jī)管理信息系統(tǒng)??????????\n\n“);
printf(“??使用說(shuō)明\n“);
printf(“??查看所有信息請(qǐng)按?1???學(xué)生信息查詢請(qǐng)按?2\n“);
printf(“??學(xué)生信息插入請(qǐng)按?3???學(xué)生信息修改請(qǐng)按?4\n“);
printf(“??學(xué)生信息刪除請(qǐng)按?5???學(xué)生成績(jī)統(tǒng)計(jì)請(qǐng)按?6\n“);
printf(“??退出請(qǐng)按?0\n\n“);
printf(“********************************************\n“);
}
/*打印學(xué)生信息的表頭*/
void?Printtitle()
{
printf(“??學(xué)號(hào)??姓名??數(shù)學(xué)??英語(yǔ)??政治“);
}
/*輸出temp指針指向的單個(gè)學(xué)生的信息*/
void?PrintStuInfo(struct?students?*temp)
{
printf(“%6s%6s%6.1lf%6.1lf%6.1lf“?temp->num?temp->name?
temp->sco.mathtemp->sco.english?temp->sco.politics);
}
/*查看所有學(xué)生信息*/
void?Chakan(struct?students?*head)
{
struct?students?*temp?=?head;
if?(NULL?==?head)
{
printf(“沒(méi)有學(xué)生信息,請(qǐng)先輸入后再查看學(xué)生信息\n\n“);
}
else
{
printf(“????學(xué)生的所有信息如下:\n\n“);
Printtitle();
printf(“\n“);;
while?(temp->next!=NULL)
{
PrintStuInfo(temp);
printf(“\n“);
temp?=?temp->next;
}
printf(“\n\n“);
}
}
/*按學(xué)生學(xué)號(hào)進(jìn)行查詢*/
struct?students?*NumQuery(struct?students?*head?char?number[])
{
struct?students?*temp?=?head;
while?(temp->next?!=?NULL)
{
if?(!strcmp(temp->num?number))
{
return?temp;
}
temp?=?temp->next;
}
return?NULL;
}
/*按學(xué)生姓名進(jìn)行查詢*/
struct?students?*NameQuery(stru
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????9573??2008-09-21?20:15??學(xué)生成績(jī)管理信息系統(tǒng)\stumanage.c
?????文件?????134656??2008-09-21?20:27??學(xué)生成績(jī)管理信息系統(tǒng)\課程設(shè)計(jì).doc
?????目錄??????????0??2008-09-21?20:25??學(xué)生成績(jī)管理信息系統(tǒng)
-----------?---------??----------?-----??----
???????????????144229????????????????????3
評(píng)論
共有 條評(píng)論