学生成绩管理信息系统代码 VC++

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include
#include
#include

/*
成绩记录簿
用Visual C++编制一个C语言成绩记录簿,每个学生信息包括:学号、姓名、C语言成绩。具体功能:
(1)创建信息链表并以磁盘文件保存;
(2)读取磁盘文件并显示输出所有学生的成绩;
(3)按学号或姓名查询成绩;
(4)添加成绩记录;
(5)修改指定姓名或学号的学生的成绩并可存盘;
(6)显示输出60分以下、60~79、80~89、90分以上各分数段的学生信息。
*/

//结构体
struct stdinfo
{
int ID;
char Name[10];
float Score;
stdinfo *pNext;
};


void AddData(stdinfo &std)
{
FILE *pf = fopen("score.data","a+");
fwrite((void *)&(std.ID),sizeof(int),1,pf);
fwrite((void *),sizeof(),1,pf);
fwrite((void *)&(std.Score),sizeof(float),1,pf);
fclose(pf);
}

void ReadData(stdinfo **phead)
{
if(_access("score.data",0)==-1)
{
return;
}
stdinfo *pNewStudent;
FILE *pf = fopen("score.data","r");
stdinfo *p =NULL;
fseek(pf,0,SEEK_END);
int lof = ftell(pf);
fseek(pf,0,SEEK_SET);
int len =0;
while(len!=lof)
{
pNewStudent= new stdinfo;
pNewStudent->ID =0;
memset(pNewStudent->Name,0,sizeof(pNewStudent->Name));
pNewStudent->Score =0;
pNewStudent->pNext =NULL;
if(p!=NULL)
{
p->pNext = pNewStudent;
}
fread((void *)&(pNewStudent->ID),sizeof(int),1,pf);
fread((void *)pNewStudent->Name,sizeof(pNewStudent->Name),1,pf);
fread((void *)&(pNewStudent->Score),sizeof(float),1,pf);

if(*phead==NULL)
{
*phead = pNewStudent;
p=*phead;
}
else
{
p=p->pNext;
}
len=ftell(pf);
}

fclose(pf);
}

void SaveData(stdinfo* phead)
{
if(phead==NULL)
{
return;
}
FILE *pf = fopen("score.data","w");
stdinfo *p = phead;
while(p!=NULL)
{
fwrite((void *)&(p->ID),sizeof(int),1,pf);
fwrite((void *)p->Name,sizeof(p->Name),1,pf);
fwrite((void *)&(p->Score),sizeof(float),1,pf);
p=p->pNext;
}
fclose(pf);
}

void ShowList(stdinfo *phead)
{
if(phead==NULL)
{
return;
}
stdinfo *p = phead;
while(p!=NULL)
{
printf("\t%d,",p->ID);
printf("\t%s,",p->Name);
printf("\t%.2f\n",p->Score);
p=p->pNext;
}

}

void showFenduan(stdinfo *phead)
{
if(phead==NULL)
{
return;
}
stdinfo *p;
printf("60以下:\n");
p= phead;
while(p!=NULL)
{
if(p->Score<60)
{
printf("\t%d,",p->ID);
printf("\t%s,",p->Name);
printf("\t%.2f\n",p->Score);
}
p=p->pNext;
}
printf("60~79:\n");
p= phead;
while(p!=NULL)
{
if(p->Score>=60 &&p->Score<80)
{
printf("\t%d,",p->ID);
printf("\t%s,",p->Name);
printf("\t%.2f\n",p->Score);
}
p=p->pNext;
}
printf("80~89:\n");
p= phead;
while(p!=NULL)
{
if(p->Score>=80 &&p->Score<90)
{
printf("\t%d,",p->ID);
printf("\t%s,",p->Name);
printf

("\t%.2f\n",p->Score);
}
p=p->pNext;
}
printf("90以上:\n");
p= phead;
while(p!=NULL)
{
if(p->Score>=90)
{
printf("\t%d,",p->ID);
printf("\t%s,",p->Name);
printf("\t%.2f\n",p->Score);
}
p=p->pNext;
}

}

void main()
{
//指向链表头的指针
stdinfo *pHead = NULL;
int n;
printf("请输入指令\n");
printf("1、输入成绩\n");
printf("2、显示所有学生成绩\n");
printf("3、查询成绩\n");
printf("4、修改成绩\n");
printf("5、按分数段显示成绩\n");
printf("6、退出\n");
stdinfo *p ;
bool flag;
int m;

while(1)
{
scanf("%d",&n);
switch(n)
{
case 1:
stdinfo std;
printf("学号:");
scanf("%d",&std.ID);
memset(,0,sizeof());
printf("姓名:");
scanf("%s",);
printf("成绩:");
scanf("%f",&std.Score);
AddData(std);
break;
case 2:
pHead=NULL;
ReadData(&pHead);
ShowList(pHead);
break;
case 3:
printf("要查询的学生的学号:");
scanf("%d",&m);
pHead=NULL;
ReadData(&pHead);
if(pHead ==NULL)
{
printf("没有找到该学生的记录\n");
break;
}
p= pHead;
flag =false;

while(p!=NULL)
{
if(p->ID==m)
{
printf("\t%d,\t%s,\t%.2f\n",p->ID,p->Name,p->Score);
flag=true;
break;
}
p=p->pNext;
}
if(!flag)
{
printf("没有找到该学生的记录\n");
}
break;
case 4:
printf("要修改成绩的学生的学号:");
scanf("%d",&m);
pHead=NULL;
ReadData(&pHead);
if(pHead ==NULL)
{
printf("没有找到该学生的记录\n");
break;
}
p= pHead;
flag =false;
while(p!=NULL)
{
if(p->ID==m)
{
printf("新的成绩:");
scanf("%f",&(p->Score));
flag=true;
break;
}
p=p->pNext;
}
if(!flag)
{
printf("没有找到该学生的记录\n");
}
else
{
SaveData(pHead);
}
break;
case 5:
pHead=NULL;
ReadData(&pHead);
showFenduan(pHead);
break;
case 6:
return;
break;
}
}

}

相关文档
最新文档