当前位置:首页 » 编程语言 » c语言学生成绩管理系统
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言学生成绩管理系统

发布时间: 2022-02-09 07:42:19

Ⅰ 用c语言怎么学生成绩管理系统

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int shoudsave=0; /* */
struct student
{
char num[10];/* 学号 */
char name[20];
char sex[4];
int cgrade;
int mgrade;
int egrade;
int totle;
int ave;
char neartime[10];/* 最近更新时间 */
};

typedef struct node
{
struct student data;
struct node *next;
}Node,*Link;

void menu()
{
printf("********************************************************************************");
printf("\t1登记学生资料\t\t\t\t\t2删除学生资料\n");
printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n");
printf("\t5保存学生资料\t\t\t\t\t0退出系统\n");
printf("********************************************************************************\n");
}

void printstart()
{
printf("-----------------------------------------------------------------------\n");
}
void Wrong()
{
printf("\n=====>提示:输入错误!\n");
}

void Nofind()
{
printf("\n=====>提示:没有找到该学生!\n");
}

void printc() /* 本函数用于输出中文 */
{
printf(" 学号\t 姓名 性别 英语成绩 数学成绩 C语言成绩 总分 平均分\n");
}

void printe(Node *p)/* 本函数用于输出英文 */
{
printf("%-12s%s\t%s\t%d\t%d\t%d\t %d\t %d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave);
}

Node* Locate(Link l,char findmess[],char nameornum[]) /* 该函数用于定位连表中符合要求的接点,并返回该指针 */
{
Node *r;
if(strcmp(nameornum,"num")==0) /* 按学号查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.num,findmess)==0)
return r;
r=r->next;
}
}
else if(strcmp(nameornum,"name")==0) /* 按姓名查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.name,findmess)==0)
return r;
r=r->next;
}
}
return 0;
}

void Add(Link l) /* 增加学生 */
{
Node *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next; /* 将指针置于最末尾 */
while(1)
{
printf("请你输入学号(以'0'返回上一级菜单:)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break;
while(s)
{
if(strcmp(s->data.num,num)==0)
{
printf("=====>提示:学号为'%s'的学生已经存在,若要修改请你选择'4 修改'!\n",num);
printstart();
printc();
printe(s);
printstart();
printf("\n");
return;
}
s=s->next;
}

p=(Node *)malloc(sizeof(Node));

strcpy(p->data.num,num);
printf("请你输入姓名:");
scanf("%s",p->data.name);
getchar();
printf("请你输入性别:");
scanf("%s",p->data.sex);
getchar();
printf("请你输入c语言成绩:");
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入数学成绩:");
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入英语成绩:");
scanf("%d",&p->data.egrade);
getchar();
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle / 3;
/* 信息输入已经完成 */
p->next=NULL;
r->next=p;
r=p;
shoudsave=1;

}
}

void Qur(Link l) /* 查询学生 */
{
int sel;
char findmess[20];
Node *p;

if(!l->next)
{
printf("\n=====>提示:没有资料可以查询!\n");
return;

}
printf("\n=====>1按学号查找\n=====>2按姓名查找\n");
scanf("%d",&sel);
if(sel==1)/* 学号 */
{
printf("请你输入要查找的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else if(sel==2) /* 姓名 */
{
printf("请你输入要查找的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else
Wrong();

}

void Del(Link l) /* 删除 */
{
int sel;
Node *p,*r;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以删除!\n");
return;
}
printf("\n=====>1按学号删除\n=====>2按姓名删除\n");
scanf("%d",&sel);
if(sel==1)
{
printf("请你输入要删除的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else if(sel==2)
{
printf("请你输入要删除的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else
Wrong();
}

void Modify(Link l)
{
Node *p;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以修改!\n");
return;
}
printf("请你输入要修改的学生学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("请你输入新学号(原来是%s):",p->data.num);
scanf("%s",p->data.num);
printf("请你输入新姓名(原来是%s):",p->data.name);
scanf("%s",p->data.name);
getchar();
printf("请你输入新性别(原来是%s):",p->data.sex);
scanf("%s",p->data.sex);
printf("请你输入新的c语言成绩(原来是%d分):",p->data.cgrade);
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入新的数学成绩(原来是%d分):",p->data.mgrade);
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入新的英语成绩(原来是%d分):",p->data.egrade);
scanf("%d",&p->data.egrade);
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle/3;
printf("\n=====>提示:资料修改成功!\n");
shoudsave=1;
}
else
Nofind();

}

void Disp(Link l)
{
int count=0;
Node *p;
p=l->next;

if(!p)
{
printf("\n=====>提示:没有资料可以显示!\n");
return;
}
printf("\t\t\t\t显示结果\n");
printstart();
printc();
printf("\n");
while(p)
{
printe(p);
p=p->next;
}
printstart();
printf("\n");
}

void Tongji(Link l)
{
Node *pm,*pe,*pc,*pt,*pa; /* 用于指向分数最高的接点 */
Node *r=l->next;
if(!r)
{
printf("\n=====>提示:没有资料可以统计!\n");
return ;
}
pm=pe=pc=pt=pa=r;
while(r!=NULL)
{
if(r->data.cgrade>=pc->data.cgrade)
pc=r;
if(r->data.mgrade>=pm->data.mgrade)
pm=r;
if(r->data.egrade>=pe->data.egrade)
pe=r;
if(r->data.totle>=pt->data.totle)
pt=r;
if(r->data.ave>=pa->data.ave)
pa=r;

r=r->next;
}
printf("------------------------------统计结果--------------------------------\n");
printf("总分最高者:\t%s %d分\n",pt->data.name,pt->data.totle);
printf("平均分最高者:\t%s %d分\n",pa->data.name,pa->data.ave);

printf("英语最高者:\t%s %d分\n",pe->data.name,pe->data.egrade);
printf("数学最高者:\t%s %d分\n",pm->data.name,pm->data.mgrade);
printf("c语言最高者:\t%s %d分\n",pc->data.name,pc->data.cgrade);
printstart();
}

void Sort(Link l)
{
Link ll;
Node *p,*rr,*s;

ll=(Link)malloc(sizeof(Node)); /* 用于做新的连表 */
ll->next=NULL;

if(l->next==NULL)
{
printf("\n=====>提示:没有资料可以排序!\n");
return ;
}
p=l->next;
while(p)
{
s=(Node*)malloc(sizeof(Node)); /* 新建接点用于保存信息 */
s->data=p->data;
s->next=NULL;

rr=ll;
while(rr->next!=NULL && rr->next->data.totle>=p->data.totle)
rr=rr->next;
if(rr->next==NULL)
rr->next=s;
else
{
s->next=rr->next;
rr->next=s;
}
p=p->next;
}
free(l);
l->next=ll->next;
printf("\n=====>提示:排序已经完成!\n");
}

void Save(Link l)
{
FILE* fp;
Node *p;
int flag=1,count=0;
fp=fopen("c:\\student","wb");
if(fp==NULL)
{
printf("\n=====>提示:重新打开文件时发生错误!\n");
exit(1);
}
p=l->next;

while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{
p=p->next;
count++;
}
else
{
flag=0;
break;
}
}
if(flag)
{
printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count);
shoudsave=0;
}
fclose(fp);
}

void main()
{
Link l;/* 连表 */
FILE *fp; /* 文件指针 */
int sel;
char ch;
char jian;

int count=0;
Node *p,*r;
printf("\t\t\t\t学生成绩管理系统\n\t\t\t\t-------福建农业职业学院计应0501 黄欢(32号)\n");
l=(Node*)malloc(sizeof(Node));
l->next=NULL;
r=l;

fp=fopen("C:\\student","rb");
if(fp==NULL)
{
printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n");
scanf("%c",&jian);
if(jian=='y'||jian=='Y')
fp=fopen("C:\\student","wb");
else
exit(0);
}
printf("\n=====>提示:文件已经打开,正在导入记录......\n");

while(!feof(fp))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp)) /* 将文件的内容放入接点中 */
{
p->next=NULL;
r->next=p;
r=p; /* 将该接点挂入连中 */
count++;
}
}

fclose(fp); /* 关闭文件 */
printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count);

while(1)
{
menu();
printf("请你选择操作:");
scanf("%d",&sel);

if(sel==0)
{
if(shoudsave==1)
{ getchar();
printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
Save(l);
}
printf("\n=====>提示:你已经退出系统,再见!\n");
break;
}
switch(sel)
{
case 1:Add(l);break; /* 增加学生 */
case 2:Del(l);break;/* 删除学生 */
case 3:Qur(l);break;/* 查询学生 */
case 4:Modify(l);break;/* 修改学生 */
case 5:Save(l);break;/* 保存学生 */
case 9:printf("\t\t\t==========帮助信息==========\n");break;
default: Wrong();getchar();break;
}
}
}
/* */

/*
学生成绩管理程序
编制一个统计学生考试分数的管理程序。
设学生成绩已以一个学生一个记录的形式存储在文件中,
每位学生记录包含的信息有:姓名,学号和各门功课的成绩。
程序具有以下几项功能:求出各门课程的总分,平均分,按姓名,
按学号寻找其记录并显示,浏览全部学生成绩和按总分由高到低显示学生信息等。
*/

#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语言 学生成绩管理系统

int main (void) //定义了 student 函数,用来管理学生信息
{
int a,t1,t2,t3,t4
struct student * st=(struct student *)malloc(sizeof(struct student)*200); //最难的语句 定义了动态的结构体数组
struct student t5; //定义了结构体类型的临时变量t5

printf("欢迎来到学生信息管理系统!\n");
printf("请输入你想处理几个学生的信息?:");
scanf("%d",&t1); //t1表示学生的个数
for (t2=0;t2<t1;++t2) //t2是临时变量
{
printf("第%d个学生\n",t2+1);
printf("姓名:");
scanf("%s",st[t2].name);
printf("年龄:");
scanf("%d",&st[t2].age);

printf("成绩:");
scanf("%lf",&st[t2].score);
}
printf("\n\n你想升序排成绩,还是降序排成绩(升序请按1,降序请按其他字符)?:");
scanf("%d",&a); //a用来判断升序还是降序
for (t3=0;t3<t1-1;++t3)
{
for (t4=t3+1;t4<t1;++t4)
{
if(a==1)
{
if( (((st+t3))->score) > ((st+t4)->score) ) //t3,t4用来结束循环
{
t5=*(st+t3);
*(st+t3)=*(st+t4);
*(st+t4)=t5;
}
}
else
{
if( (((st+t3))->score) < ((st+t4)->score) )
{
t5=*(st+t3);
*(st+t3)=*(st+t4);
*(st+t4)=t5;
}
}

}
}
for (t2=0;t2<t1;++t2)
printf("第%d名是%s %lf \n",t2+1,(st+t2)->name,(st+t2)->score);
return 0;

}
打字好累,希望帮你,谢谢

Ⅲ c语言实训 学生成绩管理系统

#include<stdio.h>
#include<string.h>

typedefstruct{
intqq;
charstring[1024];
}C语言;

intmain(){
C语言c={563337217,"计算机C语言课程设计有偿助攻,看清楚了有偿助攻再加好友! 总有穷逼和傻逼想不花钱让爹给你白写,你TMD以为你是谁啊。 想让爹给你白写的滚一边去,省的挨骂!"};
printf("QQ:%d %s ",c.qq,c.string);
return0;
}

Ⅳ c语言程序学生成绩管理系统源代码

VC++6.0编译通过,利用结构体,结构体指针,单链表,文件操作,命令窗口下简单菜单设计,可从文件读入数据,自动保存数据,有错误自动判断修复,能添加,删除,查询,显示,排序记录,通过本人2小时升级修改,已经适合多数初学者期末C语言作业设计要求!如果要增加科目,只要修改源代码中的Class_N的值就可以了,科目的名称在程序第一次运行时输入,会自动保存到student.ini文件,程序运行时自动生成的student.ini文件为系统信息文件(二进制文件),student.db为数据存储文件(二进制文件),Student.txt为操作记录文件(文本文件),可以修改Student.txt的打开方式,那样就能保存以前的操作记录了。代码下载:请点击下载链接:网页链接

Ⅳ c语言的学生成绩管理系统

#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>

using namespace std;

#define max 100;

class student
{
public:
student *next;
public:
string name;//姓名
long num;//学号
int x,y,z;//数学,语文,英语
int AA;//总分
void play(){cout<<name<<"学生的学号是"<<num<<",数学:"<<x<<",语文:"<<y<<",英语:"<<z<<",总分:"<<AA<<endl;};
student(string sname,long snum,int sx,int sy,int sz)
{
name=sname;
num=snum;
x=sx;
y=sy;
z=sz;
}
};

class cla
{
public:
cla()//构造函数
{
stu=0;
sload();
}
~cla()//析构函数
{
student *p;
p=stu;
while(p)
{
p=p->next;
delete stu;
stu=p;
}
stu=0;
}
void sadd(); //添加
void sremove(); //删除
void samend(); //修改
void ssearch(); //查询
void staxis(); //排序
void ssave(); //保存
void sload(); //读取

//排序函数
void pxh();
void psx();
void pyw();
void pyy();
void pAA();
private:
student *stu; //头接点
};

void cla::sadd()//添加
{
student *q;
string name1;
long num1;
int x1,y1,z1;

system("cls");
cout<<"\n **增加的学生** \n"<<endl;
cout<<"请输入学生的(中间用空格间隔) "<<endl;
cout<<"姓名 学号 数学成绩 语文成绩 英语成绩:"<<endl;
cin>>name1>>num1>>x1>>y1>>z1;

q=new student(name1,num1,x1,y1,z1);
q->next=0;
q->AA=x1+y1+z1;

if(stu)
{
student *t;
t=stu;
if(t->num==num1)
{
cout<<"学号已存在,请重新输入"<<endl;
return;
}
while(t->next)
{
if(t->num==num1)
{
cout<<"学号已存在,请重新输入"<<endl;
return;
}
t=t->next;
}
t->next=q;
}
else
{
stu=q;
}
cout<<"输入完毕"<<endl;
}

void cla::sremove()//删除
{
system("cls");
int num1;
cout<<"\n** 删除学生信息 **\n";
cout<<"请输入想要删除学生的学号:";
cin>>num1;

//查找要删除的结点
student *p1,*p2;
p1=stu;
while(p1)
{
if(p1->num==num1)
break;
else
{
p2=p1;
p1=p1->next;
}
}

//删除结点
if(p1!=NULL)//若找到结点,则删除
{
p1->play();
cout<<"确定删除吗?[Y/N]"<<endl;
char c;cin>>c;
if(toupper(c)!='Y') return;

if(p1==stu) //若要删除的结点是第一个结点
{
stu=p1->next;
delete p1;
}
else //若要删除的结点是后续结点
{
p2->next=p1->next;
delete p1;
}
cout<<"找到学号为"<<num1<<"的学生,并删除\n";
}
else //未找到结点
cout<<"未找到想要删除的学生!\n";
}

void cla::samend()//修改
{
system("cls");
long num1;
cout<<"\n** 修改学生信息 **\n";
cout<<"输入要修改学生的学号";
cin>>num1;

//查找要修改的结点
student *p1,*p2;
p1=stu;
while(p1)
{
if(p1->num==num1)
break;
else
{
p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{
cout<<"学号是"<<num1<<"的学生的信息"<<endl;
cout<<"姓名 "<<p1->name<<"数学"<<p1->x<<"语文"<<p1->y<<"英语"<<p1->z<<endl;
cout<<"请输入修改后的信息:姓名 数学成绩 语文成绩 英语成绩"<<endl;
cin>>p1->name>>p1->x>>p1->y>>p1->z;
p1->AA=p1->x+p1->y+p1->z;
cout<<"修改成功"<<endl;
}
else //未找到接点
cout<<"未找到!\n";
}

void cla::ssearch()//查询
{
system("cls");
cout<<"\n** 查询学生信息 **\n"<<endl;
cout<<"请输入查询方式:"<<endl;
cout<<"1.按学号查询"<<endl;
cout<<"2.按姓名查询"<<endl;
cout<<"3.返回"<<endl;
char c; cin>>c;
switch (c)
{
case '1':
{
long num1;
cout<<"要查询的学号"<<endl;
cin>>num1;
//查找要查询的结点
student *p1,*p2;
p1=stu;
while(p1)
{
if(p1->num==num1)
break;
else
{
p2=p1;
p1=p1->next;
}
}

if(p1!=NULL)
{
cout<<"学号是"<<num1<<"的学生的信息"<<endl;
cout<<"姓名:"<<p1->name<<" 数学:"<<p1->x<<" 语文:"<<p1->y<<" 英语:"<<p1->z<<endl;
cout<<"查询完毕...";
}
else //未找到接点
cout<<"未找到!\n";
break;
}
case '2':
{
string name1;
cout<<"要查询的学生姓名"<<endl;
cin>>name1;
//查找要查询的结点
student *p1,*p2;
p1=stu;
while(p1)
{
if(p1->name==name1)
break;
else
{
p2=p1;
p1=p1->next;
}
}

if(p1!=NULL)
{
cout<<name1<<"的学生的信息"<<endl;
cout<<"学号:"<<p1->num<<" 数学:"<<p1->x<<" 语文:"<<p1->y<<" 英语:"<<p1->z<<endl;
cout<<"查询完毕...";
}
else //未找到接点
cout<<"未找到!\n";
break;
}
case '3': return;
}

}

void cla::pxh() //按学号排序
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<<"共有"<<n<<"条信息..."<<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{
p1=stu;
if (p1->num>p1->next->num) // 如果头结点大于第二个的
{
p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; //头结点交换
stu=p2;
}
p1=stu;
while(p1->next->next) //中间的交换
{
p2=p1;
p1=p1->next;
if(p1->num>p1->next->num)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //交换
}
}
}

p1=stu;
do
{
p1->play();
p1=p1->next;
}while(p1);
}

void cla::psx()//按数学成绩排序
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<<"共有"<<n<<"条信息..."<<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->x>p1->next->x) // 如果头结点大于第二个的
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; //头结点交换
stu=p2;
}
p1=stu;
while(p1->next->next) //中间的交换
{ p2=p1;
p1=p1->next;
if(p1->x>p1->next->x)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //交换
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}

void cla::pyw()//按语文成绩排序
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<<"共有"<<n<<"条信息..."<<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->y>p1->next->y) // 如果头结点大于第二个的
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; //头结点交换
stu=p2;
}
p1=stu;
while(p1->next->next) //中间的交换
{ p2=p1;
p1=p1->next;
if(p1->y>p1->next->y)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //交换
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}

