c语言程序设计成绩管理
❶ 学生成绩管理程序设计(c语言)
测试过了
/*头文件*/
#include <stdio.h>
#include<dos.h>
#include<stdlib.h> /*其它说明*/
#include<string.h> /*字符串函数*/
#include<memory.h> /*内存操作函数*/
#include<ctype.h> /*字符操作函数*/
#include "conio.h"
#define LEN sizeof(STUDENT)
typedef struct stu /*定义结构体数组用于缓存数据*/
{char num[6];
char name[5];
int score[3];
int sum;
float average;
int order;
struct stu *next;
}STUDENT;
/*函数原型*/
STUDENT *init(); /*初始化函数*/
int menu_select(); /*菜单函数*/
STUDENT *create(); /*创建链表*/
void print(STUDENT *head); /* 显示全部记录*/
void search(STUDENT *head); /*查找记录*/
STUDENT *mydelete(STUDENT *head); /*删除记录*/
STUDENT *sort(STUDENT *head); /*排序*/
STUDENT *insert(STUDENT *head,STUDENT *mynew); /*插入记录*/
void save(STUDENT *head); /*保存文件*/
STUDENT *load(); /*读文件*/
/*主函数界面*/
void main()
{STUDENT *head,mynew;
head=init(); /*链表初始化,使head的值为NULL*/
for(;;) /*循环无限次*/
{switch(menu_select())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:search(head);break;
case 4:head=mydelete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,&mynew);break; /*&mynew表示返回地址*/
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0); /*如菜单返回值为9则程序结束*/
}
}
}
/*初始化函数*/
STUDENT *init()
{
return NULL; /*返回空指针*/
}
/*菜单选择函数*/
menu_select()
{int n;
printf("\n按任一键进入主菜单...... \npress any key to enter the menu......"); /*按任一键进入主菜单*/
getch(); /*从键盘读取一个字符,但不显示于屏幕*/
system("cls");
printf("********************************************************************************\n");
printf("\t\t 欢迎 Welcome to\n");
printf("\n\t\t\t 使用学生管理系统1.0\n\n\t\t\t\t\t\n");
printf("*************************************MENU***************************************\n");
printf("\t\t\t1. 输入学生成绩记录 Enter the record\n"); /*输入学生成绩记录*/
printf("\t\t\t2. 显示 Print the record\n"); /*显示*/
printf("\t\t\t3. 寻找 Search record on name\n"); /*寻找*/
printf("\t\t\t4. 删除 mydelete a record\n"); /*删除*/
printf("\t\t\t5. 排序 Sort to make mynew a file\n"); /*排序*/
printf("\t\t\t6. 插入 Insert record to list\n"); /*插入*/
printf("\t\t\t7. 保存 Save the file\n"); /*保存*/
printf("\t\t\t8. 读取 Load the file\n"); /*读取*/
printf("\t\t\t9. 退出 Quit\n"); /*退出*/
printf("********************************************************************************\n");
do{
printf("\n\t\t\t输入你的选择Enter your choice(1~9):");
scanf("%d",&n);
}while(n<1||n>9); /*如果选择项不在1~9之间则重输*/
return(n); /*返回选择项,主函数根据该数调用相应的函数*/
}
/*输入函数*/
STUDENT *create()
{int i,s;
STUDENT *head=NULL,*p; /* 定义函数.此函数带回一个指向链表头的指针*/
system("cls");
for(;;)
{p=(STUDENT *)malloc(LEN); /*开辟一个新的单元*/
if(!p) /*如果指针p为空*/
{printf("\n输出内存溢出. Out of memory."); /*输出内存溢出*/
return (head); /*返回头指针,下同*/
}
printf("输入学号Enter the num(0:list end):");
scanf("%s",p->num);
if(p->num[0]=='0') break; /*如果学号首字符为0则结束输入*/
printf("输入名字Enter the name:");
scanf("%s",p->name);
printf("请输入3门成绩Please enter the %d scores\n",3); /*提示开始输入成绩*/
s=0; /*计算每个学生的总分,初值为0*/
for(i=0;i<3;i++) /*3门课程循环3次*/
{
do{
printf("成绩score%d:",i+1);
scanf("%d",&p->score[i]);
if(p->score[i]<0 || p->score[i]>100) /*确保成绩在0~100之间*/
printf("数据错误,请重新输入 Data error,please enter again.\n");
}while(p->score[i]<0 || p->score[i]>100);
s=s+p->score[i]; /*累加各门成绩*/
}
p->sum=s; /*将总分保存*/
p->average=(float)s/3; /*先用强制类型转换将s转换成float型,再求平均值*/
p->order=0; /*未排序前此值为0*/
p->next=head; /*将头结点做为新输入结点的后继结点*/
head=p; /*新输入结点为新的头结点*/
}
return(head);
}
/* 显示全部记录函数*/
void print(STUDENT *head)
{int i=0; /* 统计记录条数*/
STUDENT *p; /*移动指针*/
system("cls");
p=head; /*初值为头指针*/
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
while(p!=NULL)
{
i++;
printf("| %3d | %4s | %-4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
i, p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("-------------------------------------------------------------------------------\n");
printf("**************************************END**************************************\n");
}
/*查找记录函数*/
void search(STUDENT *head)
{STUDENT *p; /* 移动指针*/
char s[5]; /*存放姓名用的字符数组*/
system("cls");
printf("请输入个姓名来查找. Please enter name for searching.\n");
scanf("%s",s);
p=head; /*将头指针赋给p*/
while(strcmp(p->name,s) && p != NULL) /*当记录的姓名不是要找的,或指针不为空时*/
p=p->next; /*移动指针,指向下一结点*/
if(p!=NULL) /*如果指针不为空*/
{printf("\n*************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
}
else
printf("\n没有该学生 There is no num %s student on the list.\n",s); /*显示没有该学生*/
}
/*删除记录函数*/
STUDENT *mydelete(STUDENT *head)
{int n;
STUDENT *p1,*p2; /*p1为查找到要删除的结点指针,p2为其前驱指针*/
char c,s[6]; /*s[6]用来存放学号,c用来输入字母*/
system("cls");
printf("请输入要删除的学号 Please enter the mydeleted num: ");
scanf("%s",s);
p1=p2=head; /*给p1和p2赋初值头指针*/
while(strcmp(p1->num,s) && p1 != NULL) /*当记录的学号不是要找的,或指针不为空时*/
{p2=p1; /*将p1指针值赋给p2作为p1的前驱指针*/
p1=p1->next; /*将p1指针指向下一条记录*/
}
if(strcmp(p1->num,s)==0) /*学号找到了*/
{printf("**************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1->num,p1->name,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
printf("\n是否要删除,输入Y删除,N则退出\nAre you sure to mydelete the student Y/N ?"); /*提示是否要删除,输入Y删除,N则退出*/
for(;;)
{scanf("%c",&c);
if(c=='n'||c=='N') break; /*如果不删除,则跳出本循环*/
if(c=='y'||c=='Y')
{
if(p1==head) /*若p1==head,说明被删结点是首结点*/
head=p1->next; /*把第二个结点地址赋予head*/
else
p2->next=p1->next; /*否则将一下结点地址赋给前一结点地址*/
n=n-1;
printf("\n学号为(Num): %s 学生以被删除(student have been mydeleted.)\n",s);
printf("别忘了保存. Don't forget to save.\n");break; /*删除后就跳出循环*/
}
}
}
else
printf("\n没有这个学生在表上\nThere is no num %s student on the list.\n",s); /*找不到该结点*/
return(head);
}
/*排序函数*/
STUDENT *sort(STUDENT *head)
{int i=0; /*保存名次*/
STUDENT *p1,*p2,*t,*temp; /*定义临时指针*/
temp=head->next; /*将原表的头指针所指的下一个结点作头指针*/
head->next=NULL; /*第一个结点为新表的头结点*/
while(temp!=NULL) /*当原表不为空时,进行排序*/
{
t=temp; /*取原表的头结点*/
temp=temp->next; /*原表头结点指针后移*/
p1=head; /*设定移动指针p1,从头指针开始*/
p2=head; /*设定移动指针p2做为p1的前驱,初值为头指针*/
while(t->average<p1->average&&p1!=NULL) /*作成绩平均分比较*/
{
p2=p1; /*待排序点值小,则新表指针后移*/
p1=p1->next;
}
if(p1==p2) /*p1==p2,说明待排序点值大,应排在首位*/
{
t->next=p1; /*待排序点的后继为p*/
head=t; /*新头结点为待排序点*/
}
else /*待排序点应插入在中间某个位置p2和p1之间,如p为空则是尾部*/
{
t->next=p1; /*t的后继是p1*/
p2->next=t; /*p2的后继是t*/
}
}
p1=head; /*已排好序的头指针赋给p1,准备填写名次*/
while(p1!=NULL) /*当p1不为空时,进行下列操作*/
{
i++; /*结点序号*/
p1->order=i; /*将结点序号赋值给名次*/
p1=p1->next; /*指针后移*/
}
printf("排序成功 Sorting is sucessful.\n"); /*排序成功*/
return (head);
}
/*插入记录函数*/
STUDENT *insert(STUDENT *head,STUDENT *mynew)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head; /*使p1指向第一个结点*/
p0=mynew; /*p0指向要插入的结点*/
printf("\nPlease enter a mynew record.\n"); /*提示输入记录信息*/
printf("输入学号Enter the num:");
scanf("%s",mynew->num);
printf("输入名字Enter the name:");
scanf("%s",mynew->name);
printf("Please enter the %d scores.\n",3);
sum1=0; /*保存新记录的总分,初值为0*/
for(i=0;i<3;i++)
{
do{
printf("成绩score%d:",i+1);
scanf("%d",&mynew->score[i]);
if(mynew->score[i]>100||mynew->score[i]<0)
printf("数据错误Data error,please enter again.\n");
}while(mynew->score[i]>100||mynew->score[i]<0);
sum1=sum1+mynew->score[i]; /*累加各门成绩*/
}
mynew->sum=sum1; /*将总分存入新记录中*/
mynew->average=(float)sum1/3;
mynew->order=0;
if(head==NULL) /*原来的链表是空表*/
{head=p0;p0->next=NULL;} /*使p0指向的结点作为头结点*/
else
{while((p0->average<p1->average)&&(p1->next!=NULL))
{p2=p1; /*使p2指向刚才p1指向的结点*/
p1=p1->next; /*p1后移一个结点*/
}
if(p0->average>=p1->average)
{if(head==p1)head=p0; /*插到原来第一个结点之前*/
else p2->next=p0; /*插到p2指向的结点之后*/
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;} /*插到最后的结点之后*/
}
n=n+1; /*结点数加1*/
head=sort(head); /*调用排序的函数,将学生成绩重新排序*/
printf("\n学生Student %s 已被更新have been inserted.\n",mynew->name);
printf("不要忘了保存Don't forget to save the mynew file.\n");
return(head);
}
/*保存数据到文件函数*/
void save(STUDENT *head)
{FILE *fp; /*定义指向文件的指针*/
STUDENT *p; /* 定义移动指针*/
char outfile[10];
printf("输出文件例如:c:\\score Enter outfile name,for example c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"w"))==NULL) /*为输出打开一个二进制文件,为只写方式*/
{
printf("打不开文件Cannot open the file\n");
return; /*若打不开则返回菜单*/
}
printf("\n保存中...Saving the file......\n");
p=head; /*移动指针从头指针开始*/
while(p!=NULL) /*如p不为空*/
{
fwrite(p,LEN,1,fp); /*写入一条记录*/
p=p->next; /*指针后移*/
}
fclose(fp); /*关闭文件*/
printf("保存成功....Save the file successfully!\n");
}
/* 从文件读数据函数*/
STUDENT *load()
{STUDENT *p1,*p2,*head=NULL; /*定义记录指针变量*/
FILE *fp; /* 定义指向文件的指针*/
char infile[10];
printf("倒入文件例如:c:\\score Enter infile name,for example c:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"r"))==NULL) /*打开一个二进制文件,为只读方式*/
{
printf("打不开文件Can not open the file.\n");
return(head);
}
printf("\n寻找文件...Loading the file!\n");
p1=(STUDENT *)malloc(LEN); /*开辟一个新单元*/
if(!p1)
{
printf("内存溢出!Out of memory!\n");
return(head);
}
head=p1; /*申请到空间,将其作为头指针*/
while(!feof(fp)) /*循环读数据直到文件尾结束*/
{
if(fread(p1,LEN,1,fp)!=1) break; /*如果没读到数据,跳出循环*/
p1->next=(STUDENT *)malloc(LEN); /*为下一个结点开辟空间*/
if(!p1->next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1; /*使p2指向刚才p1指向的结点*/
p1=p1->next; /*指针后移,新读入数据链到当前表尾*/
}
p2->next=NULL; /*最后一个结点的后继指针为空*/
fclose(fp);
printf("\n你成功的从文件中读取了数据!\nYou have success to read data from the file!\n");
return (head);
}
❷ c语言设计学生成绩管理程序
#include<stdio.h>
#include<memory.h>
#include<stdlib.h>
#include<string.h>
chargrades[5][10]={"语文","数学","英语","总成绩","平均成绩"};
typedefstructdata{
charnumber[16];
charname[20];
doublescore[5];
}dataType;
typedefstructlist{
dataTypepauline;
structlist*next;
}*LinkList,*pNode,Node;
void*getMemory(size_tsize){
returnmalloc(size);
}
LinkListgetEmptyList(){
LinkListhead=(pNode)getMemory(sizeof(Node));
memset(head,0,sizeof(Node));
returnhead;
}
intaddNode(LinkListhead,pNodepnode){
pNodeq;
for(q=head;q->next;q=q->next)
if(strcmp(q->next->pauline.number,pnode->pauline.number)==0){
printf("重复的学号:%d ",pnode->pauline.number);
return0;
}
q->next=pnode;
pnode->next=NULL;
return1;
}
//按学号升排序
voidsortNumber(LinkListhead){
pNodep,q,pt,qt;
p=head;
while(p->next){
qt=p;
q=p->next;
while(q->next){
if(strcmp(qt->next->pauline.number,q->pauline.number)>0)
qt=q;
q=q->next;
}
if(qt!=p){
pt=p->next;
p->next=qt->next;
qt->next=qt->next->next;
p->next->next=pt;
}
p=p->next;
}
}
//按第th门成绩降排序,th=1,2,3,4,5
voidsortScore(LinkListhead,intth){
pNodep,q,pt,qt;
inti;
if(th<1||th>5)return;
i=th-1;
for(p=head;p->next;p=p->next){
qt=p;
q=p->next;
while(q->next){
if(qt->next->pauline.score[i]<q->next->pauline.score[i])
qt=q;
q=q->next;
}
if(qt!=p){
pt=p->next;
p->next=qt->next;
qt->next=qt->next->next;
p->next->next=pt;
}
}
}
voidshow(LinkListhead){
inti;
pNodep;
for(p=head->next;p;p=p->next){
printf("%s %s ",p->pauline.number,p->pauline.name);
for(i=0;i<5;++i)
printf("%.2f ",p->pauline.score[i]);
printf(" ");
}
}
pNodereadData(){
pNodepnode=(pNode)getMemory(sizeof(Node));
inti;
printf("学号:");
scanf("%s",pnode->pauline.number);
printf("姓名:");
scanf("%s",pnode->pauline.name);
pnode->pauline.score[3]=0;
for(i=0;i<3;++i){
printf("%s成绩:",grades[i]);
scanf("%lf",&pnode->pauline.score[i]);
pnode->pauline.score[3]+=pnode->pauline.score[i];
}
pnode->pauline.score[4]=pnode->pauline.score[3]/3.0;
returnpnode;
}
voidmenu(){
printf("******************************** ");
printf("******学生成绩管理系统****** ");
printf("******************************** ");
printf("*1、添加学生信息* ");
printf("*2、显示学生信息* ");
printf("*3、按学号排序* ");
printf("*4、按成绩排序* ");
printf("******************************** ");
printf("*0、退出* ");
printf("******************************** ");
}
intmain(){
charop[20];
intselect;
LinkListhead=getEmptyList();
do{
menu();
printf("请选择:");
fflush(stdin);
fgets(op,20,stdin);
fflush(stdin);
switch(op[0]-'0'){
case1:addNode(head,readData());break;
case2:show(head);break;
case3:sortNumber(head);break;
case4:printf("按第几门功课排序;");
scanf("%d",&select);
sortScore(head,select);
break;
}
}while(op[0]-'0');
printf("END ");
return0;
}
❸ C语言程序设计学生成绩管理系统
#include <stdio.h>
#include <stdlib.h>
int stu[3][3];
void input( )//定义input函数,输入学生成绩
{
int score;
int i;
int j;
for( i=1;i<4;i++)
{
printf("请输入第%d个学生三门课程的成绩:",i);
for(j=0;j<3;j++)
{
scanf("%d",&score);
stu[i][j]=score;
}
}
}
void update( )//定义update函数,修改学生成绩
{
//请补充完整
int a,i, j,b,score;
printf("i would like to ask you a question,how many students you want to change:");
scanf("%d", &a);
for(b = 1; b <= a; b++)
{
printf("who is you want to change:");
scanf("%d",&i);
printf("\n what mark you want to change:");
scanf("%d",&j);
printf("\n input mark:");
scanf("%d", &score);
stu[i-1][j-1]=score;
}
}
void print( )//定义print函数,打印成绩单
{
//请补充完整
int score;
int i;
int j;
for( i=1;i<4;i++)
{
for(j=0;j<3;j++)
{
score = stu[i][j];
printf("第%d个学生第%d门课程的成绩:%d\n", i+1, j+1, score);
}
}
}
int main( )
{
int n;
do{
printf("1.输入学生成绩\n");
printf("2.修改学生的成绩\n");
printf("3.打印学生的成绩单\n");
printf("请输入要选择的功能:");
scanf("%d",&n);
if(n==1)
{
input( );
}
if(n==2)
{
update( );
}
if(n==3)
{
print( );
}
}while(n != 4);
system("pause");
return 0;
}
❹ c语言编写查询学生成绩管理程序。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>struct record
{
char xuehao[10];//学号
char name[20]; //姓名
char sex[3];//性别
int ke1;//数学
int ke2 ;//语文
int ke3;//英语
int pin;
}stu[50];
int k=1,n,m;void readfile();
void seek();
void insert();
void del();
void save();
void menu();
void seek()
{int i,j,item,flag;<br>char s1[20];<br>printf("------------------\n");<br>printf("1.按学号查询\n");<br>printf("2.退出本菜单\n");<br>printf("------------------\n");<br>while(1)<br>{ printf("请选择子菜单编号:");<br>scanf("%d",&item);<br>flag=0;<br>switch(item)<br>{<br>case 1:<br>printf("请输入要查询的学生的学号:\n");<br>scanf("%s",s1);<br>for(i=0;i<n;i++)<br>if(strcmp(stu[i].xuehao,s1)==0)<br>{ flag=1;<br>printf("该学生学号,姓名,性别,数学,语文,英语 分别为:\n");<br>printf(" %s %s %s %d %d %d",stu[i].xuehao,stu[i].name,<br>stu[i].sex,stu[i].ke1,stu[i].ke2,stu[i].ke3);<br>}
if(flag==0)
printf("该学号不存在!\n"); break;
case 2:return;
default:printf("请在1-2之间选择\n");
}
}
}
void insert()
{ int i=n,j,flag;
printf("请输入待增加的学生数:\n");
scanf("%d",&m);
do
{ flag=1;
while(flag)
{ flag=0;
printf("请输入第 %d 个学生的学号:\n",i+1);
scanf("%s",stu[i].xuehao);
for(j=0;j<i;j++)
if(strcmp(stu[i].xuehao,stu[j].xuehao)==0)
{ printf("已有该学号,请检查后重新录入!\n");
flag=1;
break;
}
}
printf("请输入第 %d 个学生的姓名:",i+1);
scanf("%s",stu[i].name);
printf("\n请输入第 %d 个学生的性别:",i+1);
scanf("%s",stu[i].sex);
printf("\n请输入第 %d 个学生的数学成绩:",i+1);
scanf("%d",&stu[i].ke1);
printf("\n请输入第 %d 个学生的语文成绩:",i+1);
scanf("%d",&stu[i].ke2);
printf("\n请输入第 %d 个学生的英语成绩:",i+1);
scanf("%d",&stu[i].ke3);if(flag==0)
{ i=i;
i++;
}
}while(i<n+m);
n+=m;
printf("录入完毕!\n\n");
}void del()
{ int i,j,flag=0;
char s1[20];
printf("请输入要删除学生的学号:\n");
scanf("%s",s1);
for(i=0;i<n;i++)
if(strcmp(stu[i].xuehao,s1)==0)
{ flag=1;
for(j=i;j<n-1;j++)
stu[j]=stu[j+1];
}
if(flag==0)
printf("该学号不存在!\n");
if(flag==1)
{ printf("删除成功,显示结果请选择菜单6\n");
n--;
}
}
void readfile()
{
char buf[80],*p="student.dat";
FILE *fp;
int i=0;
if ((fp=fopen("student.dat","r"))==NULL)
{ printf("Open file %s error! Strike any key to exit!",p);
system("pause");
exit(0);
}
while(fscanf(fp,"%s%s%s%d%d%d",stu[i].xuehao,stu[i].name,
stu[i].sex,&stu[i].ke1,&stu[i].ke2,&stu[i].ke3)==6)
{ i++;
i=i;
}
fclose(fp);
n=i;
printf("录入完毕!\n");
}void save()
{ int i,j,k,flag=0;
FILE *fp;
fp=fopen("student.dat","w");
for(i=0;i<m;i++)
{
fprintf(fp,"%s%s%d%d%d",stu[i].xuehao,stu[i].name,stu[i].sex,&stu[i].ke1,
&stu[i].ke2,&stu[i].ke3);
fclose(fp);
printf("已储存");
}
}
void paixu()
{
int i,j,k,t;
for(i=0;i<m;i++)
{
stu[i].pin=(stu[i].ke1+stu[i].ke2+stu[i].ke3)/3;
}
for(i=0;i<=m-2;i++)
{
k=i;
for(j=i+1;j<=m-1;j++)
if(stu[j].pin<stu[k].pin)
k=j;
if(k!=i)
{
t=stu[k].pin;
stu[k].pin=stu[i].pin;
stu[i].pin=t;
}
}
for(i=0;i<m;i++)
{printf("第 %d 个学生的姓名%s:",i+1,stu[i].name);<br> printf("\n第 %d 个学生的性别:%s",i+1,stu[i].sex);<br> printf("\n第 %d 个学生的数学成绩:%d",i+1,stu[i].ke1);<br> printf("\n第 %d 个学生的语文成绩:%d",i+1,stu[i].ke2);<br> printf("\n第 %d 个学生的英语成绩:%d",i+1,stu[i].ke3);<br> printf("\n第 %d 个学生的平均成绩:%d",i+1,stu[i].pin);<br> }
}
void menu()
{ int nub;
printf(" \n\n学生成绩管理系统\n\n");
printf("*****系统功能菜单*****\n");
printf("----------------------\n");
printf("1.输入学生信息\n");
printf("2.查询学生信息\n");
printf("3.按学号删除信息\n");
printf("4.读入学生信息\n");
printf("5.保存信息(要把修改保存到文件,退出程序前必须执行本项)\n");
printf("6.查询学生平均成绩信息\n");
printf("0.退出系统\n");
printf("----------------------\n");
printf("请选择菜单编号:");
scanf("%d",&nub);
switch(nub)
{
case 1:insert();break;
case 2:seek();break;
case 3:del();break;
case 4:readfile();break;
case 5:save();break;
case 6:paixu();break;
case 0:k=0;break;
default:printf("请在0-6之间选择\n");
}}
void main()
{
while(k)
menu();
}
//平均数是排序后,输出的,如果你不想直接输入,那就不要对每个学生进行选择排序了
❺ 用C语言设计一个学生成绩管理系统
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#defineMAX1000
/*定义学生成绩信息结构*/
struct stu
{
char id[8];
char name[8];
(5)c语言程序设计成绩管理扩展阅读:
short:修饰int,短整型数据,可省略被修饰的int。(K&R时期引入)
long:修饰int,长整型数据,可省略被修饰的int。(K&R时期引入)
long long:修饰int,超长整型数据,可省略被修饰的int。(C99标准新增)
signed:修饰整型数据,有符号数据类型。(C89标准新增)
unsigned:修饰整型数据,无符号数据类型。(K&R时期引入)
restrict:用于限定和约束指针,并表明指针是访问一个数据对象的唯一且初始的方式。(C99标准新增)
复杂类型关键字
struct:结构体声明。(K&R时期引入)
union:联合体声明。(K&R时期引入)
enum:枚举声明。(C89标准新增)
typedef:声明类型别名。(K&R时期引入)
sizeof:得到特定类型或特定类型变量的大小。(K&R时期引入)
inline:内联函数用于取代宏定义,会在任何调用它的地方展开。(C99标准新增)
❻ 用C语言编写一个简单的成绩管理系统
(ps:没有自己编译过)
//我写 C++比较多
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define TOTAL_STUD 1000
typedef struct stud {
char name[20];
int score;
} students[TOTAL_STUD],sorted[TOTAL_STUD];
void delstud (int i) {
students[i].name = "无效学生";
students[i].score = -999;
return;
}
#define show(listname,i)printf("%04d%s%d ",i,listname[i].name,listname[i].score);
int cmpfunc (const void * a, const void * b)
{
return ( *(stud*)a.score - *(stud*)b.score );
} // 本段代码修改自此处
void run(int menu) {
switch (menu) {
case 1:
char uname[20];
int uid,uscore;
printf("请输入学生姓名:");
scanf("%s",uname);
printf("
请输入学生学号:");
scanf("%d",&uid);
printf("
请输入学生成绩:");
scanf("%d",&uscore);
students[uid].name = uname;
students[uid].score = uscore;
printf("
插入成功!
");
break;
case 2:
int delid;
printf("要删除谁?学号?");
scanf("%d",&delid);
delstud(delid);
break;
case 3:
for (int i = 0; i < TOTAL_STUD; i++) {
strcpy(sorted[i].name,students[i].name);
sorted[i].score=students[i].score;
}
qsort(sorted,TOTAL_STUD,sizeof(stud),cmpfunc);
printf("学号 姓名 分数
");
for (int i = 0; i < TOTAL_STUD; i++) {
if (sorted[i].score > -900) show(sorted,i);
}
break;
case 4:
for (int i = 0; i < TOTAL_STUD; i++) {
if (students[i].score > -900) show(students,i);
}
break;
case 5:
int delid;
printf("要查询谁?学号?");
scanf("%d",&delid);
show(students,delid);
break;
default:
printf("-- %d 无此功能。请重试。--",menu);
}
return;
}
int main() {
int key = -1;
for (int i = 0; i < TOTAL_STUD; i++) {
delstud(i);
}
while (key != 0) {
printf("---成绩管理系统 V0.9 --- 请选择: 1 -- 录入 2 -- 删除 3 -- 排序输出 4 -- 不排序输出 5 -- 查询 0 -- 退出");
key=getch()-48;
if (key>0) run(key);
else {
printf("谢谢使用!再见!");
return 0;
}
}
return 0;
}
❼ C语言程序设计 题目:学生成绩管理
#include <stdio.h>
#include <alloc.h>
#include <string.h>
#define STUNUMBER 10
typedef struct student
{
int id;
char name[15];
float math;
float english;
float java;
float basic;
float average;
}STUDENT;
void input(void);
void list(void);
void score(void);
void inquire(void);
int main(void)
{
char ch='c';
clrscr();
input();
system("pause");
while(ch!='/')
{
clrscr();
list();
score();
system("pause");
clrscr();
inquire();
printf("\n\ncontinue ...[any key]\n");
printf("exit ...[/]\n");
ch=getch();
}
return(0);
}
void input(void)
{
STUDENT *stu=(STUDENT *)malloc(STUNUMBER*sizeof(STUDENT));
FILE *fp;
int id;
char name[15];
float math;
float english;
float java;
float basic;
int count=0;
fp=fopen("stu.dat","w+");
if(fp==NULL)
{
printf("can't open stu.dat...");
getch();
exit(1);
}
for(count=0;count<STUNUMBER;count++)
{
printf("input the information of student%d\n",count+1);
printf("ID:");
scanf("%d",&id);
printf("\nName:");
scanf("%s",name);
printf("\nMath score:");
scanf("%f",&math);
printf("\nEnglish score:");
scanf("%f",&english);
printf("\nJava score:");
scanf("%f",&java);
printf("\nBasic of computer application score:");
scanf("%f",&basic);
stu[count].id=id;
strcpy(stu[count].name,name);
stu[count].math=math;
stu[count].english=english;
stu[count].java=java;
stu[count].basic=basic;
}
fwrite(stu,STUNUMBER*sizeof(STUDENT),1,fp);
free(stu);
fclose(fp);
}
void list(void)
{
FILE *fp;
STUDENT *stu=(STUDENT *)malloc(STUNUMBER*sizeof(STUDENT));
STUDENT *temp=(STUDENT *)malloc(sizeof(STUDENT));
int count=0;
int i,j;
fp=fopen("stu.dat","r+");
if(fp==NULL)
{
printf("can't open stu.dat...");
getch();
exit(1);
}
fread(stu,STUNUMBER*sizeof(STUDENT),1,fp);
for(count=0;count<STUNUMBER;count++)
{
stu[count].average=(stu[count].math+stu[count].english+stu[count].java+stu[count].basic)/4;
}
for (i=0;i<STUNUMBER;i++)
{
for (j=i+1;j<STUNUMBER;j++)
{
if (stu[i].average<stu[j].average)
{
temp->id=stu[j].id;
strcpy(temp->name,stu[j].name);
temp->math=stu[j].math;
temp->english=stu[j].english;
temp->java=stu[j].java;
temp->basic=stu[j].basic;
temp->average=stu[j].average;
stu[j].id=stu[i].id;
strcpy(stu[j].name,stu[i].name);
stu[j].math=stu[i].math;
stu[j].english=stu[i].english;
stu[j].java=stu[i].java;
stu[j].basic=stu[i].basic;
stu[j].average=stu[i].average;
stu[i].id=temp->id;
strcpy(stu[i].name,temp->name);
stu[i].math=temp->math;
stu[i].english=temp->english;
stu[i].java=temp->java;
stu[i].basic=temp->basic;
stu[i].average=temp->average;
}
}
}
printf("ID\tName\tMath English Java ComputerBasic Average\n");
for(count=0;count<STUNUMBER;count++)
{
printf("%-8d",stu[count].id);
printf("%-8s",stu[count].name);
printf("%-6.1f",stu[count].math);
printf("%-9.1f",stu[count].english);
printf("%-6.1f",stu[count].java);
printf("%-15.1f",stu[count].basic);
printf("%-13.1f\n",stu[count].average);
}
rewind(fp);
fwrite(stu,STUNUMBER*sizeof(STUDENT),1,fp);
free(temp);
free(stu);
fclose(fp);
}
void score(void)
{
int count=0;
float avem=0,avee=0,avej=0,aveb=0;
float maxm=0,maxe=0,maxj=0,maxb=0;
float minm=1000,mine=1000,minj=1000,minb=1000;
FILE *fp;
STUDENT *stu=(STUDENT *)malloc(STUNUMBER*sizeof(STUDENT));
fp=fopen("stu.dat","r");
if(fp==NULL)
{
printf("can't open stu.dat...");
getch();
exit(1);
}
fread(stu,STUNUMBER*sizeof(STUDENT),1,fp);
for(count=0;count<STUNUMBER;count++)
{
avem+=stu[count].math;
avee+=stu[count].english;
avej+=stu[count].java;
aveb+=stu[count].basic;
}
avem=avem/STUNUMBER;
avee=avee/STUNUMBER;
avej=avej/STUNUMBER;
aveb=aveb/STUNUMBER;
for(count=0;count<STUNUMBER;count++)
{
if(stu[count].math>maxm) maxm=stu[count].math;
if(stu[count].english>maxe) maxe=stu[count].english;
if(stu[count].java>maxj) maxj=stu[count].java;
if(stu[count].basic>maxb) maxb=stu[count].basic;
}
for(count=0;count<STUNUMBER;count++)
{
if(stu[count].math<minm) minm=stu[count].math;
if(stu[count].english<mine) mine=stu[count].english;
if(stu[count].java<minj) minj=stu[count].java;
if(stu[count].basic<minb) minb=stu[count].basic;
}
printf("\n\n\t Math English Java ComputerBasic\n");
printf("average %-6.1f%-9.1f%-6.1f%-6.1f\n",avem,avee,avej,aveb);
printf("max %-6.1f%-9.1f%-6.1f%-6.1f\n",maxm,maxe,maxj,maxb);
printf("min %-6.1f%-9.1f%-6.1f%-6.1f\n",minm,mine,minj,minb);
free(stu);
fclose(fp);
}
void inquire(void)
{
FILE *fp;
char name[15];
int count=0;
STUDENT *stu=(STUDENT *)malloc(STUNUMBER*sizeof(STUDENT));
fp=fopen("stu.dat","r");
if(fp==NULL)
{
printf("can't open stu.dat...");
getch();
exit(1);
}
fread(stu,STUNUMBER*sizeof(STUDENT),1,fp);
printf("input the name you want to inquire:");
scanf("%s",name);
while(strcmp(name,stu[count].name)!=0)
{
count++;
if(count==STUNUMBER)
{
printf("No the student!\n");
getch();
exit(0);
}
}
printf("ID\tName\tMath English Java ComputerBasic Average score\n");
printf("%-8d",stu[count].id);
printf("%-8s",stu[count].name);
printf("%-6.1f",stu[count].math);
printf("%-9.1f",stu[count].english);
printf("%-6.1f",stu[count].java);
printf("%-15.1f",stu[count].basic);
printf("%-13.1f\n",stu[count].average);
free(stu);
fclose(fp);
}
❽ 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语言学生成绩管理程序
#include"stdio.h"
/*定义学生结构体*/
structStudent
{
charID[20];
charName[20];
floatMark1;
floatMark2;
floatMark3;
floatAverage;
};
/*声明学生数组及学生数量*/
structStudentstudents[1000];
intnum=0;
/*求平均值*/
floatAvg(structStudentstu)
{
return(stu.Mark1+stu.Mark2+stu.Mark3)/3;
}
/*通过学号返回数组下标*/
intStudent_SearchByIndex(charid[])
{
inti;
for(i=0;i<num;i++)
{
if(strcmp(students[i].ID,id)==0)
{
returni;
}
}
return-1;
}
/*通过姓名返回数组下标*/
intStudent_SearchByName(charname[])
{
inti;
for(i=0;i<num;i++)
{
if(strcmp(students[i].Name,name)==0)
{
returni;
}
}
return-1;
}
/*显示单条学生记录*/
voidStudent_DisplaySingle(intindex)
{
printf("%10s%10s%8s%8s%8s%10s ","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("------------------------------------------------------------- ");
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f ",students[index].ID,students[index].Name,
students[index].Mark1,students[index].Mark2,students[index].Mark3,students[index].Average);
}
/*插入学生信息*/
voidStudent_Insert()
{
while(1)
{
printf("请输入学号:");
scanf("%s",&students[num].ID);
getchar();
printf("请输入姓名:");
scanf("%s",&students[num].Name);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num].Mark1);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num].Mark2);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num].Mark3);
getchar();
students[num].Average=Avg(students[num]);
num++;
printf("是否继续?(y/n)");
if(getchar()=='n')
{
break;
}
}
}
/*修改学生信息*/
voidStudent_Modify()
{
floatmark1,mark2,mark3;
while(1)
{
charid[20];
intindex;
printf("请输入要修改的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if(index==-1)
{
printf("学生不存在! ");
}
else
{
printf("你要修改的学生信息为: ");
Student_DisplaySingle(index);
printf("--请输入新值-- ");
printf("请输入学号:");
scanf("%s",&students[index].ID);
getchar();
printf("请输入姓名:");
scanf("%s",&students[index].Name);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index].Mark1);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index].Mark2);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index].Mark3);
getchar();
students[index].Average=Avg(students[index]);
}
printf("是否继续?(y/n)");
if(getchar()=='n')
{
break;
}
}
}
/*删除学生信息*/
voidStudent_Delete()
{
inti;
while(1)
{
charid[20];
intindex;
printf("请输入要删除的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if(index==-1)
{
printf("学生不存在! ");
}
else
{
printf("你要删除的学生信息为: ");
Student_DisplaySingle(index);
printf("是否真的要删除?(y/n)");
if(getchar()=='y')
{
for(i=index;i<num-1;i++)
{
students[i]=students[i+1];
}
num--;
}
getchar();
}
printf("是否继续?(y/n)");
if(getchar()=='n')
{
break;
}
}
}
/*按姓名查询*/
voidStudent_Select()
{
while(1)
{
charname[20];
intindex;
printf("请输入要查询的学生的姓名:");
scanf("%s",&name);
getchar();
index=Student_SearchByName(name);
if(index==-1)
{
printf("学生不存在! ");
}
else
{
printf("你要查询的学生信息为: ");
Student_DisplaySingle(index);
}
printf("是否继续?(y/n)");
if(getchar()=='n')
{
break;
}
}
}
/*按平均值排序*/
voidStudent_SortByAverage()
{
inti,j;
structStudenttmp;
for(i=0;i<num;i++)
{
for(j=1;j<num-i;j++)
{
if(students[j-1].Average<students[j].Average)
{
tmp=students[j-1];
students[j-1]=students[j];
students[j]=tmp;
}
}
}
}
/*显示学生信息*/
voidStudent_Display()
{
inti;
printf("%10s%10s%8s%8s%8s%10s ","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("------------------------------------------------------------- ");
for(i=0;i<num;i++)
{
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f ",students[i].ID,students[i].Name,
students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Average);
}
}
/*将学生信息从文件读出*/
voidIO_ReadInfo()
{
FILE*fp;
inti;
if((fp=fopen("Database.txt","rb"))==NULL)
{
printf("不能打开文件! ");
return;
}
if(fread(&num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;i<num;i++)
{
fread(&students[i],sizeof(structStudent),1,fp);
}
}
fclose(fp);
}
/*将学生信息写入文件*/
voidIO_WriteInfo()
{
FILE*fp;
inti;
if((fp=fopen("Database.txt","wb"))==NULL)
{
printf("不能打开文件! ");
return;
}
if(fwrite(&num,sizeof(int),1,fp)!=1)
{
printf("写入文件错误! ");
}
for(i=0;i<num;i++)
{
if(fwrite(&students[i],sizeof(structStudent),1,fp)!=1)
{
printf("写入文件错误! ");
}
}
fclose(fp);
}
/*主程序*/
main()
{
intchoice;
IO_ReadInfo();
while(1)
{
/*主菜单*/
printf(" ------学生成绩管理系统------ ");
printf("1.增加学生记录 ");
printf("2.修改学生记录 ");
printf("3.删除学生记录 ");
printf("4.按姓名查询学生记录 ");
printf("5.按平均成绩排序 ");
printf("6.退出 ");
printf("请选择(1-6):");
scanf("%d",&choice);
getchar();
switch(choice)
{
case1:
Student_Insert();
break;
case2:
Student_Modify();
break;
case3:
Student_Delete();
break;
case4:
Student_Select();
break;
case5:
Student_SortByAverage();
Student_Display();
break;
case6:
exit();
break;
}
IO_WriteInfo();
}
}
❿ c语言程序设计(2) 学生成绩管理系统
你好,程序完成了吗