学生成绩管理系统(C语言)

学生成绩信息包括:学期,学号,班级,姓名,四门课程成绩(语文,数学,英语和计算机)等、
主要功能:
(1)能按学期、班级、完成对学生成绩的录入、修改
(2)能按班级统计学生的成绩,求学生的总分及平均分
(3)能查询学生的成绩,不及格科目及学生名单
(4)能按班级输出学生的成绩单
要求:使用二进制文件方式存储数据,系统以菜单方式工作
不要在网上下来的!急用!谢谢了!

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#define NUM_SUBJECT 4
typedef struct zl
{
char no[5]; /*学号*/
char name[6]; /*姓名*/
int score[NUM_SUBJECT]; /*各门学科成绩*/
float total; /*总分*/
float average; /*平均分*/
int order; /*名次*/
}STUDENT;
int REC_NUM=0; /*学生记录数*/
char*subject[]={"数学","电脑","物理","电工学"};
char*menu[]={"**************MENU***************",
"1. Enter new record",
"2. Display record",
"3. Search record",
"4. Modify record",
"5. Delete a record to list",
"6. Add a record to list",
"7. Sort to make new file",
"8. Save the file",
"9. Load the file",
"10. Quit"};
STUDENT records[10];
void newRec();
void showTable();
void showTable2(Iint);
void display();
void searchRec();
void modifyRec();
void deleteRec();
void addRec();
void orderRec();
void sortRec();
void saveRec();
void loadRec();
void copyRec(STUDENT*,STUDENT*);
void quit();
int menu_select();
int findRec(char*,int,int);
void main()
{
system("cls");
for(;;)
{
switch(menu_select())
{
case 1: newRec();break;
case 2: display();break;
case 3: searchRec();break;
case 4: modifyRec();break;
case 5: deleteRec();break;
case 6: addRec();break;
case 7: sortRec();break;
case 8: saveRec();break;
case 9: loadRec();break;
case 10: quit();
}
}
}

int menu_select()
{
char s[3];
int c,i;
for(i=0;i<11;i++)
{
printf("%s",menu[i]);
}
window(1,1,80,25);
do
{
printf(" Enter you choice(1-10):");
scanf("%s",s);
c=atoi(s);
}while(c<0||c>11);
return c;
}
void showTable1()
{
system("cls");
printf("*****************STUDENT INFORMATION****************");
printf("????D?D?D?D?D?D?D?D?D?D???\n");
printf("|Rec | No | Name | Computer | Physics | English | total | Average | Order\n");
printf("?¨¤?¨¤?¨¤?¨¤?¨¤?¨¤?¨¤?¨¨\n");
}
void showTable2(int n)
{
if(n==0)n=1;
if(REC_NUM==0)n=-1;
printf("??????????????????\n");
}
void quit()
{
char str[5];
printf("Save records?(Y/N)");
scanf("%s",str);
if(str[0]=='Y'||str[0]=='y')
saveRec();
exit(0);
}
void newRec()
{
int i, j, sum;
system("cls");
printf("Please input the REC_NUM:");
scanf("%d",&REC_NUM);
for(i=0;i<REC_NUM;i++)
{
system("cls");
sum=0;
for(j=0;j<NUM_SUBJECT;j++);
{
scanf("%d",&records[i].score[j]);
sum=sum+records[i].score[j];
}
records[i].total=sum;
records[i].average=records[i].total/NUM_SUBJECT;
records[i].order=0;
}
}
void display()
{
int i=0;
showTable1();
for(i=0;i<REC_NUM;i++)
{
printf("|%2d |%4s |6s?%4d | %4d | %4d | %5.1f | %5.1f | %2d \n",i+1,records[i].no,records[i].name,records[i].score[0],records[i].score[1],records[i].score[2],records[i].score[3],records[i].total,records[i].average,records[i].order);
}
showTable2(i);
printf("Press any key to return!");
getch();
}
void saveRec()
{
FILE*fp1,*fp2;
if((fp1=fopen("d:\\cjt\\tc\\lianxiti\\keshe\\keshe.dat","wb"))==NULL)
{
printf("Cannot open this file!");
exit(1);
}
if((fp2=fopen("d:\\cjt\\tc\\lianxiti\\keshe\\keshe.dat","wb"))==NULL)
{
printf("Cannot open this file!");
exit(1);
}

printf("\nSaving file......\n");
fwrite(&REC_NUM,sizeof(REC_NUM),1,fp2);
fwrite(records,sizeof(STUDENT),REC_NUM,fp1);
fclose(fp1);fclose(fp2);
printf("n\Save success!!\n");delay(1000);
printf("\nPress any key to return!");
getch();
}
void loadRec()
{
FILE*fp1,*fp2;
if((fp1=fopen("d:\\cjt\\tc\\lianxiti\\keshe\\keshe.dat","rb"))==NULL)
{
printf("Cannot open this file!");
exit(1);
}
if((fp2=fopen("d:\\cjt\\tc\\lianxiti\\keshe\\keshe.dat","rb"))==NULL)
{
printf("Cannot open this file!");
exit(1);
}
system("cls");
printf("\nLoading file.....\n");
fread(&REC_NUM,sizeof(REC_NUM),1,fp2);
fread(records,sizeof(STUDENT),REC_NUM,fp1);
fclose(fp1);fclose(fp2);
delay(2000);
printf("\nYou have success read date from file!!!\n");
printf("\press any key to return!");
getch();
}
void searchRec()
{
char str[20];
int i;
system("cls");
printf("Please input the number you want to get:");
scanf("%s",str);
i=findRec(str,1,0);
if(i!=-1)
{
printf("|%2d |%4s | 6s| %4d | %4d | %4d | %4d| %5.1f | %5.1f | %2d \n",i+1,records[i].no,records[i].name,records[i].score[0],records[i].score[1],records[i].score[2],records[i].score[3],records[i].total,records[i].average,records[i].order);
showTable2(0);
}
else printf("Not find!\n");
printf("Press any key to return!");
getch();
}