void cla::pyy()//按英语成绩排序
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<<"共有"<<n<<"条信息..."<<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->z>p1->next->z) // 如果头结点大于第二个的
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; //头结点交换
stu=p2;
}
p1=stu;
while(p1->next->next) //中间的交换
{ p2=p1;
p1=p1->next;
if(p1->z>p1->next->z)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //交换
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}

void cla::pAA()//按总分排序
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<<"共有"<<n<<"条信息..."<<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->AA>p1->next->AA) // 如果头结点大于第二个的
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; //头结点交换
stu=p2;
}
p1=stu;
while(p1->next->next) //中间的交换
{ p2=p1;
p1=p1->next;
if(p1->AA>p1->next->AA)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //交换
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}

void cla::staxis()//排序
{

system("cls");
char c;
cout<<"请选择以何种方式排序:"<<endl;
cout<<"1……以学号排序"<<endl;
cout<<"2……以数学成绩排序"<<endl;
cout<<"3……以语文成绩排序"<<endl;
cout<<"4……以英语成绩排序"<<endl;
cout<<"5……以总分排序"<<endl;
cout<<"6……返回"<<endl;
cout<<"请选择(1-6)"<<endl;
cin>>c;

switch (c)
{
case '1':pxh(); break;
case '2':psx(); break;
case '3':pyw(); break;
case '4':pyy(); break;
case '5':pAA(); break;
case '6':return;
}

}

