c课程设计学生成绩管理
#include<iostream.h>
/*head.h*/
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
#include<ctype.h>
typedef struct student
{
char num[6]; //定义学号
char name[8];//定义姓名
// int tax;//定义学生的按总分排名的名次,这个我不做了,自己可以加上,看看怎样修改,都做出来就没意思了呵呵。
int english;//定义英语成绩
int math;//定义数学成绩
// int score;//定义总分 这个我不要了
struct student *next;//指向下一个学生的指针链域
}student;
int getint(int a) //字符转换成数字
{
return (int)(a-'0');
}
student * head1;//头指针,全局变量
void student_read() //从文件中读入学生成绩原始数据
{
int i=7;//共有7个学生的记录,需要时可以修改该初始值
ifstream infile ("student.txt",ios::in);//读文件的操作使用C++
while(i>0)
{
student * p;//定义临时结构体指针变量p
p=new student;//开辟内存空间,并将p指向该地址的引用
infile>>p->num>>p->name>>p->english>>p->math;//为了简化
p->next=head1->next;
head1->next=p;
i--;//下标减1
}
}
void Reverselist(student *p)
{ student *p1,*p2,*p3;
student *_data;
_data=new student;
p1=p->next;
if(!p1->next) return;
p2=p1->next;
if(!p2->next)
{
strcpy(_data->num,p1->num);
strcpy(_data->name,p1->name);
// _data->tax=p1->tax;
_data->english=p1->english;
_data->math=p1->math;
//_data->score=p1->score;
strcpy(p1->num,p2->num);
strcpy(p1->name,p2->name);
// p1->tax=p2->tax;
p1->english=p2->english;
p1->math=p2->math;
//p1->score=p2->score;
strcpy(p2->num,_data->num);
strcpy(p2->name,_data->name);
// p2->tax=_data->tax;
p2->english=_data->english;
p2->math=_data->math;
//p2->score=_data->score;
return;
}//if
p3=p2->next;
p1->next=NULL;
while(p3->next)
{p2->next=p1;
p1=p2;
p2=p3;
p3=p3->next;
}//while
p2->next=p1;
p3->next=p2;
p->next=p3;
}//Reverselist
void student_order(student *p)
{ student *_temp = p->next;
student *_node = p->next;
student *temp;
temp=new student;
temp->next=NULL;
for (;_temp->next;_temp = _temp->next)
{
for (_node = p->next;_node->next;_node = _node ->next)
{
if ((_node->english+_node->math)>(_node->next->english+_node->next->math))
{
strcpy(temp->num,_node->num);
strcpy(temp->name,_node->name);
temp->english=_node->english;
temp->math=_node->math;
// temp->score=_node->score;
strcpy(_node->num,_node->next->num);
strcpy(_node->name,_node->next->name);
_node->english=_node->next->english;
_node->math=_node->next->math;
//_node->score=_node->next->score;
strcpy(_node->next->num,temp->num);
strcpy(_node->next->name,temp->name);
_node->next->english=temp->english;
_node->next->math=temp->math;
//_node->next->score=temp->score;
}//if
}//for
}//for
Reverselist(p);
}//student_order
void student_output(student *p)
{ cout<<"学号 姓名 英语 数学\t\n";
p=p->next;
while(p)
{cout<<" "<<p->num<<"\t"<<p->name<<"\t"<<p->english<<"\t"<<p->math<<endl;
p=p->next;
}
}
void student_output1(student *p)
{ cout<<"学号 姓名 英语 数学 总分\t\n";
p=p->next;
while(p)
{ cout<<" "<<p->num<<"\t"<<p->name<<"\t"<<p->english<<"\t"<<p->math<<"\t "<<(p->english+p->math)<<endl;
p=p->next;
}
}
void student_write() //将项目数据写入文本文档
{
student * p;
p=head1;
p=p->next;
ofstream outfile("result.txt",ios::out);
while (p!=NULL)
{
outfile<<" "<<p->num<<"\t"<<p->name<<"\t"<<p->english<<"\t"<<p->math<<"\t "<<p->english+p->math<<endl;
p=p->next;
}
outfile.close();
}
/*主程序*/
#include<iostream.h>
#include<fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include<conio.h>
#include"head.h"
void main()
{ system("color 1b");
head1=new student;
head1->next=NULL;
student_read(); //读入学生数据
student * p1;
p1=head1;
p1=p1->next;
int temp;
student_output(head1); /*显示原有的记录*/
student_order(head1);
student_output1(head1); //信息的输出函数
student_write();//将学校数据写入文本
getch();
}
⑵ c程序课程设计,学生成绩管理系统
*
学生成绩管理程序
编制一个统计学生考试分数的管理程序。
设学生成绩已以一个学生一个记录的形式存储在文件中,
每位学生记录包含的信息有:姓名,学号和各门功课的成绩。
程序具有以下几项功能:求出各门课程的总分,平均分,按姓名,
按学号寻找其记录并显示,浏览全部学生成绩和按总分由高到低显示学生信息等。
*/
#include <stdio.h>
#define SWN 3 /* 课程数 */
#define NAMELEN 20 /* 姓名最大字符数 */
#define CODELEN 10 /* 学号最大字符数 */
#define FNAMELEN 80 /* 文件名最大字符数 */
#define BUFLEN 80 /* 缓冲区最大字符数 */
/* 课程名称表 */
char schoolwork[SWN][NAMELEN+1] = {"Chinese","Mathematic","English"};
struct record
{
char name[NAMELEN+1]; /* 姓名 */
char code[CODELEN+1]; /* 学号 */
int marks[SWN]; /* 各课程成绩 */
int total; /* 总分 */
}stu;
struct node
{
char name[NAMELEN+1]; /* 姓名 */
char code[CODELEN+1]; /* 学号 */
int marks[SWN]; /* 各课程成绩 */
int total; /* 总分 */
struct node *next; /* 后续表元指针 */
}*head; /* 链表首指针 */
int total[SWN]; /* 各课程总分 */
FILE *stfpt; /* 文件指针 */
char stuf[FNAMELEN]; /* 文件名 */
/* 从指定文件读入一个记录 */
int readrecord(FILE *fpt,struct record *rpt)
{
char buf[BUFLEN];
int i;
if(fscanf(fpt,"%s",buf)!=1)
return 0; /* 文件结束 */
strncpy(rpt->name,buf,NAMELEN);
fscanf(fpt,"%s",buf);
strncpy(rpt->code,buf,CODELEN);
for(i=0;i<SWN;i++)
fscanf(fpt,"%d",&rpt->marks[i]);
for(rpt->total=0,i=0;i<SWN;i++)
rpt->total+=rpt->marks[i];
return 1;
}
/* 对指定文件写入一个记录 */
writerecord(FILE *fpt,struct record *rpt)
{
int i;
fprintf(fpt,"%s\n",rpt->name);
fprintf(fpt,"%s\n",rpt->code);
for(i=0;i<SWN;i++)
fprintf(fpt,"%d\n",rpt->marks[i]);
return ;
}
/* 显示学生记录 */
displaystu(struct record *rpt)
{
int i;
printf("\nName : %s\n",rpt->name);
printf("Code : %s\n",rpt->code);
printf("Marks :\n");
for(i=0;i<SWN;i++)
printf(" %-15s : %4d\n",schoolwork[i],rpt->marks[i]);
printf("Total : %4d\n",rpt->total);
}
/* 计算各单科总分 */
int totalmark(char *fname)
{
FILE *fp;
struct record s;
int count,i;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return 0;
}
for(i=0;i<SWN;i++)
total[i]=0;
count=0;
while(readrecord(fp,&s)!=0)
{
for(i=0;i<SWN;i++)
total[i]+=s.marks[i];
count++;
}
fclose(fp);
return count; /* 返回记录数 */
}
/* 列表显示学生信息 */
void liststu(char *fname)
{
FILE *fp;
struct record s;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return ;
}
while(readrecord(fp,&s)!=0)
{
displaystu(&s);
printf("\n Press ENTER to continue...\n");
while(getchar()!='\n');
}
fclose(fp);
return;
}
/* 构造链表 */
struct node *makelist(char *fname)
{
FILE *fp;
struct record s;
struct node *p,*u,*v,*h;
int i;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return NULL;
}
h=NULL;
p=(struct node *)malloc(sizeof(struct node));
while(readrecord(fp,(struct record *)p)!=0)
{
v=h;
while(v&&p->total<=v->total)
{
u=v;
v=v->next;
}
if(v==h)
h=p;
else
u->next=p;
p->next=v;
p=(struct node *)malloc(sizeof(struct node));
}
free(p);
fclose(fp);
return h;
}
/* 顺序显示链表各表元 */
void displaylist(struct node *h)
{
while(h!=NULL)
{
displaystu((struct record *)h);
printf("\n Press ENTER to continue...\n");
while(getchar()!='\n');
h=h->next;
}
return;
}
/* 按学生姓名查找学生记录 */
int retrievebyn(char *fname, char *key)
{
FILE *fp;
int c;
struct record s;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return 0;
}
c=0;
while(readrecord(fp,&s)!=0)
{
if(strcmp(s.name,key)==0)
{
displaystu(&s);
c++;
}
}
fclose(fp);
if(c==0)
printf("The student %s is not in the file %s.\n",key,fname);
return 1;
}
/* 按学生学号查找学生记录 */
int retrievebyc(char *fname, char *key)
{
FILE *fp;
int c;
struct record s;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return 0;
}
c=0;
while(readrecord(fp,&s)!=0)
{
if(strcmp(s.code,key)==0)
{
displaystu(&s);
c++;
break;
}
}
fclose(fp);
if(c==0)
printf("The student %s is not in the file %s.\n",key,fname);
return 1;
}
main()
{
int i,j,n;
char c;
char buf[BUFLEN];
FILE *fp;
struct record s;
clrscr();
printf("Please input the students marks record file's name: ");
scanf("%s",stuf);
if((fp=fopen(stuf,"r"))==NULL)
{
printf("The file %s doesn't exit, do you want to creat it? (Y/N) ",stuf);
getchar();
c=getchar();
if(c=='Y'||c=='y')
{
fp=fopen(stuf,"w");
printf("Please input the record number you want to write to the file: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Input the student's name: ");
scanf("%s",&s.name);
printf("Input the student's code: ");
scanf("%s",&s.code);
for(j=0;j<SWN;j++)
{
printf("Input the %s mark: ",schoolwork[j]);
scanf("%d",&s.marks[j]);
}
writerecord(fp,&s);
}
fclose(fp);
}
}
fclose(fp);
getchar();
/*clrscr();*/
puts("Now you can input a command to manage the records.");
puts("m : mean of the marks.");
puts("t : total of the marks.");
puts("n : search record by student's name.");
puts("c : search record by student's code.");
puts("l : list all the records.");
puts("s : sort and list the records by the total.");
puts("q : quit!");
while(1)
{
puts("Please input command:");
scanf(" %c",&c); /* 输入选择命令 */
if(c=='q'||c=='Q')
{
puts("\n Thank you for your using.");
break; /* q,结束程序运行 */
}
switch(c)
{
case 'm': /* 计算平均分 */
case 'M':
if((n=totalmark(stuf))==0)
{
puts("Error!");
break;
}
printf("\n");
for(i=0;i<SWN;i++)
printf("%-15s's average is: %.2f.\n",schoolwork[i],(float)total[i]/n);
break;
case 't': /* 计算总分 */
case 'T':
if((n=totalmark(stuf))==0)
{
puts("Error!");
break;
}
printf("\n");
for(i=0;i<SWN;i++)
printf("%-15s's total mark is: %d.\n",schoolwork[i],total[i]);
break;
case 'n': /* 按学生的姓名寻找记录 */
case 'N':
printf("Please input the student's name you want to search: ");
scanf("%s",buf);
retrievebyn(stuf,buf);
break;
case 'c': /* 按学生的学号寻找记录 */
case 'C':
printf("Please input the student's code you want to search: ");
scanf("%s",buf);
retrievebyc(stuf,buf);
break;
case 'l': /* 列出所有学生记录 */
case 'L':
liststu(stuf);
break;
case 's': /* 按总分从高到低排列显示 */
case 'S':
if((head=makelist(stuf))!=NULL)
displaylist(head);
break;
default: break;
}
}
}
⑶ c语言课程设计之学生成绩管理系统设计的程序
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include<string.h>
#define MAX 80
#define max 3
int nu=0;
struct classname
{
char name[20];
float score;
};
struct student
{
char no[20];
char std_name[20];
struct classname km[max];
float ave;
float sum;
int save;
};
struct student stu[MAX],*p;
void chushi()
{
int i,j;
for(i=0;i<MAX;i++)
{
for(j=0;j<20;j++)
{
stu[i].no[j]=NULL;
stu[i].std_name[j]=NULL;
stu[i].km[j].name[j]=NULL;
stu[i].km[j].score=0;
}
stu[i].ave=0;
stu[i].sum=0;
stu[i].save=0;
}
}
void av()/*求平均值*/
{
int i;
for(i=0;i<nu;i++)
{
stu[i].sum=stu[i].km[1].score+stu[i].km[2].score+stu[i].km[3].score;
stu[i].ave=stu[i].sum/3;
}
}
void first_check()
{
FILE *p;
int i,j;
struct classname frist[max];
for(i=0;i<max;i++)
{
for(j=0;j<20;j++)
frist[i].name[j]=NULL;
frist[i].score=0;
}
if ((p=fopen("c:\\kemu.txt","r"))==NULL)
{
printf("您好,欢迎使用学生成绩管理系统\n\n因为您是第一次使用,请输入科目名称(三科)\n\n");
p=fopen("c:\\kemu.txt","w");
printf("输入课程1名称:");
scanf("%s",frist[0].name);
fprintf(p,"%s\n",frist[0].name);
printf("输入课程2名称:");
scanf("%s",frist[1].name);
fprintf(p,"%s\n",frist[1].name);
printf("输入课程3名称:");
scanf("%s",frist[2].name);
fprintf(p,"%s\n",frist[2].name);
}
system("cls");
fclose(p);
}
void save_nu()
{
FILE *p;
p=fopen("c:\\renshu.txt","w");
fprintf(p,"%d\n",nu);
fclose(p);
}
void Save_add(int n)
{
FILE * p;
int i;
p= fopen("c:\\cheji.txt","at");
if (p == NULL)
{
printf("文件不存在!!\n");
exit(0);
}
save_nu();
for (i = 0;i<n;i++)
if(stu[i].save==1)
{
stu[i].sum=stu[i].km[1].score+stu[i].km[2].score+stu[i].km[3].score;
stu[i].ave=stu[i].sum/3;
fprintf(p,"%s %s %2.1f %2.1f %2.1f %2.1f %2.1f \n",stu[i].no,stu[i].std_name,stu[i].km[0].score,stu[i].km[1].score,stu[i].km[2].score,stu[i].ave,stu[i].sum);
}
fclose(p);
}
void Save()
{
FILE * p;
int i;
p= fopen("c:\\cheji.txt","w");
if (p == NULL)
{
printf("文件不存在!!\n");
exit(0);
}
save_nu();
for (i = 0;i<nu;i++)
if(stu[i].save==1)
{
av();
fprintf(p,"%s %s %2.1f %2.1f %2.1f %2.1f %2.1f \n",stu[i].no,stu[i].std_name,stu[i].km[0].score,stu[i].km[1].score,stu[i].km[2].score,stu[i].ave,stu[i].sum);
}
fclose(p);
}
int read_nu()
{
FILE *p;
char ch,s[10]={'\0'};
int i=0;
p=fopen("c:\\renshu.txt","r");
if(p==NULL)
{
save_nu();
return 0;
}
ch=fgetc(p);
while(ch!='\n')
{
s[i]=ch;
ch=fgetc(p);
i++;
}
nu=atoi(s);
fclose(p);
return 0;
}
int read_km()
{
FILE *p;
int i,j=0;
char s[20]={'\0'};
chushi();
p=fopen("c:\\kemu.txt","r");
if(p==NULL)
{
printf("ERROR read_km");
return 0;
}
fgets(s,20,p);
while(strlen(s)!=0)
{
for(i=0;i<strlen(s);i++)
if(s[i]==10)
{
s[i]='\0';
break;
}
for(i=0;i<=nu;i++)
strcpy(stu[i].km[j].name,s);
for(i=0;i<20;i++)
s[i]='\0';
j++;
fgets(s,20,p);
}
}
void read()
{
FILE *p;
int i,j,n,k,z=0;
char s[50]={'\0'};
char o[10]={'\0'};
p=fopen("c:\\cheji.txt","r");
if(p==NULL)
printf("ERROR_read");
chushi();
read_km();
fgets(s,50,p);
while(strlen(s)!=0)
{
j=0;
for(i=0;i<50;i++)
{
if(s[i]!='\n')
{
n=0;
while(j==0)
{
if(s[i]!=' ')
{
stu[z].no[n]=s[i];
n++;i++;
}
else
break;
}
while(j==1)
{
if(s[i]!=' ')
{
stu[z].std_name[n]=s[i];
n++;i++;
}
else
break;
}
while(j==2)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[0].score=atoi(o);
break;
}
}
while(j==3)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[1].score=atoi(o);
break;
}
}
while(j==4)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[2].score=atoi(o);
break;
}
}
while(j==5)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].ave=atoi(o);
break;
}
}
while(j==6)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].sum=atoi(o);
break;
}
}
for(k=0;k<10;k++)
o[k]='\0';
}
else
break;
j++;
}
for(i=0;i<50;i++)
s[i]='\0';
fgets(s,50,p);
z++;
}
}
void putin()
{
int n,i=0;
char ch;
read_km();
do
{
printf("\t\t\t\t录入学员信息\n输入第%d个学员的信息\n",i+1);
printf("\n输入学生编号:");
scanf("%s",stu[i].no);
printf("\n输入学员姓名:");
scanf("%s",stu[i].std_name);
printf("\n输入课程%s的分数:",stu[0].km[0].name);
scanf("%f",&stu[i].km[0].score);
printf("\n输入课程%s的分数:",stu[0].km[1].name);
scanf("%f",&stu[i].km[1].score);
printf("\n输入课程%s的分数:",stu[0].km[2].name);
scanf("%f",&stu[i].km[2].score);
stu[i].save=1;
printf("\n\n");
i++;
n=i;
printf("是否继续输入?(Y/N)");
fflush(stdin);
ch=getch();
system("cls");
}
while(ch!='n'&&ch!='N');
system("cls");
if(nu==0)
{
nu=n;
Save();
}
else
{
nu=n+nu;
Save_add(n);
}
}
int putout()
{
int i;char s;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
read();
do
{
printf("学生成绩信息:\n\n");
for(i=0;i<nu;i++)
printf("学号:%s 姓名:%s\n%s分数:%2.1f\t%s分数:%2.1f\t%s分数:%2.1f\n平均分数:%2.1f\t总成绩:%2.1f\n\n",stu[i].no,stu[i].std_name,stu[i].km[0].name,stu[i].km[0].score,stu[i].km[1].name,stu[i].km[1].score,stu[i].km[2].name,stu[i].km[2].score,stu[i].ave,stu[i].sum);
printf("\t\t按任意键返回主菜单");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
}
int sort()/*排序数据函数*/
{
struct student temp;
int i,j;
char s;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
chushi();
read();
for(i=1;i<nu;i++)
{
for(j=1;j<=nu-i;j++)
{
if(stu[j-1].ave<stu[j].ave)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
}
}
}
do
{
printf("学生成绩信息:\n\n");
for(i=0;i<nu;i++)
printf("学号:%s 姓名:%s 平均成绩:%2.1f\n\n",stu[i].no,stu[i].std_name,stu[i].ave);
printf("\t\t按任意键返回主菜单");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
}
void find()/*查询函数*/
{
int j,i=0;
int c=0;
char search[10]={'\0'};
char as;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
chushi();
read();
do
{
printf("输入要查询课程名称:");
scanf("%s",search);
for(j=0;j<max;j++)
if(!strcmp(stu[i].km[j].name,search))
{
c=1;
printf("\n该课程不及格学生姓名:\n");
for(i=0;i<nu;i++)
if(stu[i].km[j].score<60)
printf("%s\n",stu[i].std_name);
}
if(c==0)
printf("无此课程!");
printf("\n\t\t按任意键返回主菜单");
fflush(stdin);
as=getch();
}
while(!as);
system("cls");
}
void tongji()
{
int j,m,z,i=0;
char s;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
chushi();
read();
for(z=0;z<max;z++)
{
m=stu[i].km[z].score;j=0;
printf("%s 最高分: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(m<stu[i].km[z].score)
{
m=stu[i].km[z].score;
j=i;
}
printf("%s\t",stu[j].std_name);
j=0;i=0;m=stu[i].km[z].score;
printf("%s 最低分: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(m>stu[i].km[z].score)
{
m=stu[i].km[z].score;
j=i;
}
printf("%s\t",stu[j].std_name);
m=0;j=0;i=0;
printf("%s 平均分: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
m=m+stu[i].km[z].score;
printf("%d\n",m/nu);
m=0;i=0;
printf("%s 分数低于的60人数: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(stu[i].km[z].score<60)
m++;
printf("%d\t",m);
m=0;j=0;i=0;
printf("%s 分数高于60的人数: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(stu[i].km[z].score>60)
m++;
printf("%d\n\n",m);
}
do
{
printf("\t\t按任意键返回主菜单");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
}
void main()/*主函数*/
{
int as;
first_check();
start: printf("\n\t\t\t欢迎使用学生成绩管理系统\n");
/*一下为功能选择模块*/
do
{
printf("\n\t\t\t\t1.录入学员信息\n\t\t\t\t2.显示学员信息\n\t\t\t\t3.成绩排序信息\n\t\t\t\t4.查询不及格学生\n\t\t\t\t5.统计信息\n\t\t\t\t6.退出\n");
printf("\t\t\t\t选择功能选项:");
fflush(stdin);
read_nu();
scanf("%d",&as);
switch(as)
{
case 1:system("cls");putin();break;
case 2:system("cls");putout();break;
case 3:system("cls");sort();break;
case 4:system("cls");find();break;
case 5:system("cls");tongji();break;
case 6:system("exit");exit(0);
default:system("cls");goto start;
}
}
while(1);
/*至此功能选择结束*/
}
⑷ c语言课程设计 学生成绩管理系统
楼主笑纳
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10 /*定义常量SIZE便于以后的修改*/
struct student /*定义一个结构体数组存放学生的信息*/
{
int number; /*学号*/
char name[20];/*名字*/
float score[3];/*分数*/
float average;/*平均分*/
}stu[SIZE];
void menu();/*调用菜单函数*/
void write();/*读入信息*/
void save();/*保存stud.dat文件函数*/
void open();/*检查是否正确保存*/
void inturn (struct student c[]);/*用于对学生的信息按平均分排序的函数*/
void save2();/*将排序后的信息存入studsort.dat文件中*/
void read();/*读取studsort.dat文件文件中第2 4 6 8 10个学生的信息*/
void main()
{
int choice;/*用户选择变量*/
printf("*******************************************************************************\n");
printf("* *\n");
printf("* Hwadee &学生成绩文件管理& Hwadee *\n");
printf("* *\n");
printf("*******************************************************************************\n\n\n");
printf("******************************●●欢迎使用●●*********************************");
system("pause");
while (1)
{
menu();/*调用菜单函数形成操作界面*/
printf("请选择:\t");
scanf("%d", &choice);
if ( choice == 0 )
{
system("cls");
printf("\n\n\t\t\t\t谢谢使用!!!);
break;
}
switch(choice) /*多重选择实现功能不同的功能*/
{
case 1:
write();
break;
case 2:
system("cls");
save();
break;
case 3:
system("pause");
system("cls");
open();
break;
case 4:
system("cls");
printf("排序前的学生信息:\n");
open();
inturn(stu);
save2();
break;
case 5:
system("cls");
read();
break;
default:
printf("\n无此项功能!\n请重新输入\n");
}
}
}
void menu()
{
printf("\n1*****输入学生信息\t\t2*****将信息存入文件stud.dat中\n");
printf("3*****检查文件数据\t\t4*****将学生信息排序并存入文件studsort.dat中\n");
printf("5*****读取文件studsort.dat中的第 2 4 6 8 10个学生的信息\n");
printf("0*****退出系统\n\n\n");
}
/**********************************************************************\
函数名称:
write
功能描述:
完成将学生信息写入
函数参数:
i stu
返回值:
无
模块历史:
\*********************************************************************/
void write()
{
int i;/*计数变量*/
stu[i].average = 0;/*初始化结构体成员 average*/
printf("请你输入学生的信息\n");
printf("学号\t姓名\t语文\t数学\t英语\t\n");
for (i=0; i<SIZE;i++)
{
scanf("%d\t",&stu[i].number);
if (stu[i].number == 0)/*不需输入信息时输入0即可*/
break;
scanf("%s\t%f\t%f\t%f",&stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
stu[i].average = (stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;/*计算平均成绩*/
}
}
/**********************************************************************\
函数名称:
save
功能描述:
将写入的信息读入文件中
函数参数:
FILE *fp i
返回值:
无
模块历史:
\*********************************************************************/
void save()
{
FILE *fp;/*定义文件指针用于向文件读入数据*/
int i;
if ((fp=fopen("stud.dat","wb")) == NULL)
{
printf("cannot open file\n");
return;
}
for (i=0;i<SIZE;i++)
if (fwrite(&stu[i],sizeof(struct student),1,fp) != 1)
printf("file write error\n");
fclose(fp);
printf("\n信息保存成功!恭喜!!\n\n");
}
/**********************************************************************\
函数名称:
open
功能描述:
用于检查读入文件的数据是否正确
函数参数:
FILE *cp i
返回值:
无
模块历史:
\*********************************************************************/
void open()
{
int i;
FILE *cp;
cp = fopen ("stud.dat","rb");
printf("保存在stud.dat文件中的信息:\n\n");
printf("学号\t姓名\t数学\t语文\t英语\t平均分\n\n");
for (i=0;i<SIZE;i++)
{
fread(&stu[i],sizeof(struct student),1,cp);
printf("%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\n\n\n",stu[i].number, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].average );
}
fclose (cp);
}
/**********************************************************************\
函数名称:
inturn
功能描述:
用于对结构体数组中的元素排序
函数参数:
into i,j,k
struct student temp
返回值:
无
模块历史:
\*********************************************************************/
void inturn(struct student m[])
{
int i,j,k;/*计数变量*/
struct student temp;/*中间变量 类型为结构体*/
for(i=0; i<SIZE-1; i++) /*运用冒泡排序对结构体数组进行排序*/
for (j=i+1; j<SIZE; j++)
{
if( m[i].average < m[j].average )
{
temp = m[i];
m[i] = m[j];
m[j] = temp;
}
}
printf("\n排序后的学生信息:\n\n");
printf(" 学号\t姓名\t数学\t语文\t英语\t平均分\n");
for (i=0; i<SIZE; i++)
{
printf("第%d名 %d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\n\n\n",i+1, stu[i].number, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].average );
}/*输出排序后的学生信息*/
}
/**********************************************************************\
函数名称:
save2
功能描述:
将排序后的学生信息读入到另外的文件中
函数参数:
FILE *mp
i
返回值:
无
模块历史:
\*********************************************************************/
void save2()
{
FILE *mp;
int i;
if ((mp=fopen("studsort.dat","wb"))==NULL)
{
printf("cannot open file\n");
return;
}
for (i=0;i<SIZE;i++)
if (fwrite(&stu[i], sizeof(struct student), 1, mp) != 1)
printf("file write error\n");
fclose(mp);/*读取完毕关闭文件*/
}
/**********************************************************************\
函数名称:
read
功能描述:
读出另外文件中的信息
函数参数:
FILE *tp
i
返回值:
无
模块历史:
\*********************************************************************/
void read()
{
int i=1;
FILE *tp;
tp = fopen ("studsort.dat", "rb" );
printf("studsort.dat文件中偶数号码学生的信息如下:\n\n");
printf("学号\t姓名\t数学\t语文\t英语\t平均分\n\n");
for (i = 1;i<SIZE;i += 2)
{
fseek(tp,i*sizeof(struct student),0);/*fseek函数可以根据用户所需对文件开头的偏移量来读取文件的数据。
k*sizeof(struct student)是指将位置指针移到当前位置k个字节处*/
fread(&stu[i],sizeof(struct student),1,tp);
/*注意:必须使用fseek函数定位后才能根据自己所需读出数据,但是只用fseek函数不用fread,
只是把数据打印到屏幕上而并没有从文件中读取。这是一个常见性问题*/
printf("%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\n", stu[i].number, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].average );
}
fclose (tp);/*读取完毕关闭文件*/
}
⑸ c语言课程设计学生成绩管理系统
直接在网络上搜 有 你不必在提问了
⑹ C语言课程设计学生成绩管理系统 功能:学生成绩管理系统,每个学
参考以下,部分代码改了即可:首先将记录储存再TXT文件下,格式如下所示:学号姓名性别等级笔试机试类别1张三男二级66772李四男三级88993张二男二级40604李二女二级50595王五女三级99996王三男二级77617刘四男四级60598刘五女二级88779张五女二级648110李六女二级5930-------------------------------------------------------------代码如下,本人亲自编写,无错误通过--------------------------------------------------------------------#include#include#include#includeusingnamespacestd;voidadd_information(stringstr);voiddelete_information(stringstr);voidedit_information(stringstr);voidscanf_information(stringstr);voidscore_scanf(stringstr);voidpingfen(stringstr);voidpass_total(stringstr);main(){cout>number;stringname;//统计用的科目名switch(number){case1:cout>number;switch(number){case1:add_information(str);break;case2:delete_information(str);break;case3:edit_information(str);break;case4:scanf_information(str);break;default:cout>a>>b>>c>>d>>e>>f;outstream.precision(6);//显示精度outstreamname_1;stringa,b,c,d,e,f;ofstreamoutstream;//暂存的中间文件outstream.open("temp.txt");boolflag=0;//是否查找到while(1){//删除操作,自己感觉都有点麻烦instream>>a>>b>>c>>d>>e>>f;if(name_1!=a){outstreamname_1;stringa,b,c,d,e,f;ofstreamoutstream;//暂存的中间文件outstream.open("temp.txt");boolflag=0;//是否查找到while(1){//删除操作,自己感觉都有点麻烦instream>>a>>b>>c>>d>>e>>f;if(name_1==a){//找到修改的记录flag=1;cout>a>>b>>c>>d>>e>>f;}outstreama>>b>>c>>d>>e>>f;coutname_1;stringa,b,c,d,e,f,g;boolflag=0;//是否查找到while(1){//删除操作,自己感觉都有点麻烦instream>>a>>b>>c>>d>>e>>f>>g;if(name_1==g){//找到修改的记录flag=1;couta>>b>>c>>d>>e>>f;outstream=85)outstream=70&&f=60&&f=70&&e=70)outstream=60&&f=60&&e=60)outstreama>>b>>c>>d>>e>>f>>g;if(g=="优秀"||g=="良好"||g=="及格")count++;if(instream.eof())break;}cout<<"合格的人数为:"<
⑺ C语言课程设计学生成绩管理
/*********************************************************
*创建日期:2011-04-27
*程序名称:链表综合操作
*程序作者:子夜星空
*备注信息:以前写的。
**********************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SN 2 //科目数
typedef struct student
{
char num[10],
name[10];
float score[SN],
sum,
avg;
struct student *next;
}STU;
/**********输入链表单元内容************/
void input(STU *p)
{
int i;
printf("please input number:\n");
scanf("%s",p->num);
printf("please input name:\n");
scanf("%s",p->name);
printf("please input %d scores:\n",SN);
p->sum=0;
for(i=0;i<SN;i++)
{
scanf("%f",&p->score[i]);
p->sum+=p->score[i];
}
p->avg=p->sum/SN;
}
/**********创建一个链表单元**********/
STU *creat_node()
{
STU *p;
p=(STU *)malloc(sizeof(STU));
if(p == NULL)
{ printf("No enough memory !");
exit(0);
}
input(p);
p->next=NULL;
return p;
}
/**********创建一个链表**********/
STU *creat_list()
{
STU *head=NULL,*tail=NULL,*p;
char str[4];
printf("List creating...\n");
do
{
printf("Do you want to continue (yes/no) :");
scanf("%s",str);
if(strcmp(str,"yes")==0)
{
p=creat_node();
if(head==NULL){head=tail=p;continue;}
tail->next=p;
tail=p;
}
if(strcmp(str,"yes")!=0&&strcmp(str,"no")!=0)
{
printf("You must input 'yes' or 'no'.\n");
//getchar();
continue;
}
if(strcmp(str,"no")==0)break;
//getchar();
}while(1);
printf("List create end...\n\n");
return head;
}
/************输出一个链表单元**********/
void print_a_node(STU *fin)
{
int i;
printf("%s;\t%s;\t%0.2f;\t%0.2f\t",fin->num,fin->name,fin->avg,fin->sum);
for(i=0;i<SN;i++)
printf("%0.2f\t",fin->score[i]);
putchar(10);
}
/************输出一个链表头部**********/
void print_a_head()
{
int i;
printf("number\tname\tavg\tsum\t");
for(i=0;i<SN;i++)
printf("score%d\t",i+1);
putchar(10);
}
/************输出操作菜单**********/
void print_menu_list()
{
printf("======the operation menu list======\n");
printf("[0]-->exit\n[1]-->creat a list\n[2]-->print the list\n[3]-->insert a list node\n[4]-->select by number\n[5]-->select by name\n");
printf("[6]-->delete a list node\n[7]-->update a list node\n[8]-->order the list by score\n[9]-->print the operation menu list\n");
printf("======the operation menu list======\n");
putchar(10);
}
/************输出链表**********/
int print_list(STU *stu)
{
STU *p=stu;
if(stu==NULL)
{
printf("no records!!!\n");
return (0);
}
print_a_head();
while(p!=NULL)
{
print_a_node(p);
p=p->next;
}
putchar(10);
return (0);
}
/************插入链表单元************/
void insert(STU *stu)
{
STU *tail=stu,*p;
printf("now insert a list node...\n");
while(tail->next!=NULL)
{
tail=tail->next;
}
p=creat_node();
tail->next=p;
printf("Insert end...\n\n");
}
/**********查找链表num**********/
STU *find_num(STU *stu, char num[])
{
STU *p=stu,*pr=NULL;
while(p!=NULL)
{
if(strcmp(p->num,num)==0){pr=p;break;}
p=p->next;
}
return pr;
}
/**********查找链表name**********/
STU *find_name(STU *stu, char name[])
{
STU *p=stu,*pr=NULL;
while(p!=NULL)
{
if(strcmp(p->name,name)==0){pr=p;break;}
p=p->next;
}
return pr;
}
/************删除链表单元************/
STU * delet(STU *stu, char name[])
{
STU *p=stu,*front=stu;
if((p=find_name(stu,name))!=NULL)
{
printf("the delete record:\n");
print_a_head();
print_a_node(p);
}
else
{
printf("can not find the student!\n");
return stu;
}
p=stu;
while(p!=NULL&&strcmp(p->name,name)!=0)
{
front=p;
p=p->next;
}
if(p==stu&&front==stu)stu=NULL;
else front->next=p->next;
if(p!=NULL)p->next=NULL;
free(p);
printf("delete end...\n\n");
return stu;
}
/**********更新链表单元**********/
void update(STU *stu, char name[])
{
STU *fin;
if((fin=find_name(stu,name))!=NULL)
{
printf("before update:\n");
print_a_head();
print_a_node(fin);
}
else
{
printf("can not find the student!\n");
exit(0);
}
printf("please input the new records now...\n");
input(fin);
printf("update end...\n\n");
}
/**********链表单元排序**********/
void order(STU *stu)
{
STU *pi,*pj,*max,temp;
int i;
if(stu!=NULL&&stu->next!=NULL)
{
for(pi=stu;pi!=NULL;pi=pi->next)
{
max=pi;
for(pj=pi->next;pj!=NULL;pj=pj->next)
{
if(max->sum<pj->sum)
max=pj;
}
if(max!=pi)
{
strcpy(temp.num,max->num);
strcpy(max->num,pi->num);
strcpy(pi->num,temp.num);
strcpy(temp.name,max->name);
strcpy(max->name,pi->name);
strcpy(pi->name,temp.name);
temp.sum=pi->sum;
pi->sum=max->sum;
max->sum=temp.sum;
temp.avg=max->avg;
max->avg=pi->avg;
pi->avg=temp.avg;
for(i=0;i<SN;i++)
{
temp.score[i]=max->score[i];
max->score[i]=pi->score[i];
pi->score[i]=temp.score[i];
}
}
}
printf("order end...\n\n");
}
else
printf("do not need to order...\n\n");
}
/************释放链表**********/
void fre(STU *stu)
{
STU *p=stu,*pf;
if(stu==NULL)
{
printf("the list is NULL!\n");
exit(0);
}
while(p!=NULL)
{
pf=p->next;
free(p);
p=pf;
}
if(stu==NULL)
printf("free the list.\n");
}
STU * menu(STU *stu,int cas)
{
STU *fin=NULL;
char a[10];
switch(cas)
{
//创建链表
case 1:
if(stu!=NULL)fre(stu);
stu=creat_list();
break;
//输出链表
case 2:
if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}
print_list(stu);
break;
//插入链表单元
case 3:
if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}
insert(stu);
break;
//查找输出number
case 4:
if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}
printf("please input the 'number' you want to find:\n");
scanf("%s",a);
if((fin=find_num(stu,a))!=NULL)
{
print_a_head();
print_a_node(fin);
}
else printf("no found!\n");
break;
//查找输出name
case 5:
if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}
printf("please input the 'name' you want to find:\n");
scanf("%s",a);
if((fin=find_name(stu,a))!=NULL)
{
print_a_head();
print_a_node(fin);
putchar(10);
}
else printf("no found!\n");
break;
//删除链表单元
case 6:
if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}
printf("please input the 'name' you want to delete:\n");
scanf("%s",a);
stu=delet(stu,a);
break;
//更新链表单元
case 7:
if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}
printf("please input the 'name' you want to update:\n");
scanf("%s",a);
update(stu,a);
break;
//链表单元排序
case 8:
if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}
printf("order by score\n");
order(stu);
break;
//打印链表操作菜单
case 9:
print_menu_list();
break;
default:
printf("can not do this operation!\n");putchar(10);break;
}
return stu;
}
void main()
{
STU *stu=NULL;
int cas;
//打印操作提示
print_menu_list();
//用户操作
do
{
printf("press 0~9 to choose operation!\n");
scanf("%d",&cas);
if(cas<0||cas>9){printf("you must press 0 to 9 !\n");continue;}
if(cas!=0)stu=menu(stu,cas);
if(cas==0){printf("operation end !\n\n");fre(stu);}
}while(cas!=0);
//释放链表
fre(stu);
}