void deleteRec()
{
int i, j;
char str[20];
system("cls");
printf("Please input the number you want to delete:");
scanf("%S",str);
i=findRec(str,1,0);
for(j=i;j<REC_NUM;j++)
records[j]=records[j+1];
REC_NUM--;
saveRec();
}
void copyRec(STUDENT*src,STUDENT*dest)
{
int i;
strcpy(dest->no,src->no);
strcpy(dest->name,src->name);
for(i=0;i<NUM_SUBJECT;i++)
dest->score[i]=src->score[i];
dest->total=src->total;
dest->average=src->average;
dest->order=src->order;
}
void orderRec()
{
int i;
records[0].order=1;
for(i=1;i<REC_NUM;i++)
if(records[i].total==records[i-1].total)
records[i].order=records[i-1].order;
else
records[i].order=i+1;
}
void sortRec()
{
int i,j,flag;
STUDENT t;
system("cls");
printf("\nsorting file\n");
for(i=0;i<REC_NUM;i++)
{
flag=0;
for(j=REC_NUM-1;j>i;j--)
if(records[j].total>records[j-1].total)
{
copyRec(&records[j],&t);
copyRec(&records[j-1],&records[j]);
copyRec(&t,&records[j-1]);
flag=1;
}
if(!flag) break;
}
orderRec();
delay(2000);
printf("\nsorting success\n");
saveRec();
}

int findRec(char *target,int tarType,int from)
{
int i;
for(i=from;i<REC_NUM;i++)
{
if((tarType==1&&strcmp(target,records[i].no)==0)
||tarType==2&&strcmp(target,records[i].name)==0)
return(i);
}
return(-1);
}
void modifyRec()
{
int i,j,sum;
char no[20],str[8];
system("cls");
printf("Please input the number you want to modify:");
scanf("%s",no);
i=findRec(no,1,0);
showTable1();
printf("| %2d | %4s | 6s |%4d |%4d | %4d | %4d | %5.1f | %5.1f|%2d |\n",i+1,records[i].no,records[i].name,records[i].score[0],records[i].score[1],records[i].score[2],records[i].score[3],records[i].total,records[i].average,records[i].order);
showTable2(0);
printf("Do you wang to modify this student(Y/N):");
scanf("%s",str);
if(str[0]=='y'||str[0]=='Y')
{
printf("enter number:");scanf("%s",records[i].no);
printf("enter name:");scanf("%s",records[i].name);
sum=0;
for(j=0;j<NUM_SUBJECT;j++)
{
printf("%s:",subject[j]);
scanf("%d",&records[i].score[j]);
sum=sum+records[i].score[j];
}
records[i].total=sum;
records[i].average=records[i].total/NUM_SUBJECT;
records[i].order=0;
}
printf("Press any key to return!");
getch();
}