void cla::ssave() //保存到文件
{
system("cls");
char c;
cout<<"\n保存学生信息(将覆盖原文件),是否继续?[Y/N]:"; cin>>c;
if(toupper(c)!='Y') return;

ofstream tfile("date.txt",ios_base::binary);
student *p=stu;
while(p)// 写入文件
{
tfile<<p->name<<"\t"<<p->num<<"\t"<<p->x<<"\t"<<p->y<<"\t"<<p->z;
tfile<<endl;
p=p->next;
}
tfile.close();
cout<<"保存完毕..."<<endl;
}

void cla::sload() //读取
{
student *p;
p=stu;
while(p)
{
stu=p->next;
delete p;
p=stu;
}

ifstream tfile("date.txt",ios_base::binary);

string name1;
long num1;
int x1,y1,z1;

tfile>>name1>>num1>>x1>>y1>>z1;
while(tfile.good())
{
//创建学生接点
student *s;
s=stu;
s=new student(name1,num1,x1,y1,z1);
s->next=0;
s->AA=x1+y1+z1;
if(stu) //若已经存在结点
{
student *p2;
p2=stu;
while(p2->next) //查找尾结点
{
p2=p2->next;
}
p2->next=s; //连接
}
else //若不存在结点(表空)
{
stu=s; //连接
}
tfile>>name1>>num1>>x1>>y1>>z1;
}
tfile.close();
cout<<"\n学生信息已经装入...\n";

}

