㈠ c语言程序设计:学生成绩管理系统
include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕操作函数*/
#include "mem.h" /*内存操作函数*/
#include "ctype.h" /*字符操作函数*/
#include "alloc.h" /*动态地址分配函数*/
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;
void shuru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i<=1000;i++)
{
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);
}
void xianshi()
{
float s;int n;
if((fp=fopen("s_score.txt","rb+"))==NULL)
{
printf("Cannot reading this file.\n");
exit(0);
}
for(i=0;i<=1000;i++)
{
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break;
}
printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n");
for(j=0,k=1;j<i;j++,k++)
{
info[j].mingci=k;
printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
}
getch();
fclose(fp);
}
void xiugai()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xiugai xuehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
} fwrite(&data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp);
}
fclose(fp);
fclose(fp1);
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xuehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao);
if(i==j)
{
printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
}getch();
}
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(0);
}
printf("\nPlease input ID which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("Anykey will delet it.\n");
getch();
continue;
}
fwrite(&data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
}
main()
{
while(1)
{
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移动光标*/
textcolor(YELLOW); /*设置文本显示颜色为黄色*/
textbackground(BLUE); /*设置背景颜色为蓝色*/
window(1,1,99,99); /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr();
printf("*************welcome to use student manage******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1>shuru 2>xiugai * \n");
printf("* 3>shanchu 4>chazhao * \n");
printf("* 5>xianshi 6>exit * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
{
case '1':shuru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':xianshi(); break;
case '6':exit(0);
default: continue;
}
}
}
在tc中运行
㈡ 跪求mfc的学生成绩管理系统,简单的增删改查就行,数据库是ACCESS,小弟就20财富,全给大家了.
给你传了一个压缩的,里面有两个系统都是,有一个csdn程序员网站 要注册 那里有很多!以后可以自己找了!
㈢ C程序班级成绩管理系统
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define t 100
void fun(struct student *s);
void fun1(struct student *s);
void fun2(struct student *s);
void fun3(struct student *s);
void fun4(struct student *s);
void fun5(struct student *s);
void fun6(struct student *s);
struct student
{
char no[20];
char name[20];
char spec[20];
int grade;
char sex[20];
};
void main()
{
struct student s[t]=,
,
,
,
};
fun(s);
}
void fun(struct student *s)
{
int n;
printf("\n\n\t\t学生档案管理系统");
printf("\n\n\t----------------------------------------");
printf("\n\n\t\t1:录入学生信息系统");
printf("\n\n\t\t2:修改学生信息系统");
printf("\n\n\t\t3:删除学生信息系统");
printf("\n\n\t\t4:查询学生信息系统");
printf("\n\n\t\t5:输出学生信息系统");
printf("\n\n\t\t6:退出系统");
printf("\n\n\t----------------------------------------");
printf("\n\n请选择你要的服务(按数字1~6进入):");
scanf("%d",&n);
system("cls");
if(n==1)
{
printf("\n\n\t\t欢迎进入录入学生系统");
fun1(s);
}
else if(n==2)
{
printf("\n\n\t\t欢迎进入修改学生系统");
fun5(s);
}
else if(n==3)
{
printf("\n\n\t\t欢迎进入删除学生系统");
fun6(s);
}
else if(n==4)
{
printf("\n\n\t\t欢迎进入查询学生系统");
printf("\n\n\t----------------------------------------");
printf("\n\n\t\t1:按学号查询学生信息系统");
printf("\n\n\t\t2:按班级查询学生信息系统");
printf("\n\n\t----------------------------------------");
printf("\n\n请选择你要的服务(按数字1~2进入):");
scanf("%d",&n);
system("cls");
if(n==1)
{
printf("\n\n\t\t1:按学号查询学生信息系统");
fun2(s);
}
else if(n==2)
{
printf("\n\n\t\t1:按班级查询学生信息系统");
fun3(s);
}
else
{
printf("\n\n\t\t数据错误");
}
}
else if(n==5)
{
printf("\n\n\t\t欢迎进入输出学生系统");
fun4(s);
} else if(n==6)
{
printf("\n\n\t\t谢谢使用学生管理系统!\n");
printf("\n\n\t\t请双击Enter键退出系统:");
getchar();
getchar();
exit(0);
}
else
printf("\n\n\t\t数据错误");
}
void fun1(struct student *s)
{
int n,i;
char d;
printf("\n\n\t请输入学生的数量:");
scanf("%d",&n);
for(i=5;i<n+5;i++)
{
printf("\n\t\t请输入学生学号:");
scanf("%s",s[i].no);
printf("\n\t\t请输入学生姓名:");
scanf("%s",s[i].name);
printf("\n\t\t请输入学生专业:");
scanf("%s",s[i].spec);
printf("\n\t\t请输入学生年级:");
scanf("%d",&s[i].grade);
printf("\n\t\t请输入学生性别:");
scanf("%s",s[i].sex);
getchar('\n');
system("cls");
}
printf("\n\n\t\t学号\t姓名\t专业\t年级\t性别");
printf("\n\t---------------------------------------------------");
for(i=0;i<n+5;i++)
{
printf("\n\n\t\t%-8s%-8s%-8s%-8d%-8s",s[i].no,s[i].name,s[i].spec,s[i].grade,s[i].sex);
}
printf("\n\t---------------------------------------------------\n");
printf("返回首页(请按任意键):");
scanf("%c",&d);
system("cls");
fun(s);
}
void fun2(struct student *s)
{
char a[20],d;
int i;
printf("\n\n\t请输入要查询学生的学号(10001~10005):");
scanf("%s",a);
for(i=0;i<5;i++)
{
if(!strcmp(s[i].no,a))
{
printf("\n\t此学生的信息:");
printf("\n\n\t\t学号\t姓名\t专业\t年级\t性别");
printf("\n\t---------------------------------------------------");
printf("\n\n\t\t%-8s%-8s%-8s%-8d%-8s\n",s[i].no,s[i].name,s[i].spec,s[i].grade,s[i].sex);
printf("\n\t---------------------------------------------------");
}
if(i==4&&s[i].no!="10005")
{
printf("\n\t\t查无此人!");
}
}
printf("\n\n返回首页(请按任意键):");
getchar();
scanf("%c",&d);
system("cls");
fun(s);
}
void fun3(struct student *s)
{
int i,a;
char d;
printf("\n\n\t请输入要查询学生的班级(12~14):");
scanf("%d",&a);
for(i=0;i<5;i++)
{
if(a==s[i].grade)
{
printf("\n\t此学生的信息:");
printf("\n\n\t\t学号\t姓名\t专业\t年级\t性别");
printf("\n\t---------------------------------------------------");
printf("\n\n\t\t%-8s%-8s%-8s%-8d%-8s\n",s[i].no,s[i].name,s[i].spec,s[i].grade,s[i].sex);
printf("\n\t---------------------------------------------------");
}
if(i==4&&s[i].grade!=a)
{
printf("\n\t\t查无此人!");
}
}
printf("\n\n返回首页(请按任意键):");
getchar();
scanf("%c",&d);
system("cls");
fun(s);
}
void fun4(struct student *s)
{
int i;
char d;
printf("\n\n\t\t学号\t姓名\t专业\t年级\t性别");
printf("\n\t---------------------------------------------------");
for(i=0;i<5;i++)
{
printf("\n\n\t\t%-8s%-8s%-8s%-8d%-8s",s[i].no,s[i].name,s[i].spec,s[i].grade,s[i].sex);
}
printf("\n\t---------------------------------------------------\n");
printf("返回首页(请按任意键):");
scanf("%c",&d);
getchar();
system("cls");
fun(s);
}
void fun5(struct student *s)
{
char a[20],d;
int i;
printf("\n\n\t请输入要修改学生的姓名:");
scanf("%s",a);
for(i=0;i<5;i++)
{
if(!strcmp(s[i].name,a))
{ printf("\n\t\t请输入修改学号:");
scanf("%s",s[i].no);
printf("\n\t\t请输入修改专业:");
scanf("%s",s[i].spec);
printf("\n\t\t请输入修改年级:");
scanf("%d",&s[i].grade);
printf("\n\t\t请输入修改性别:");
scanf("%s",s[i].sex);
getchar('\n');
system("cls");
}
}
printf("\n\n\t\t学号\t姓名\t专业\t年级\t性别");
printf("\n\t---------------------------------------------------");
for(i=0;i<5;i++)
{
printf("\n\n\t\t%-8s%-8s%-8s%-8d%-8s",s[i].no,s[i].name,s[i].spec,s[i].grade,s[i].sex);
}
printf("\n\t---------------------------------------------------\n");
printf("返回首页(请按任意键):");
scanf("%c",&d);
system("cls");
fun(s);
}
void fun6(struct student *s)
{
char a[20],d;
int i,k;
printf("\n\n\t请输入要删除学生的姓名:");
scanf("%s",a);
for(i=0;i<5;i++)
{
if(!strcmp(s[i].name,a))
{
s[i]=s[i+1];
printf("\n\t此学生的信息:");
printf("\n\n\t\t学号\t姓名\t专业\t年级\t性别");
printf("\n\t---------------------------------------------------");
for(k=0;k<4;k++)
{
printf("\n\n\t\t%-8s%-8s%-8s%-8d%-8s\n",s[k].no,s[k].name,s[k].spec,s[k].grade,s[k].se
㈣ 学生成绩管理系统c
#include "stdio.h"
#include<conio.h>
#include<string.h>
#include<stdlib.h>
struct book{
char number[21];
char shuming[30];
int shuliang;
int jiage;
char zhuanye[20];
char zuozhe[26];
char chubanshe[20];
char beizhu[100];
struct book *next;
};
struct book *creat() /*创建链表*/
{
struct book *p,*head,*end;
head=end=p=(struct book *)malloc(sizeof(struct book));
printf("输入教材编号为0结束输入,每项信息都必须输入内容。\n");
do
{
printf("\n教材编号:");
gets(p->number);
if(strcmp(p->number,"0")==0){ end->next=NULL; return head;}
end=p;
printf("\n教材名称:");
gets(p->shuming);
printf("\n教材数量:");
scanf("%d",&p->shuliang);
printf("\n教材价格:");
scanf("%d",&p->jiage);
getchar();
printf("\n教材专业:");
gets(p->zhuanye);
printf("\n教材作者:");
gets(p->zuozhe);
printf("\n教材出版社:");
gets(p->chubanshe);
printf("\n备注:");
gets(p->beizhu);
p=(struct book *)malloc(sizeof(struct book));
end->next=p;
}while(1);
}
void save(struct book *head) /*保存链表*/
{FILE *fp;
struct book *p;
char filename[30];
int ch;
printf("请输入“文件名.后缀”:");
scanf("%s",filename);
if((fp=fopen(filename,"r"))!=NULL)
{
printf("\n该文件已存在,是否覆盖?1,是 2,否");
scanf("%d",&ch);
if(ch!=1)
return;
}
if((fp=fopen(filename,"w"))==NULL) { printf("\n文件保存失败");getchar();return;}
p=head;
do{
fprintf(fp,"\n%s",p->number);
fprintf(fp,"\n%s",p->shuming);;
fprintf(fp,"\n%d",p->shuliang);
fprintf(fp,"\n%d",p->jiage);
fprintf(fp,"\n%s",p->zhuanye);
fprintf(fp,"\n%s",p->zuozhe);
fprintf(fp,"\n%s",p->chubanshe);
fprintf(fp,"\n%s",p->beizhu);
p=p->next;
}while(p!=NULL);
fprintf(fp," over");
printf("\n成功保存");
getchar();
getchar();
fclose(fp);
}
void print(struct book *head) /*输出链表*/
{
struct book *p;
p=head;
if(p==NULL) { printf("未打开任何文件,无法显示"); getch();return;}
do{
printf("\n\n教材编号:%s",p->number);
printf("\n教材名称:%s",p->shuming);;
printf("\n数量:%d",p->shuliang);
printf("\n价格:%d",p->jiage);
printf("\n专业:%s",p->zhuanye);
printf("\n作者:%s",p->zuozhe);
printf("\n出版社:%s",p->chubanshe);
printf("\n备注:%s",p->beizhu);
p=p->next;
}while(p!=NULL);
}
struct book *openfile() /*打开文件*/
{struct book *p,*f,*head;
FILE *fp;
char filename[20];
printf("\n请输入路径,文件名,和后缀):");
scanf("%s",filename);
if((fp=fopen(filename,"r"))==NULL){ printf("\n文件找不到,请检查是否有该文件和路径是否正确");getchar();return NULL;}
head=f=p=(struct book *)malloc(sizeof(struct book));
fscanf(fp,"%s%s%d%d%s%s%s%s",p->number,p->shuming,&p->shuliang,&p->jiage,p->zhuanye,p->zuozhe,p->chubanshe,p->beizhu);
while(!feof(fp))
{ p=(struct book *)malloc(sizeof(struct book));
f->next=p;
fscanf(fp,"%s%s%d%d%s%s%s%s",p->number,p->shuming,&p->shuliang,&p->jiage,p->zhuanye,p->zuozhe,p->chubanshe,p->beizhu);
if(strcmp(p->number,"over")==0){ f->next=NULL; printf("\n文件打开成功,可以显示此信息");getchar(); return head; }
f=p;
}
return head;
}
void namesort(struct book *head) /*按教材名称排序*/
{ struct book *p,*t,*f,*h;
char ch[20];
int i;
h=t=f=p=head;
if(head==NULL) {printf("未打开任何文件");getchar();return; };
f=p->next;
for(p=head;p->next!=NULL;p=p->next)
{
for(t=head,f=t->next;t->next!=NULL;f=f->next,t=t->next)
{
if(strcmp(t->shuming,f->shuming)>0)
{
strcpy(ch,t->number );
strcpy(t->number,f->number);
strcpy(f->number,ch);
strcpy(ch,t->shuming );
strcpy(t->shuming,f->shuming);
strcpy(f->shuming,ch);
i=t->shuliang ;
t->shuliang=f->shuliang;
f->shuliang=i;
i=t->jiage ;
t->jiage=f->jiage;
f->jiage=i;
strcpy(ch,t->zhuanye);
strcpy(t->zhuanye,f->zhuanye);
strcpy(f->zhuanye,ch);
strcpy(ch,t->zuozhe);
strcpy(t->zuozhe,f->zuozhe);
strcpy(f->zuozhe,ch);
strcpy(ch,t->chubanshe);
strcpy(t->chubanshe,f->chubanshe);
strcpy(f->chubanshe,ch);
strcpy(ch,t->beizhu);
strcpy(t->beizhu,f->beizhu);
strcpy(f->beizhu,ch);
}
}
}
print(h);
}
void chubanshesort(struct book *head) /*按出版社排序*/
{ struct book *p,*t,*f,*h;
char ch[20];
int i;
h=t=f=p=head;
if(head==NULL) {printf("未打开任何文件");getchar();return; }
f=p->next;
for(p=head;p->next!=NULL;p=p->next)
{
for(t=head,f=t->next;t->next!=NULL;f=f->next,t=t->next)
{
if(strcmp(t->chubanshe,f->chubanshe)>0)
{
strcpy(ch,t->number );
strcpy(t->number,f->number);
strcpy(f->number,ch);
strcpy(ch,t->shuming );
strcpy(t->shuming,f->shuming);
strcpy(f->shuming,ch);
i=t->shuliang ;
t->shuliang=f->shuliang;
f->shuliang=i;
i=t->jiage ;
t->jiage=f->jiage;
f->jiage=i;
strcpy(ch,t->zhuanye);
strcpy(t->zhuanye,f->zhuanye);
strcpy(f->zhuanye,ch);
strcpy(ch,t->zuozhe);
strcpy(t->zuozhe,f->zuozhe);
strcpy(f->zuozhe,ch);
strcpy(ch,t->chubanshe);
strcpy(t->chubanshe,f->chubanshe);
strcpy(f->chubanshe,ch);
strcpy(ch,t->beizhu);
strcpy(t->beizhu,f->beizhu);
strcpy(f->beizhu,ch);
}
}
}
print(h);
}
void shumingsearch(struct book *head) /*按教材名称查找*/
{ struct book *p;
char name[20];
int c;
if(head==NULL) {printf("未打开任何文件");getchar();return;}
printf("1,查找专业 2,查找教材名称:");
scanf("%d",&c);
getchar();
if(c==2)
printf("请输入要查找的教材名称:");
else printf("请输入要查找的专业:");
gets(name);
p=head;
do{ if(c==2)
if(strcmp(p->shuming,name)==0)
{
printf("教材编号:%s\n教材名称:%s\n数量:%d\n价格:%d\n专业:%s\n作者:%s\n出版社:%s\n备注:%s\n",p->number,p->shuming,p->shuliang,p->jiage,p->zhuanye,p->zuozhe,p->chubanshe,p->beizhu);
}
if(c==1)
if(strcmp(p->zhuanye,name)==0)
{
printf("教材编号:%s\n教材名称:%s\n数量:%d\n价格:%d\n专业:%s\n作者:%s\n出版社:%s\n备注:%s\n",p->number,p->shuming,p->shuliang,p->jiage,p->zhuanye,p->zuozhe,p->chubanshe,p->beizhu);
}
p=p->next;
}while(p!=NULL);
printf("查找完成");
return;
}
struct book *add(struct book *head) /*增加记录*/
{ struct book *p,*e,*f,*h;
if(head==NULL) {printf("未打开任何文件");getchar(); return NULL;}
h=f=e=head;
p=(struct book *)malloc(sizeof(struct book));
printf("\n教材编号:");
gets(p->number);
printf("\n教材名称:");
gets(p->shuming);
printf("\n数量:");
scanf("%d",&p->shuliang);
printf("\n价格:");
scanf("%d",&p->jiage);
getchar();
printf("\n专业:");
gets(p->zhuanye);
printf("\n作者:");
gets(p->zuozhe);
printf("\n出版社:");
gets(p->chubanshe);
printf("\n备注:");
gets(p->beizhu);
if(strcmp(f->number,p->number)>0) { p->next=f;h=p;printf("\n添加成功");return h;}
if(f->next==NULL) { f->next=p;p->next=NULL;printf("\n添加成功");return h;}
do{
if(f->next!=NULL)
if(strcmp(f->number,p->number)>0)
{
e->next=p;p->next=f;printf("\n添加成功");return h;
}
if(f->next==NULL)
{
f->next=p;
p->next=NULL;
printf("\n添加成功");
return h;
}
f=f->next;
e=e->next;
}while(1);
}
struct book *delet(struct book *head) /*删除记录*/
{ struct book *p,*e;
char num[20];
if(head==NULL) {printf("未打开任何文件");getchar();return NULL;}
printf("请输入要删除的教材编号:");
scanf("%s",num);
p=e=head;
if(strcmp(p->number,num)==0) { head=head->next; print(head);return head;}
else p=p->next;
do{
if(strcmp(p->number,num)==0)
{
if(p->next!=NULL)
e->next=p->next;
if(p->next==NULL) e->next=NULL;
print(head);
return head;
}
p=p->next;
e=e->next;
}while(p!=NULL);
printf("搜索完毕,未找到该记录");
return head;
}
struct book *change(struct book *head) /*修改记录*/
{ struct book *p;
char num[20];
if(head==NULL) {printf("未打开任何文件");getchar();return NULL;}
printf("请输入要修改的教材编号:");
scanf("%s",num);
getchar();
p=head;
do{
if(strcmp(p->number,num)==0)
{
printf("教材编号:%s\n教材名称:%s\n数量:%d\n价格:%d\n专业:%s\n作者:%s\n出版社:%s\n备注:%s\n",p->number,p->shuming,p->shuliang,p->jiage,p->zhuanye,p->zuozhe,p->chubanshe,p->beizhu);
printf("\n教材编号:");
gets(p->number);
printf("\n教材名称:");
gets(p->shuming);
printf("\n数量:");
scanf("%d",&p->shuliang);
printf("\n价格:");
scanf("%d",&p->jiage);
getchar();
printf("\n专业:");
gets(p->zhuanye);
printf("\n作者:");
gets(p->zuozhe);
printf("\n出版社:");
gets(p->chubanshe);
printf("\n备注:");
gets(p->beizhu);
printf("修改成功");
return head;
}
p=p->next;
}while(p!=NULL);
printf("未找到要修改的记录");
return head;
}
int mima()
{ FILE *fp;
char mima1[20],mima2[20];
if((fp=fopen("mima","r"))==NULL)
{ printf("尚未设置密码请输入:");
scanf("%s",mima1);
printf("请再次输入密码:");
scanf("%s",mima2);
if(strcmp(mima1,mima2)!=0) { printf("两次密码不一样");return 0;}
else {
fp=fopen("mima","w");
fprintf(fp,"%s",mima1);
printf("密码设置成功");
return 1;
}
}
printf("请输入初始化密码:");
scanf("%s",mima1);
fscanf(fp,"%s",mima2);
if(strcmp(mima1,mima2)==0)
{
printf("密码正确");
printf("请输入要删除的文件名:");
scanf("%s",mima1);
if(remove(mima1)==0)
{
printf("删除成功");
getchar();
return 1;
}
else {
printf("删除失败,请检查是否存在该文件或路径是否正确");
getchar();
return 0;
}
}
else {
printf("密码错误");
getchar();
return 0;
}
}
void main()
{
struct book *head=NULL;
char i;
printf(" 88888888888 \n");
printf(" d88888888888b \n");
printf(" d88888 88888b \n");
printf(" d88P 88b \n");
printf(" 888' `88b \n");
printf(" 88P Y88 \n");
printf(" 88 88\n");
printf(" 88 88\n");
printf(" 88 88\n");
printf(" 88 88\n");
printf(" 88 88\n");
printf(" 88 ,aa. ,aa. 88 \n");
printf(" 88 d88b d88b 88 \n");
printf(" ,=88 Y88P Y88P 88=, \n");
printf(" ,d88P' `' _aa_ `' `Y88b, \n");
printf(" 88P' (8888) `Y88 ad88888b \n");
printf(" 88 ~^^~ 88 d88Y Y8b\n");
printf(" Yb._ _.d8 d8Y 88\n");
printf(" d88888888ba888=,. .,=8888 d88 88 \n");
printf(" ★☆88P Y88~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~★☆\n");
printf(" ★☆ 88 88 ★☆\n");
printf(" ★☆88 88 欢迎使用本教材系统,按任意键进入系统 ★☆\n");
printf(" ★☆ 8b,___,d8 ★☆\n");
printf(" ★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆\n");
getch();
system("cls");
do{
printf(" ☆★☆★☆★ 教材管理系统 ☆★☆★☆★\n");
printf("m--菜单 h--帮助");
printf("\n请输入命令:");
i=getch();
if(i=='h')
{ printf("\n1,录入教材信息的时候,每一个项目都必须输入相应的内容。\n2,修改,增加,删除,查找记录前必须先打开一个文件,修改完后必须记得保存教材信息。\n3,必须使用正确的路径打开文件,建议保存文件时候不用输入路径(此时是默认路径,即保存在程序目录下。)");
getch();
break;
}
if(i=='m')
break;
system("cls");
}while(i!='m'||i!='h');
system("cls");
do{
printf(" ☆★☆★☆★ 教材管理系统 ☆★☆★☆★\n");
printf("┌————-———┐\n");
printf("│1,录入教材信息│\n│2,显示教材信息│\n│3,打开一个记录│\n│4,编辑一个记录│\n│5,保存教材信息│\n│6,查找记录 │\n│s,初始化系统 │\n│e,退出系统 │\n");
printf("└———————-┘\n");
printf("\n请输入功能编号:");
i=getch();
system("cls");
switch(i)
{
case '1': head=creat();save(head);break;
case '2': print(head);break;
case '3': head=openfile();break;
case '4': system("cls");
printf("┌————-———┐\n");
printf("│1,增加一个记录│\n");
printf("│2,删除一个记录│\n");
printf("│3,修改一个记录│\n");
printf("└———————-┘\n");
i=getch();
switch(i)
{
case '1':
head=add(head);break;
case '2':
head=delet(head);break;
case '3': head=change(head);break;
default: break;
}
break;
case '5': save(head);break;
case '6': shumingsearch(head);break;
case 's': mima();break;
case 'e': exit(0);
default :break;
}
system("cls");
}while(1);
}
我想这个程序包含了你那个成绩管理系统的全部要求,但我这个是教材管理系统我想改一下就可以了,具体如何改就要看楼主的天赋咯,呵呵。参考一下吧
㈤ 求用C++编写简单的学生成绩管理系统!!!~~~
发给你了
㈥ 假设收集到了一个班学生的所有成绩信息(不低于20人),要求用C语言编写一个简单的成绩管理系统
代码已发,在附件,邮件名“代码”,附件Untitled2.c
如果有疑问欢迎追问。
代码如下:
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<math.h>
#define min(A,B) (A<B?A:B)
#define max(A,B) (A<B?B:A)
typedef struct Student
{
long long int id;
char name[11];
int score[4];
double avg;
struct Student* next;
} Student;
void print(Student* stu)
{
printf("学号:%10lld 姓名:%10s 成绩:语文:%3d 数学:%3d 英语:%3d 计算机:%3d 平均分:%3.2lf ",
stu->id,stu->name,stu->score[0],stu->score[1],stu->score[2],stu->score[3],stu->avg);
}
int main(void)
{
Student* head = 0;
int stucount=0;//数量
while(1)
{
printf("输入操作号:1:录入学生 2:浏览 3:查询 4:修改 5:排序 6:统计 ");
int quest;
scanf("%d",&quest);
scanf("%*[^ ]");
if(quest==1)
{
printf("录入学生: ") ;
while(1)
{
printf("请输入学生学号(-1退出录入): ");
long long int id;
scanf("%lld", &id);
if(id==-1)break;
Student* newStudent = (Student*)malloc(sizeof(Student));
newStudent->id=id;
printf("请输入学生名字: ");
scanf("%10s", newStudent->name);
scanf("%*[^ ]");
printf("请输入学生语文成绩: ");
scanf("%d",&(newStudent->score[0]));
printf("请输入学生数学成绩: ");
scanf("%d",&(newStudent->score[1]));
printf("请输入学生英语成绩: ");
scanf("%d",&(newStudent->score[2]));
printf("请输入学生计算机成绩: ");
scanf("%d",&(newStudent->score[3]));
int sum=0;
for(int i=0; i<4; ++i)sum+=newStudent->score[i];
newStudent->avg = sum/4.0;
printf("学生已录入!平均分为:%lf ",newStudent->avg);
//插入链表首,这样最新添加的显示在最上面,容易看见效果
newStudent->next=head;
head=newStudent;
++stucount;
}
}
else if(quest==2)
{
if(head==0)
printf("没有学生! ");
else
{
printf("开始浏览学生: ");
int st=0,en=min(st+10,stucount);
while(1)
{
printf("浏览学生:%d个到%d个学生 ",st+1,en);
Student* stu = head;
for(int i=0; i<st; ++i)
{
stu=stu->next;
}
for(int i=st; i<en; ++i)
{
print(stu);
stu=stu->next;
}
printf("输入操作号:1 向后翻页;2 向前翻页;-1 退出 ");
int squest;
scanf("%d",&squest);
scanf("%*[^ ]");
if(squest==1)
{
if(en!=stucount) st=en;
}
else if(squest==2)
{
st=max(0,st-10);
}
else if(squest==-1)break;
en=min(st+10,stucount);
}
}
}
else if(quest==3)
{
printf("开始查询学生信息: ");
while(1)
{
printf("通过什么查询?1:学生id 2:学生名字 3:学生语文成绩 4:学生数学成绩 5:学生英语成绩 6:学生计算机成绩 7:平均分 -1 退出 ");
int squery,squery2;
scanf("%d", &squery);
if(squery==-1)break;
Student temp;
Student* newStudent = &temp;
if(squery==1)
{
printf("请输入学生id: ");
scanf("%lld", &(newStudent->id));
}
else if(squery==2)
{
printf("请输入学生名字: ");
scanf("%10s", newStudent->name);
scanf("%*[^ ]");
}
else if(squery==3)
{
printf("请输入学生语文成绩: ");
scanf("%d",&(newStudent->score[0]));
}
else if(squery==4)
{
printf("请输入学生数学成绩: ");
scanf("%d",&(newStudent->score[1]));
}
else if(squery==5)
{
printf("请输入学生英语成绩: ");
scanf("%d",&(newStudent->score[2]));
}
else if(squery==6)
{
printf("请输入学生计算机成绩: ");
scanf("%d",&(newStudent->score[3]));
}
else if(squery==7)
{
printf("请输入学生平均分: ");
scanf("%lf",&(newStudent->avg));
}
if(squery>=3 && squery<=7)
{
printf("显示比此分数高还是低的学生?1:低 2:高 ");
scanf("%d",&squery2);
}
Student* stu = head;
int flag=0;
while(stu!=0)
{
if(squery==1)
{
if(newStudent->id==stu->id)
{
print(stu);
flag=1;
}
}
else if(squery==2)
{
if(strcmp(newStudent->name,stu->name)==0)
{
print(stu);
flag=1;
}
}
else if(squery==7)
{
if((newStudent->avg!=stu->avg) && ((newStudent->avg>stu->avg) ^ (squery2==2)))
{
print(stu);
flag=1;
}
}
else if(squery>2 && squery<7)
{
if((newStudent->score[squery-3]!=stu->score[squery-3]) && ((newStudent->score[squery-3]>stu->score[squery-3]) ^ (squery2==2)))
{
print(stu);
flag=1;
}
}
stu=stu->next;
}
if(flag==0)
{
printf("没有查到学生! ");
continue;
}
}
}
else if(quest==4)
{
printf("开始修改学生信息: ");
while(1)
{
printf("请输入学生学号(-1退出修改): ");
long long int id;
scanf("%lld", &id);
if(id==-1)break;
Student* newStudent = head;
Student* lststu = 0;
while(newStudent!=0 && newStudent->id!=id)
{
lststu=newStudent;
newStudent=newStudent->next;
}
if(newStudent==0)
{
printf("没有查到学生! ");
continue;
}
printf("请输入操作号:1:修改学生名字 2:修改学生语文成绩 3:修改学生数学成绩 4:修改学生英语成绩 5:修改学生计算机成绩 6:删除学生 ");
int squery;
scanf("%d", &squery);
if(squery==1)
{
printf("请输入学生名字: ");
scanf("%10s", newStudent->name);
scanf("%*[^ ]");
}
else if(squery==2)
{
printf("请输入学生语文成绩: ");
scanf("%d",&(newStudent->score[0]));
}
else if(squery==3)
{
printf("请输入学生数学成绩: ");
scanf("%d",&(newStudent->score[1]));
}
else if(squery==4)
{
printf("请输入学生英语成绩: ");
scanf("%d",&(newStudent->score[2]));
}
else if(squery==5)
{
printf("请输入学生计算机成绩: ");
scanf("%d",&(newStudent->score[3]));
}
else if(squery==6)
{
stucount--;
if(lststu!=0)
lststu -> next = newStudent -> next;
else
head = newStudent -> next;
printf("已删除学生! ");
}
if(squery!=6)
{
int sum=0;
for(int i=0; i<4; ++i)sum+=newStudent->score[i];
newStudent->avg = sum/4.0;
printf("学生已修改!他的平均分为:%lf ",newStudent->avg);
}
}
}
else if(quest==5)
{
if(head==0)
printf("没有学生! ");
else
{
printf("对学生按什么排序?:1:学生号 2:名字 3:语文成绩 4:数学成绩 5:修改学生英语成绩 5:计算机成绩 6:平均分 ");
int squery;
scanf("%d", &squery);
printf("升序还是降序? 1:升序 2:降序 ");
int squery2;
scanf("%d", &squery2);
int flag=1;
Student* stu = head;
Student* lststu = 0;
while(flag==1)
{
flag=0;
while(stu->next!=0)
{
int swflag=0;
if(squery==0)
{
if((stu->next->id > stu->id) ^ (squery2==1))swflag=1;
}
else if(squery==1)
{
if((strcmp(stu->next->name,stu->name)>0) ^ (squery2==1))swflag=1;
}
else if(squery==6)
{
if((stu->next->avg > stu->avg) ^ (squery2==1))swflag=1;
}
if(swflag==1)
{
flag=1;
if(lststu==0) head=stu->next;
else lststu->next=stu->next;
Student* temp = stu->next->next;
stu->next->next=stu;
stu->next=temp;
}
lststu=stu;
stu=stu->next;
}
}
printf("已排序! ");
}
}
else if(quest==6)
{
double totscore[4]= {0};
double sum=0;
Student* stu=head;
while(stu!=0)
{
for(int i=0; i<4; ++i)
{
totscore[i]+=stu->score[i];
sum+=stu->avg;
}
}
for(int i=0; i<4; ++i) totscore[i]=totscore[i]/4.0;
sum=sum/4.0;
printf("统计:学生人数:%d 语文平均分:%lf 数学平均分:%lf 英语平均分:%lf 计算机平均分:%lf 总平均分:%lf ",stucount,totscore[0],totscore[1],totscore[2],totscore[3],sum);
}
else if(quest==-1)
break;
}
return 0;
}
㈦ 学生成绩管理
#include<iostream.h>
#include<string.h>
#include<fstream.h>
class stu
{
char name[20];
double math,chinese,english,average,sum;
public:
stu()
{
}
stu(char n[20],double ma,double chin,double eng)
{
strcpy(name,n);
math=ma;
chinese=chin;
english=eng;
}
double getsum()
{
sum=chinese+english+math;
return sum;
}
double getaver()
{
average=getsum()/3;
return average;
}
friend void main();
};
void main()
{
cout<<"请选择您需要的操作!"<<endl;
cout<<"操作:"<<endl;
cout<<"(0)数据录入"<<endl;
cout<<"(1)增加人员"<<endl;
cout<<"(2)删除人员"<<endl;
cout<<"(3)修改数据"<<endl;
cout<<"查询:"<<endl;
cout<<"(4)按总成绩查询"<<endl;
cout<<"(5)按姓名查询"<<endl;
cout<<"(6)输出所有学生的数据"<<endl;
cout<<"成绩名词"<<endl;
cout<<"(7)按总分查询排名"<<endl;
cout<<"(8)按语文查询排名"<<endl;
cout<<"(9)按数学查询排名"<<endl;
cout<<"(y)按英语查询排名"<<endl;
cout<<"选择相关操作请输入相对的括号里的阿拉伯数字!"<<endl;
char p;char w;
stu *s[50];
ofstream *file[50];
int i=0;
int j=0;
bool flag2=0;
do
{
cin>>p;
if((p>='0'&&p<='10'))
flag2=1;
else
cout<<"指令错误!请重新输入:"<<endl;
}while(flag2==0);
do{
switch(p)
{
case '0':
{
char c;
char name[20];double math,chinese,english;
do{
cout<<"请输入姓名"<<endl;
cin>>name;
cout<<"请输入数学成绩:"<<endl;
cin>>math;
cout<<"请输入语文成绩:"<<endl;
cin>>chinese;
cout<<"请输入外语成绩:"<<endl;
cin>>english;
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<<name<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
j++;
s[i]=new stu(name, math, chinese, english);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
flag2=0;
do
{
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
else
flag2=1;
}while(flag2==0);
}while(c=='y');
break;
}
case '4':
{
double t;char c;
do
{
int flag1=0;
cout<<"请输入你要查询学生的总成绩"<<endl;
cin>>t;
for(int q=0;q<i;q++)
{
if(s[q]->getsum()==t)
{
flag1=1;
cout<<"您要查询的学生是:"<<(*s[q]).name<<endl;
}
}
if(flag1==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '5':
{
char n[20];int j=0;char c;
do{
int flag=0;
cout<<"请输入你要查询的学生姓名"<<endl;
cin>>n;
for(int j=0;j<i;j++)
{
if(strcmp(n,(*s[j]).name)==0)
{
flag=1;
cout<<"您要查询的学生是:"<<(*s[j]).name<<endl;
cout<<(*s[j]).name<<"的总成绩成绩是"<<(*s[j]).getsum()<<endl<<"平均成绩是:"<<(*s[j]).getaver()<<endl;
}
}
if(flag==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '1':
{
char name[20];double math,chinese,english;
char c;
do
{
cout<<"请输入您要增加的学生的姓名:"<<endl;
cin>>name;
cout<<"请输入数学成绩:"<<endl;
cin>>math;
cout<<"请输入语文成绩:"<<endl;
cin>>chinese;
cout<<"请输入外语成绩:"<<endl;
cin>>english;
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<<name<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
j++;
s[i]=new stu(name, math, chinese, english);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '2':
{
char name[20];bool flag3=0;char c;
do{
cout<<"请输入您要删除的学生姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,s[h]->name)==0)
{
flag3=1;
i--;
do{
s[h]=s[h+1];
h++;
}while(h<=i);
}
}
if(flag3==0)
cout<<"您要求删除的对象本来就不存在!请检查输入的正确性!";
cout<<"要继续删除吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '3':
{
char name[20];double mat,chin,eng;flag2=0;
char c;
do
{
cout<<"请输入您要修改的学生的姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,s[h]->name)==0)
{
flag2=1;
cout<<"请输入新的数学成绩:"<<endl;
cin>>mat;
cout<<"请输入新的语文成绩:"<<endl;
cin>>chin;
cout<<"请输入新的外语成绩:"<<endl;
cin>>eng;
s[h]->chinese=chin;
s[h]->math=mat;
s[h]->english=eng;
cout<<"数据修改成功!";
}
}
if(flag2==0)
{
cout<<"您要修改的学生本来就不存在!请检查重新输入!"<<endl;
}
cout<<"想继续修改吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '6':
{
cout<<"本系统所有学生数据如下:"<<endl;
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!"<<endl;
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<
"语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<(*s[k]).getsum()
<<"平均分:"<<" "<<(*s[k]).getaver()<<endl;
}
break;
}
case '7':
{
int t;stu b;
cout<<"本系统所以学生排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->getsum())<(s[y]->getsum()))
t=y;
if(t!=x)
{
b=*s[x];
*s[x]=*s[t];
*s[t]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<
"语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()<<endl;
}
break;
}
case '8':
{
int t;stu b;
cout<<"本系统所以学生语文排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->chinese)<(s[y]->chinese))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<
"语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()<<endl;
}
break;
}
case '9':
{
int t;stu b;
cout<<"本系统所以学生数学排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->math)<(s[y]->math))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<
"语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()<<endl;
}
break;
}
case 'y':
{
int t;stu b;
cout<<"本系统所以学生英语排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->english)<(s[y]->english))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<
"语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()<<endl;
}
}
break;
}
cout<<"您想继续进行其他操作吗?(y/n)"<<endl;
bool flag4=0;
do
{
cin>>w;
if(w!='y'&&w!='n')
cout<<"指令错误!请重新输入!"<<endl;
else
flag4=1;
}while(flag4==0);
if(w=='y')
cout<<"请输入操作代码(0 录入/4 按总分查询/5 按姓名查询/1 增加人员/2 删除人员/3 修改数据/6 显示所有成员数据/7 按总分排名/8 按语文排名/9按数学排名/y按英语排名)"<<endl;
cin>>p;
}while(w=='y');
for(int x=0;x<i;x++)
{
delete s[x];
cout<<"delete all members!"<<endl;
}
}
㈧ c++ 学生成绩管理系统
这是我刚改过的代码,还添加了求平均分的功能
#include<iostream.h>
#include<string.h>
#include<fstream.h>
class stu
{
char name[20];
int ba;
double math,number,chinese,english,average,sum;
public:
stu()
{
}
stu(char n[20],int ban,double nu,double ma,double chin,double eng)
{
strcpy(name,n);
ba=ban;
number=nu;
math=ma;
chinese=chin;
english=eng;
}
double getsum()
{
sum=chinese+english+math;
return sum;
}
double getaver()
{
average=getsum()/3;
return average;
}
friend void main();
};
void main()
{
cout<<"(0)数据录入 (1)增加人员"<<endl;
cout<<"(2)删除人员 (3)修改数据"<<endl;
cout<<"(4)按学号查询 (5)按姓名查询"<<endl;
cout<<"(6)输出所有学生的数据 (7)按总分查询排名"<<endl;
cout<<"(8)按语文查询排名 (9)按数学查询排名"<<endl;
cout<<"(y)按英语查询排名 "<<endl;
cout<<"选择相关操作请输入相对的括号里的阿拉伯数字或字母!"<<endl;
char p;char w;
stu *s[50];
ofstream *file[50];
int i=0;
int j=0;
bool flag2=0;
do
{
cin>>p;
if((p>='0'&&p<='9'))
flag2=1;
else
cout<<"指令错误!请重新输入:"<<endl;
}while(flag2==0);
do{
switch(p)
{
case '0':
{
char c;
char name[20];int ba ;double number, math,chinese,english;
do{
cout<<"请输入姓名"<<endl;
cin>>name;
cout<<"请输入班级:"<<endl;
cin>>ba;
cout<<"请输入您要增加的学生的学号:"<<endl;
cin>>number;
cout<<"请输入数学成绩:"<<endl;
cin>>math;
cout<<"请输入语文成绩:"<<endl;
cin>>chinese;
cout<<"请输入外语成绩:"<<endl;
cin>>english;
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<<name<<"班级"<<ba<<"学号"<<number<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
j++;
s[i]=new stu(name,ba,number, math, chinese, english);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
do
{
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
else
flag2=1;
}while(flag2==0);
}while(c=='y');
break;
}
case '1':
{
char name[20];int ba;double number,math,chinese,english;
char c;
do
{
cout<<"请输入您要增加的学生的姓名:"<<endl;
cin>>name;
cout<<"请输入要增加的学生的班级:"<<endl;
cin>>ba;
cout<<"请输入您要增加的学生的学号:"<<endl;
cin>>number;
cout<<"请输入数学成绩:"<<endl;
cin>>math;
cout<<"请输入语文成绩:"<<endl;
cin>>chinese;
cout<<"请输入外语成绩:"<<endl;
cin>>english;
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<<name<<"班级"<<ba<<"学号"<<number<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
j++;
s[i]=new stu(name, ba,number,math, chinese, english);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '2':
{
char name[20];bool flag3=0;char c;
do{
cout<<"请输入您要删除的学生姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,s[h]->name)==0)
{
flag3=1;
i--;
do{
s[h]=s[h+1];
h++;
}while(h<=i);
}
}
if(flag3==0)
cout<<"您要求删除的对象本来就不存在!请检查输入的正确性!";
cout<<"要继续删除吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '3':
{
char name[20];double mat,chin,eng;flag2=0;
char c;
do
{
cout<<"请输入您要修改的学生的姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,s[h]->name)==0)
{
flag2=1;
cout<<"请输入新的数学成绩:"<<endl;
cin>>mat;
cout<<"请输入新的语文成绩:"<<endl;
cin>>chin;
cout<<"请输入新的外语成绩:"<<endl;
cin>>eng;
s[h]->chinese=chin;
s[h]->math=mat;
s[h]->english=eng;
cout<<"数据修改成功!";
}
}
if(flag2==0)
{
cout<<"您要修改的学生本来就不存在!请检查重新输入!"<<endl;
}
cout<<"想继续修改吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '4':
{
double t;char c;
do
{
int flag1=0;
cout<<"请输入你要查询学生的学号"<<endl;
cin>>t;
for(int q=0;q<i;q++)
{
if(s[q]->number==t)
{
flag1=1;
cout<<"您要查询的学生是:"<<(*s[q]).name
<<"数学成绩为:"<<s[q]->math
<<"语文成绩为:"<<s[q]->chinese
<<"英语成绩为:"<<s[q]->english
<<"总分为:"<<s[q]->getsum()
<<endl;
}
}
if(flag1==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '5':
{
char n[20];int j=0;char c;
do{
int flag=0;
cout<<"请输入你要查询的学生姓名"<<endl;
cin>>n;
for(int j=0;j<i;j++)
{
if(strcmp(n,(*s[j]).name)==0)
{
flag=1;
cout<<"您要查询的学生是:"<<(*s[j]).name
<<endl;
cout<<(*s[j]).name<<"的总成绩成绩是"<<(*s[j]).getsum()
<<"班级:"<<" "<<s[j]->ba
<<"语文:"<<" "<<s[j]->chinese
<<"数学:"<<" "<<s[j]->math
<<"外语:"<<" "<<s[j]->english
<<"平均成绩是:"<<(*s[j]).getaver()
<<endl;
}
}
if(flag==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '6':
{
cout<<"本系统所有学生数据如下:"<<endl;
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!"<<endl;
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name
<<"班级"<<s[k]->ba
<<"学号"<<s[k]->number
<<"语文:"<<" "<<s[k]->chinese<<"数学:"
<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english
<<"总分:"<<" "<<(*s[k]).getsum()
<<"平均分:"<<" "<<(*s[k]).getaver()
<<endl;
}
break;
}
case '7':
{
int t;stu b;
cout<<"本系统所有学生总分排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->getsum())<(s[y]->getsum()))
t=y;
if(t!=x)
{
b=*s[x];
*s[x]=*s[t];
*s[t]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
double o1,o2;
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name
<<"班级"<<s[k]->ba
<<"学号"<<s[k]->number
<<"语文:"<<" "<<s[k]->chinese
<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english
<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()
<<endl;
o1=s[k]->sum;
o2=s[0]->sum;
}
cout<<"总分最高分"<<o2<<endl
<<"总分最低分"<<o1<<endl
<<endl;
break;
}
case '8':
{
int t;stu b;
cout<<"本系统所有学生语文排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->chinese)<(s[y]->chinese))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
double o1 ,o2;
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name
<<"班级"<<s[k]->ba
<<"学号"<<s[k]->number
<<"语文:"<<" "<<s[k]->chinese
<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english
<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()
<<endl;
o1=s[k]->chinese;
o2=s[0]->chinese;
}
int v1=0,v2=0;double v3;
for(v2=0;v2<=i-1;v2++)
{
if(s[v2]->english>=60)
v1++;
}
v3=(v1*100)/v2;
cout<<"语文最高分"<<o2<<endl
<<"语文最低分"<<o1<<endl
<<"语文及格率"<<v3<<"%"
<<endl;
break;
}
case '9':
{
int t;stu b;
cout<<"本系统所有学生数学排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->math)<(s[y]->math))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
double o1,o2;
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name
<<"班级"<<s[k]->ba
<<"学号"<<s[k]->number
<<"语文:"<<" "<<s[k]->chinese
<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english
<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()
<<endl;
o1=s[k]->math;
o2=s[0]->math;
}
int v1=0,v2=0;double v3;
for(v2=0;v2<=i-1;v2++)
{
if(s[v2]->english>=60)
v1++;
}
v3=(v1*100)/v2;
cout<<"数学最高分"<<o2<<endl
<<"数学最低分"<<o1<<endl
<<"数学及格率"<<v3<<"%"
<<endl;
break;
}
case 'y':
{
int t;stu b;
cout<<"本系统所有学生英语排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->english)<(s[y]->english))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
double o1,o2;
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name
<<"班级"<<s[k]->ba
<<"学号"<<s[k]->number
<< "语文:"<<" "<<s[k]->chinese
<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english
<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()
<<endl;
o1=s[k]->english;
o2=s[0]->english;
}
int v1=0,v2=0;double v3;
for(v2=0;v2<=i-1;v2++)
{
if(s[v2]->english>=60)
v1++;
}
v3=(v1*100)/v2;
cout<<"英语最高分"<<o2<<endl
<<"英语最低分"<<o1<<endl
<<"英语及格率"<<v3<<"%"
<<endl;
}
break;
}
cout<<"您想继续进行其他操作吗?(y/n)"<<endl;
bool flag4=0;
do
{
cin>>w;
if(w!='y'&&w!='n')
cout<<"指令错误!请重新输入!"<<endl;
else
flag4=1;
}while(flag4==0);
if(w=='y')
cout<<" 请输入操作代码: "<<endl;
cout<<"0 录入 1 增加人员 2 删除人员"<<endl;
cout<<"3 修改数据 4 按学号查询 5 按姓名查询"<<endl;
cout<<"6 显示所有成员数据 7 按总分排名 8 按语文排名"<<endl;
cout<<"9 按数学排名 y按英语排名"<<endl;
cin>>p;
}while(w=='y');
}
㈨ 学生成绩管理系统c语言编辑的毕业设计 〔20分〕
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define MENU_NUM 7
#define N 3
typedef struct s1
{
char no[11]; /*学号由10个字符组成*/
char name[15]; /*学生姓名*/
float score[N]; /*各门课成绩*/
float sum; /*总分*/
float average; /*平均分*/
int order; /*名次*/
struct s1 *next; /*指向后继结点的指针*/
}STUDENT; /*定义结构体类型*/
STUDENT * head=NULL;
void InputData( STUDENT * ptr );
void PrintMenu( );
int Menu_Select( );
void Init( );
void create( );
void print( ) ;
void Delete( );
void append();
void computer();
main()
{
int key;
while(1) {
key=Menu_Select();
switch(key)
{
case 0: Init();
//初试化链表。也就是若链表不为空则释放链表中所有数据,将head置为空(NULL)
break;
case 1: create();
//创建链表,输入数据
break;
case 2: Delete();
//删除一个指定学号的记录数据
break;
case 3: print();
//打印链表中所有数据
break;
case 4: computer();
//计算链表中所有人的总分和平均分
break;
case 5: append();
//追加一个数据到链表的尾部
break;
case 6: Init();
//释放链表
exit(0);
}
};
}
void PrintMenu( )
{
int i;
char * menu[]={
"0. Init list",
"1. Enter list",
"2. Delete a record from list",
"3. Print list",
"4. Compute the score",
"5. Insert record to list",
"6. Quit"
};
printf("\n\n");
for (i=0;i<MENU_NUM;i++)
printf("%s\n",menu[i]);
printf("\nEnter your choice(0-6):");
}
int Menu_Select( )
{
int key;
PrintMenu( );
scanf("%d",&key);
return key;
}
void Init( ) //初始化单链表。也就是释放链表中的所有数据
{
STUDENT *p,*ptr;//定义两个临时指针变量p,ptr
p=head;ptr=head;//将两个临时变量指向头指针head ;
while(ptr!=NULL)
{
ptr=ptr->next;//ptr指向下一个结构数据
free(p);//释放p所指向的结构数据的内存
p=ptr;//将p指向ptr所指向的数据
}
head=NULL;//将head指向NULL
}
void create( ) //创建单链表
{
STUDENT *pt, *pth=NULL; //定义两个指针变量:pt指向即将申请新的数据内存,pth指向当前数据
while(1)
{
pt=(STUDENT *)malloc(sizeof(STUDENT));//让pt指向新申请的内存空间
InputData(pt);//输入数据,存放到pt所指向的结构数据。注意让pt的next指向NULL
if (strcmp(pt->no,"@")==0)
{
free(pt);//释放pt所指向的内存空间
break;//退出循环
}
else if (head==NULL)
{
pth=pt;
head=pt;//将头指针head和pth指向pt
}
else
{
pth->next=pt; //将pth的next指向pt;
pth=pt; //将pth指向pt;
}
};
}
void print( ) //打印单链表中所有数据
{ int i=0;
STUDENT *p;//第一个指针p
p=head;//将p指向head
printf("\n");
printf("******************************STUDENT******************************\n");
printf("|rec|no | name | sc1| sc2| sc3| sum | ave |order|\n");
printf("|---|----------|----------------|----|----|----|------|-----|-----|\n");
//打印表头
while (p!=NULL)
{
printf("|%3d|%10s|%-16s|%4.1f|%4.1f|%4.1f|%6.2f|%5.1f|%5d|\n",
++i,p->no,p->name,p->score[0],p->score[1],p->score[2],
p->sum,p->average,p->order); //打印p所指向的结构中的所有数据。注意打印数据间的分隔线
p=p->next;//将p指向p的下一个结构数据
}
printf("********************************END********************************\n");//打印表尾
}
void Delete( ) //删除一个记录
{
STUDENT *p,*pth;//定义两个指针p,pth
char no[11];//定义一个整数no(用来存储输入的学号)
printf("intput delete no\n");
scanf("%s",no);//用输入语句输入一个学号存储到no中
p=head;pth=head;//将p和pth都指向头指针
if (strcmp(p->no,no)==0) //也就是若头指针指向的数据需要删除
{
head=head->next;//将head指针指向head的下一个数据;
free(p);//释放p所指向的数据
}
else
{
p=p->next;//将p指向p的下一个数据
while ( p!=NULL)
{
if (strcmp(p->no,no)==0) //找到了要删除的数据
{
pth->next=p->next;//将pth的next指向p的next
free(p);//释放p
break;//退出循环
}
else
{
pth=pth->next;//将pth指向pth的next 或 将pth指向p
p=p->next;//将p指向p的next
}
}
}
}
void append()
{
STUDENT *p,*pth;//定义两个指针变量p,pth
pth=head;//将pth指向head
while ( pth->next!=NULL)
{
pth=pth->next;//ptr指向ptr的next
}
p=(STUDENT *)malloc(sizeof(STUDENT));//将p指向新申请的内存空间
InputData(p);p->next=NULL;//数据数据存储到p所指向的内存空间,注意将p的next置为NULL
pth->next=p;//将ptr的next指向p
}
void InputData( STUDENT *ptr )
{ int i;
printf("enter no:");
scanf("%s",ptr->no);
if (strcmp(ptr->no,"@")==0 ) return;
printf("enter name:");
scanf("%s",ptr->name);
for(i=0;i<3;i++)
{
printf("shuru chengji\n");
scanf("%f",&ptr->score[i]);
}
ptr->sum=0;
ptr->average=0;
ptr->order=0;
ptr->next=NULL;
}
void computer()
{
STUDENT *p;
p=head;
for(;p;p=p->next)
{
p->sum=p->score[0]+p->score[1]+p->score[2];
p->average=(p->score[0]+p->score[1]+p->score[2])/3;
}
}