void addRec()
{
int i,j,sum=0;
char no[20],str[8];
for(;;)
{
system("cls");
printf("Please input the number you want to add:");
scanf("%s",str);
i=findRec(str,1,0);
if(i==-1)break;
else printf("This number is exist!\n");
getch();
}
strcpy(records[REC_NUM].no,str);
printf("enter name:");scanf("%s",records[REC_NUM].name);
for(j=0;j<NUM_SUBJECT;j++)
{
printf("%s:",subject[j]);
scanf("%d",&records[REC_NUM].score[j]);
sum=sum+records[REC_NUM].score[j];
}
records[REC_NUM].total=sum;
records[REC_NUM].average=records[REC_NUM].total/NUM_SUBJECT;
records[REC_NUM].order=0;
REC_NUM++;
saveRec();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-27
这个问题
只能用链表或者文件来实现
#include<iostream>
#include<cstring>
#include<malloc.h>
using
namespace
std;
struct
lx
{
long
num;
char
name[20];
struct
lx
*link;
};
struct
lx
*addlist(struct
lx
*head,long
x);//添加节点;
void
listclear(struct
lx
*head);
struct
lx
*createlist(void
);
void
listprintf(struct
lx
*p);
int
main(int
argc,char
**argv)
{
long
x;
struct
lx
*p
=
createlist();
listprintf(p);
cout<<"输入学号"<<endl;
cin>>
x;
struct
lx
*head
=
addlist(p,x);
listprintf(head);
listclear(head);
//listprintf(temp);
return
0;
}
struct
lx
*createlist(void
)
{
struct
lx
*head
;
struct
lx
*tail
;
struct
lx
*p;
char
buf[20];
head
=
NULL;
p
=
(struct
lx
*)malloc(sizeof
(struct
lx));
//
cout<<
"内存分配失败!!!!"<<
endl;
cout<<
"请输入学号:";
cin>>
p->num;
cout<<
"请输入姓名:";
cin>>
p->name;
//cout<<buf<<endl;
//strcpy(p->name,
buf);
while(1)
{
if(head
==
NULL)
{
head
=
p;
tail
=
p;
}
else
{
tail->link
=
p;
tail
=
p;
}
p
=
(struct
lx*)malloc(sizeof(struct
lx));
//
cout<<"内存分配失败!!!!!"<<
endl;
cout<<
"请输入学号:";
cin>>
p->num;
if(p->num
==
0)
break;
cout<<
"请输入姓名:";
cin>>
p->name;
//strcpy(p->name,buf);
}
tail->link
=
NULL;
return
head;
}
void
listprintf(struct
lx
*p)
{
struct
lx*
q
=
p;
while(q!=
NULL)
{
cout<<
q->num<<endl;
cout<<
q->name<<endl;
q
=
q->link;
}
}
struct
lx
*addlist(struct
lx
*head,long
x)//添加节点
{
struct
lx
*p
=
head;
struct
lx
*q,*temp,*temp1;
q
=
NULL;
if(p->link
==
NULL
)
{
if((p->num
)
>
x
)
{
q=(struct
lx
*)malloc(sizeof(struct
lx));
cout<<"输入姓名:"<<endl;
cin>>q->name;
q->num
=
x;
q->link
=
p;
p
=
q;
}
else
{
q=(struct
lx
*)malloc(sizeof(struct
lx));
cout<<"输入姓名:"<<endl;
cin>>q->name;
q->num
=
x;
temp1
=
p->link;
p->link
=
q;
q->link
=
temp1;
temp1->link
=
NULL;
}
}
else
if(((p->num)
>
x)&&((p->link)->link
==
NULL))
{
q=(struct
lx
*)malloc(sizeof(struct
lx));
cout<<"输入姓名:"<<endl;
cin>>q->name;
q->num
=
x;
p->link
=
q;
q->link
=
p;
q->link
=
NULL;
}
else
{
while(1)
{
if((p->num
<
x)&&((p->link)->num
>
x))
break;
p
=
p->link;
}
q=(struct
lx
*)malloc(sizeof(struct
lx));
cout<<"输入姓名:"<<endl;
cin>>q->name;
q->num
=
x;
temp
=
p->link;
p->link
=
q;
q->link
=
temp;
}
return
p;
}
void
listclear(str
第2个回答  2009-03-09
需要原创的么?
相似回答