int main()
{
char c;
cla a;
do
{
cout<<"\n 学 生 成 绩 管 理 系 统 \n";
cout<<"**************************************\n";
cout<<" 作者:软件工程06110119:zgjxwl \n";
cout<<" 1……增加学生 \n";
cout<<" 2……删除学生 \n";
cout<<" 3……修改学生 \n";
cout<<" 4……查询学生信息 \n";
cout<<" 5……排序 \n";
cout<<" 6……保存信息 \n";
cout<<" 7……读取信息 \n";
cout<<" 8……退出 \n";
cout<<"**************************************\n";
cout<<"请选择(1-8):";
cin>>c;
switch(c)
{
case '1': a.sadd();break;
case '2': a.sremove();break;
case '3': a.samend();break;
case '4': a.ssearch();break;
case '5': a.staxis();break;
case '6': a.ssave();break;
case '7': a.sload();break;
}

}while(c!='8');
}

Ⅵ C语言 学生成绩管理系统

#include <stdio.h>

#define MAX 40

typedef struct{
char name[15];
int num;
int C;
int E;
int M;
int sum;
}student_t;

typedef struct{
int n;
student_t stu[MAX];
}class_t;

enum{
ADD_STUDENT = 1,
SHOW_STUDENT = 2,
DELETE_STUDENT = 3,
SORT_STUDENT = 4,
FIND_STUDENT = 5,
QUIT
};

void input_student(student_t *pstu)
{
int ret;

again_input:
printf("学号\t姓名\tC语言\t英语\t数学\t\n");
ret = scanf("%d %s %d %d %d",&pstu->num,pstu->name,&pstu->C,&pstu->E,&pstu->M);
if(ret < 5){
printf("Input error,must input string,int,int\n");
while ( getchar() != '\n')
;
goto again_input;
}
pstu->sum=(pstu->C+pstu->E+pstu->M);
printf("input end!\n");

return;
}

int add_student(class_t *pclass,student_t *pstu)
{
if(pclass->n >= MAX){
printf("The class is full!\n");
return -1;
}

pclass->stu[pclass->n ++] = *pstu;

return 0;
}

void show(student_t *pstu)
{
printf("%d %s %d %d %d %d\n",pstu->num,pstu->name,pstu->C,pstu->E,pstu->M,pstu->sum);
return;
}

void show_student(class_t *pclass)
{
int i;

printf("学号\t姓名\tC语言\t英语\t数学\t总分\t\n");
for(i = 0;i < pclass->n;i ++){
show(&pclass->stu[i]);
}

return;
}

int delete_student(class_t *pclass,char *stu_name)
{
int i,j;

for(i = 0, j = 0;i < pclass->n;i ++){
if(strcmp(pclass->stu[i].name,stu_name) != 0){
pclass->stu[j++] = pclass->stu[i];
}
}

if(i == j){
printf("The delete student:%s is not exist!\n",stu_name);
return 0;
}else{
pclass->n = j;
return i - j;
}
}

void sort_student(class_t *pclass)
{
int i,j;
int flag;
student_t student;

for(i = 0;i < pclass->n - 1;i ++){
for(j = 0,flag = 0;j < pclass->n - 1 - i;j ++){
if(pclass->stu[j].sum > pclass->stu[j + 1].sum){
student = pclass->stu[j];
pclass->stu[j] = pclass->stu[j+1];
pclass->stu[j+1] = student;
flag = 1;
}
}

if(!flag){
break;
}
}

return;
}

int find_student(class_t *pclass,char *stu_name)
{
int i;
int count = 0;

for(i = 0;i < pclass->n;i ++){
if(strcmp(pclass->stu[i].name,stu_name) == 0){
show(&pclass->stu[i]);
count ++;
}
}

return count;
}

int main(int argc, const char *argv[])
{
int n;
int choice;
char name[15];
class_t class = {0};
student_t student;

while(1)
{
puts("------------------------------------------");
puts("1.添加 2.查询 3.删除 4.排序 5.查找 6.退出");
puts("------------------------------------------");

printf("choice > ");
scanf("%d",&choice);

switch(choice){
case ADD_STUDENT:
input_student(&student);
add_student(&class,&student);
break;

case SHOW_STUDENT:
show_student(&class);
break;
case DELETE_STUDENT:
printf("Input delete student name : ");
scanf("%s",name);
n = delete_student(&class,name);
if(n > 0){
printf("Delete %d students!\n",n);
}
break;

case SORT_STUDENT:
sort_student(&class);
show_student(&class);
break;

case FIND_STUDENT:
printf("Input find student name : ");
scanf("%s",name);
n = find_student(&class,name);
printf("Find %d students!\n",n);
break;

case QUIT:
printf("quit student system!\n");
goto quit;
}
}
quit:
return 0;
}

Ⅶ 用c语言实现一个简单的学生成绩管理系统,包括:学号,姓名,科目,成绩

//用字符界面实现,比如按数字1,可以录入学生所有信息;
//按数字2,显示所有学生成绩;
//按数字3,进入查询,按学号或姓名查询该学生是否存在,如果存在显示他的所有信息,///否则给出不存在提示。
#include<stdio.h>
structstudent
{
charnum[6];/*学号*/
charname[10];
charsubject[20];/*科目*/
floatgrade;
}stu[10];
voidmenu()
{
printf("==================================== ");
printf("|学生成绩管理系统| ");
printf("|1输入学生成绩| ");
printf("|2输出学生成绩| ");
printf("|3查询学生成绩| ");
printf("|0退出管理系统| ");
printf("==================================== ");
}
voidinput()
{
for(inti=0;i<10;i++)
scanf("%s%s%s%f",stu[i].num,stu[i].name,stu[i].subject,&stu[i].grade);
}
voidshow()
{
printf("学号 姓名 科目 成绩 ");
for(inti=0;i<10;i++)
printf("%s %s %s %f ",stu[i].num,stu[i].name,stu[i].subject,stu[i].grade);
}
voidserach()
{
charobj[10];
printf("输入要查询的学号");
scanf("%s",obj);
for(inti=0;i<10;i++)
{
if(strcmp(obj,stu[i].num))
{
printf("学号 姓名 科目 成绩 ");
printf("%s %s %s %f ",stu[i].num,stu[i].name,stu[i].subject,stu[i].grade);
}
}
}
intmain()
{
intselection;
while(true)
{
clrscr();
menu();
printf("请选择0--3:");
scanf("%d",&selection);
switch(selection)
{
case1:input();break;
case2:show();break;
case3:search();break;
case0:exit(0);break;
default:printf("错误的输入,请重新输入:");
}
}
return0;
}

Ⅷ C语言编写一个简单的学生成绩管理系统

C语言程序:

#include<stdio.h>
#include<string.h>

typedefstructstudent
{
charname[20]; /*姓名*/
intcode; /*学号*/
intkor,eng,math; /*3门课程的成绩*/
}STUDENT;

/*返回输入数据*/
STUDENTInput();

/*输出所有输入的数据*/
voidOutput(STUDENTinfo[],intcnt);

/*将输入分数转换为A-F*/
chargrade(intscore);

intmain()
{
STUDENTS[10];
intcnt=0,select;
inti,j;
intcode;

while(1)
{
printf(" 学生信息管理系统 ");
printf(" 1 添加 ");
printf(" 2 删除 ");
printf(" 3 查询 ");
printf(" 0 结束 ");
printf(" 您的选择[0-3]:");
scanf("%d",&select);

if(select<0||select>3)
continue;
if(select==0)
{
printf("退出系统! ");
break;
}

if(select==1) /*添加*/
{
S[cnt++]=Input();
}
elseif(select==2) /*删除*/
{
printf(" 待删除学生的学号:");
scanf("%d",&code);

for(i=0;i<cnt;i++)
if(S[i].code==code)
break;
if(i>=cnt)
{
printf("学号不存在,删除失败! ");
}
else{
for(j=i+1;j<cnt;j++)
{
strcpy(S[j-1].name,S[j].name);
S[j-1].code=S[j].code;
S[j-1].kor=S[j].kor;
S[j-1].eng=S[j].eng;
S[j-1].math=S[j].math;
}
cnt--;
printf("删除成功! ");
}
}
else /*查询*/
{
printf(" 待查找学生的学号:");
scanf("%d",&code);

for(i=0;i<cnt;i++)
if(S[i].code==code)
break;
if(i>=cnt)
{
printf("学号不存在,查找失败! ");
}
else
{
printf(" 查询结果: ");
Output(S,i);
}
}
}

return0;
}

/*返回输入数据*/
STUDENTInput()
{
STUDENTstu;
printf(" 新学生信息 ");
printf(" 学号:");
scanf("%d",&stu.code);
printf(" 姓名:");
getchar();
gets(stu.name);
printf(" 3门课程成绩(以空格分隔):");
scanf("%d%d%d",&stu.kor,&stu.eng,&stu.math);

returnstu;
}

/*输出所有输入的数据*/
voidOutput(STUDENTinfo[],intcnt)
{
printf("学号:%d ",info[cnt].code);
printf("姓名:");
puts(info[cnt].name);
printf("成绩:%c%c%c ",grade(info[cnt].kor),grade(info[cnt].eng),grade(info[cnt].math));
}

/*将输入分数转换为A-F*/
chargrade(intscore)
{
if(score<0||score>100)
return'F';
if(score>=90)
return'A';
if(score>=80)
return'B';
if(score>=70)
return'C';
if(score>=60)
return'D';
else
return'E';
}


运行测试:

Ⅸ c语言学生成绩管理系统

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int shoudsave=0; /* */
struct student
{
char num[10];/* 学号 */
char name[20];
char sex[4];
int cgrade;
int mgrade;
int egrade;
int totle;
int ave;
char neartime[10];/* 最近更新时间 */
};

typedef struct node
{
struct student data;
struct node *next;
}Node,*Link;

void menu()
{
printf("********************************************************************************");
printf("\t1登记学生资料\t\t\t\t\t2删除学生资料\n");
printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n");
printf("\t5保存学生资料\t\t\t\t\t0退出系统\n");
printf("********************************************************************************\n");
}

void printstart()
{
printf("-----------------------------------------------------------------------\n");
}
void Wrong()
{
printf("\n=====>提示:输入错误!\n");
}

void Nofind()
{
printf("\n=====>提示:没有找到该学生!\n");
}

void printc() /* 本函数用于输出中文 */
{
printf(" 学号\t 姓名 性别 英语成绩 数学成绩 C语言成绩 总分 平均分\n");
}

void printe(Node *p)/* 本函数用于输出英文 */
{
printf("%-12s%s\t%s\t%d\t%d\t%d\t %d\t %d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave);
}

Node* Locate(Link l,char findmess[],char nameornum[]) /* 该函数用于定位连表中符合要求的接点,并返回该指针 */
{
Node *r;
if(strcmp(nameornum,"num")==0) /* 按学号查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.num,findmess)==0)
return r;
r=r->next;
}
}
else if(strcmp(nameornum,"name")==0) /* 按姓名查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.name,findmess)==0)
return r;
r=r->next;
}
}
return 0;
}

void Add(Link l) /* 增加学生 */
{
Node *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next; /* 将指针置于最末尾 */
while(1)
{
printf("请你输入学号(以'0'返回上一级菜单:)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break;
while(s)
{
if(strcmp(s->data.num,num)==0)
{
printf("=====>提示:学号为'%s'的学生已经存在,若要修改请你选择'4 修改'!\n",num);
printstart();
printc();
printe(s);
printstart();
printf("\n");
return;
}
s=s->next;
}

p=(Node *)malloc(sizeof(Node));

strcpy(p->data.num,num);
printf("请你输入姓名:");
scanf("%s",p->data.name);
getchar();
printf("请你输入性别:");
scanf("%s",p->data.sex);
getchar();
printf("请你输入c语言成绩:");
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入数学成绩:");
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入英语成绩:");
scanf("%d",&p->data.egrade);
getchar();
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle / 3;
/* 信息输入已经完成 */
p->next=NULL;
r->next=p;
r=p;
shoudsave=1;

}
}

void Qur(Link l) /* 查询学生 */
{
int sel;
char findmess[20];
Node *p;

if(!l->next)
{
printf("\n=====>提示:没有资料可以查询!\n");
return;

}
printf("\n=====>1按学号查找\n=====>2按姓名查找\n");
scanf("%d",&sel);
if(sel==1)/* 学号 */
{
printf("请你输入要查找的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else if(sel==2) /* 姓名 */
{
printf("请你输入要查找的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else
Wrong();

}

void Del(Link l) /* 删除 */
{
int sel;
Node *p,*r;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以删除!\n");
return;
}
printf("\n=====>1按学号删除\n=====>2按姓名删除\n");
scanf("%d",&sel);
if(sel==1)
{
printf("请你输入要删除的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else if(sel==2)
{
printf("请你输入要删除的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else
Wrong();
}

void Modify(Link l)
{
Node *p;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以修改!\n");
return;
}
printf("请你输入要修改的学生学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("请你输入新学号(原来是%s):",p->data.num);
scanf("%s",p->data.num);
printf("请你输入新姓名(原来是%s):",p->data.name);
scanf("%s",p->data.name);
getchar();
printf("请你输入新性别(原来是%s):",p->data.sex);
scanf("%s",p->data.sex);
printf("请你输入新的c语言成绩(原来是%d分):",p->data.cgrade);
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入新的数学成绩(原来是%d分):",p->data.mgrade);
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入新的英语成绩(原来是%d分):",p->data.egrade);
scanf("%d",&p->data.egrade);
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle/3;
printf("\n=====>提示:资料修改成功!\n");
shoudsave=1;
}
else
Nofind();

}

void Disp(Link l)
{
int count=0;
Node *p;
p=l->next;

if(!p)
{
printf("\n=====>提示:没有资料可以显示!\n");
return;
}
printf("\t\t\t\t显示结果\n");
printstart();
printc();
printf("\n");
while(p)
{
printe(p);
p=p->next;
}
printstart();
printf("\n");
}

void Tongji(Link l)
{
Node *pm,*pe,*pc,*pt,*pa; /* 用于指向分数最高的接点 */
Node *r=l->next;
if(!r)
{
printf("\n=====>提示:没有资料可以统计!\n");
return ;
}
pm=pe=pc=pt=pa=r;
while(r!=NULL)
{
if(r->data.cgrade>=pc->data.cgrade)
pc=r;
if(r->data.mgrade>=pm->data.mgrade)
pm=r;
if(r->data.egrade>=pe->data.egrade)
pe=r;
if(r->data.totle>=pt->data.totle)
pt=r;
if(r->data.ave>=pa->data.ave)
pa=r;

r=r->next;
}
printf("------------------------------统计结果--------------------------------\n");
printf("总分最高者:\t%s %d分\n",pt->data.name,pt->data.totle);
printf("平均分最高者:\t%s %d分\n",pa->data.name,pa->data.ave);

printf("英语最高者:\t%s %d分\n",pe->data.name,pe->data.egrade);
printf("数学最高者:\t%s %d分\n",pm->data.name,pm->data.mgrade);
printf("c语言最高者:\t%s %d分\n",pc->data.name,pc->data.cgrade);
printstart();
}

void Sort(Link l)
{
Link ll;
Node *p,*rr,*s;

ll=(Link)malloc(sizeof(Node)); /* 用于做新的连表 */
ll->next=NULL;

if(l->next==NULL)
{
printf("\n=====>提示:没有资料可以排序!\n");
return ;
}
p=l->next;
while(p)
{
s=(Node*)malloc(sizeof(Node)); /* 新建接点用于保存信息 */
s->data=p->data;
s->next=NULL;

rr=ll;
while(rr->next!=NULL && rr->next->data.totle>=p->data.totle)
rr=rr->next;
if(rr->next==NULL)
rr->next=s;
else
{
s->next=rr->next;
rr->next=s;
}
p=p->next;
}
free(l);
l->next=ll->next;
printf("\n=====>提示:排序已经完成!\n");
}

void Save(Link l)
{
FILE* fp;
Node *p;
int flag=1,count=0;
fp=fopen("c:\\student","wb");
if(fp==NULL)
{
printf("\n=====>提示:重新打开文件时发生错误!\n");
exit(1);
}
p=l->next;

while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{
p=p->next;
count++;
}
else
{
flag=0;
break;
}
}
if(flag)
{
printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count);
shoudsave=0;
}
fclose(fp);
}

void main()
{
Link l;/* 连表 */
FILE *fp; /* 文件指针 */
int sel;
char ch;
char jian;

int count=0;
Node *p,*r;
printf("\t\t\t\t学生成绩管理系统\n\t\t\t\t-------福建农业职业学院计应0501 黄欢(32号)\n");
l=(Node*)malloc(sizeof(Node));
l->next=NULL;
r=l;

fp=fopen("C:\\student","rb");
if(fp==NULL)
{
printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n");
scanf("%c",&jian);
if(jian=='y'||jian=='Y')
fp=fopen("C:\\student","wb");
else
exit(0);
}
printf("\n=====>提示:文件已经打开,正在导入记录......\n");

while(!feof(fp))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp)) /* 将文件的内容放入接点中 */
{
p->next=NULL;
r->next=p;
r=p; /* 将该接点挂入连中 */
count++;
}
}

fclose(fp); /* 关闭文件 */
printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count);

while(1)
{
menu();
printf("请你选择操作:");
scanf("%d",&sel);

if(sel==0)
{
if(shoudsave==1)
{ getchar();
printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
Save(l);
}
printf("\n=====>提示:你已经退出系统,再见!\n");
break;
}
switch(sel)
{
case 1:Add(l);break; /* 增加学生 */
case 2:Del(l);break;/* 删除学生 */
case 3:Qur(l);break;/* 查询学生 */
case 4:Modify(l);break;/* 修改学生 */
case 5:Save(l);break;/* 保存学生 */
case 9:printf("\t\t\t==========帮助信息==========\n");break;
default: Wrong();getchar();break;
}
}
}
/* */

Ⅹ C语言学生成绩管理系统

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
#define LEN sizeof(struct student)
#define FORMAT "%-8d%-15s%-12.1lf%-12.1lf%-12.1lf%-12.1lf\n"
#define DATA stu[i].num,stu[i].name,stu[i].elec,stu[i].expe,stu[i].requ,stu[i].sum
struct student
{ int num;
char name[15];
double elec;
double expe;
double requ;
double sum;
};
struct student stu[50];
void in();
void show();
void order();
void del();
void modify();
void menu();
void insert();
void total();
void search();
void main()
{ int n;
menu();
scanf("%d",&n);
while(n)
{ switch(n)
{ case 1: in();break;
case 2: search();break;
case 3: del();break;
case 4: modify();break;
case 5: insert();break;
case 6: order();break;
case 7: total();break;
default:break;
}
getch();
menu();
scanf("%d",&n);
}
}void in()
{ int i,m=0;
char ch[2];
FILE *fp;
if((fp=fopen("data.txt","a+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp)) {
if(fread(&stu[m] ,LEN,1,fp)==1)
m++;
}
fclose(fp);
if(m==0)
printf("No record!\n");
else
{
system("cls");
show();
}
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(i=0;i<m;i++)
{
fwrite(&stu[i] ,LEN,1,fp);
}
printf("please input(y/n):");
scanf("%s",ch);
while(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)
{
printf("number:");
scanf("%d",&stu[m].num);/*输入学生学号*/
for(i=0;i<m;i++)
if(stu[i].num==stu[m].num)
{
printf("the number is existing,press any to continue!");
getch();
fclose(fp);
return;
}
printf("name:");
scanf("%s",stu[m].name);
printf("elective:");
scanf("%lf",&stu[m].elec);
printf("experiment:");
scanf("%lf",&stu[m].expe);
printf("required course:");
scanf("%lf",&stu[m].requ);
stu[m].sum=stu[m].elec+stu[m].expe+stu[m].requ;
if(fwrite(&stu[m],LEN,1,fp)!=1)/*将新录入的信息写入指定的磁盘文件*/
{ printf("can not save!"); getch(); }
else { printf("%s saved!\n",stu[m].name);m++;}
printf("continue?(y/n):");/*询问是否继续*/
scanf("%s",ch);
}
fclose(fp);
printf("OK!\n");
}void show()
{ FILE *fp;
int i,m=0;
fp=fopen("data.txt","rb");
while(!feof(fp))
{
if(fread(&stu[m] ,LEN,1,fp)==1)
m++;
}
fclose(fp);
printf("number name elective experiment required sum\t\n");
for(i=0;i<m;i++)
{
printf(FORMAT,DATA);//
}
}

void menu()
{
system("cls");
printf("\n\n\n\n\n");
printf("\t\t|---------------------STUDENT-------------------|\n");
printf("\t\t|\t 0. exit |\n");
printf("\t\t|\t 1. input record |\n");
printf("\t\t|\t 2. search record |\n");
printf("\t\t|\t 3. delete record |\n");
printf("\t\t|\t 4. modify record |\n");
printf("\t\t|\t 5. insert record |\n");
printf("\t\t|\t 6. order |\n");
printf("\t\t|\t 7. number |\n");
printf("\t\t|-----------------------------------------------|\n\n");
printf("\t\t\tchoose(0-7):");
}void order()/*自定义排序函数*/
{ FILE *fp;
struct student t;
int i=0,j=0,m=0;
if((fp=fopen("data.txt","r+"))==NULL)
{
printf("can not open!\n");
return;
}
while(!feof(fp))
if(fread(&stu[m] ,LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
if((fp=fopen("data.txt","wb"))==NULL)
{
printf("can not open\n");
return;}
for(i=0;i<m-1;i++)
for(j=i+1;j<m;j++)
if(stu[i].sum<stu[j].sum)
{ t=stu[i];stu[i]=stu[j];stu[j]=t;}
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(i=0;i<m;i++)
if(fwrite(&stu[i] ,LEN,1,fp)!=1)
{
printf("%s can not save!\n");
getch();
}
fclose(fp);
printf("save successfully\n");
}
void del()/*自定义删除函数*/
{FILE *fp;<br> int snum,i,j,m=0;<br> char ch[2];<br> if((fp=fopen("data.txt","r+"))==NULL)<br> { printf("can not open\n");return;}
while(!feof(fp)) if(fread(&stu[m],LEN,1,fp)==1) m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
printf("please input the number:");
scanf("%d",&snum);
for(i=0;i<m;i++)
if(snum==stu[i].num)
break;
printf("find the student,delete?(y/n)");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判断是否要进行删除*/
for(j=i;j<m;j++)
stu[j]=stu[j+1];/*将后一个记录移到前一个记录的位置*/
m--;/*记录的总个数减1*/
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(j=0;j<m;j++)/*将更改后的记录重新写入指定的磁盘文件中*/
if(fwrite(&stu[j] ,LEN,1,fp)!=1)
{ printf("can not save!\n");
getch();}
fclose(fp);
printf("delete successfully!\n");
}void search()/*自定义查找函数*/
{ FILE *fp;
int snum,i,m=0;
char ch[2];
if((fp=fopen("data.txt","rb"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp)) if(fread(&stu[m],LEN,1,fp)==1) m++;
fclose(fp);
if(m==0) {printf("no record!\n");return;}
printf("please input the number:");
scanf("%d",&snum);
for(i=0;i<m;i++)
if(snum==stu[i].num)/*查找输入的学号是否在记录中*/
{ printf("find the student,show?(y/n)");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)
{
printf("number name elective experiment required sum\t\n");
printf(FORMAT,DATA);/*将查找出的结果按指定格式输出*/
break;
}
}
if(i==m) printf("can not find the student!\n");/*未找到要查找的信息*/
}void modify()/*自定义修改函数*/
{ FILE *fp;
int i,j,m=0,snum;
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1) m++;
if(m==0) {printf("no record!\n");<br> fclose(fp);<br> return;<br> }
printf("please input the number of the student which do you want to modify!\n");
scanf("%d",&snum);
for(i=0;i<m;i++)
if(snum==stu[i].num)/*检索记录中是否有要修改的信息*/
break;
printf("find the student!you can modify!\n");
printf("name:\n");
scanf("%s",stu[i].name);/*输入名字*/
printf("\nelective:");
scanf("%lf",&stu[i].elec);/*输入选修课成绩*/
printf("\nexperiment:");
scanf("%lf",&stu[i].expe);/*输入实验课成绩*/
printf("\nrequired course:");
scanf("%lf",&stu[i].requ);/*输入必修课成绩*/
stu[i].sum=stu[i].elec+stu[i].expe+stu[i].requ;
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(j=0;j<m;j++)
if(fwrite(&stu[j] ,LEN,1,fp)!=1)
{ printf("can not save!"); getch(); }
fclose(fp);
}void insert()
{ FILE *fp;
int i,j,k,m=0,snum;
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1) m++;
if(m==0) {printf("no record!\n");<br> fclose(fp);<br> return;<br> }
printf("please input position where do you want to insert!(input the number)\n");
scanf("%d",&snum);
for(i=0;i<m;i++)
if(snum==stu[i].num)
break;
for(j=m-1;j>i;j--)
stu[j+1]=stu[j];
printf("now please input the new information.\n");
printf("number:");
scanf("%d",&stu[i+1].num);
for(k=0;k<m;k++)
if(stu[k].num==stu[i+1].num)
{
printf("the number is existing,press any to continue!");
getch();
fclose(fp);
return;
}
printf("name:\n");
scanf("%s",stu[i+1].name);
printf("\nelective:");
scanf("%lf",&stu[i+1].elec);
printf("\nexperiment:");
scanf("%lf",&stu[i+1].expe);
printf("\nrequired course:");
scanf("%lf",&stu[i+1].requ);
stu[i+1].sum=stu[i+1].elec+stu[i+1].expe+stu[i+1].requ;
if((fp=fopen("data.txt","wb"))==NULL)
{ printf("can not open\n");return;}
for(k=0;k<=m;k++)
if(fwrite(&stu[k] ,LEN,1,fp)!=1)
{ printf("can not save!"); getch(); }
fclose(fp);
}void total()
{ FILE *fp;
int m=0;
if((fp=fopen("data.txt","r+"))==NULL)
{ printf("can not open\n");return;}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1)
m++;
if(m==0) {printf("no record!\n");fclose(fp);return;}
printf("the class are %d students!\n",m);
fclose(fp);
}