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

c语言学籍系统代码

发布时间: 2023-06-26 15:52:31

① 用c语言设计学生学籍管理系统

#include
#include
/*定义学生结构体*/
struct Student
{
char ID[20];
char Name[20];
float Mark1;
float Mark2;
float Mark3;
float Average;
};
/*声明学生数组及学生数量*/
struct Student students[1000];
int num=0;
/*求平均值*/
float Avg(struct Student stu)
{
return (stu.Mark1+stu.Mark2+stu.Mark3)/3;
}
/*通过学号返回数组下标*/
int Student_SearchByIndex(char id[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students[i].ID,id)==0)
{
return i;
}
}
return -1;
}
/*通过姓名返回数组下标*/
int Student_SearchByName(char name[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students[i].Name,name)==0)
{
return i;
}
}
return -1;
}
/*显示单条学生记录*/
void Student_DisplaySingle(int index)
{
printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[index].ID,students[index].Name,
students[index].Mark1,students[index].Mark2,students[index].Mark3,students[index].Average);
}
/*插入学生信息*/
void Student_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;
}
}
}
/*修改学生信息*/
void Student_Modify()
{
//float mark1,mark2,mark3;
while(1)
{
char id[20];
int index;
printf("请输入要修改的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要修改的学生信息为:\n");
Student_DisplaySingle(index);
printf("-- 请输入新值--\n");
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;
}
}
}
/*删除学生信息*/
void Student_Delete()
{
int i;
while(1)
{
char id[20];
int index;
printf("请输入要删除的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要删除的学生信息为:\n");
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;
}
}
}
/*按姓名查询*/
void Student_Select()
{
while(1)
{
char name[20];
int index;
printf("请输入要查询的学生的姓名:");
scanf("%s",&name);
getchar();
index=Student_SearchByName(name);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要查询的学生信息为:\n");
Student_DisplaySingle(index);
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*按平均值排序*/
void Student_SortByAverage()
{
int i,j;
struct Student tmp;
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;
}
}
}
}
/*显示学生信息*/
void Student_Display()
{
int i;
printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------\n");
for (i=0;i<num;i++)
{
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[i].ID,students[i].Name,
students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Average);
}
}
/*将学生信息从文件读出*/
void IO_ReadInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","rb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fread(&num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;i<num;i++)
{
fread(&students[i],sizeof(struct Student),1,fp);
}
}
fclose(fp);
}
/*将学生信息写入文件*/
void IO_WriteInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","wb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fwrite(&num,sizeof(int),1,fp)!=1)
{
printf("写入文件错误!\n");
}
for (i=0;i<num;i++)
{
if (fwrite(&students[i],sizeof(struct Student),1,fp)!=1)
{
printf("写入文件错误!\n");
}
}
fclose(fp);
}
/*主程序*/
void main()
{
int choice;
IO_ReadInfo();
while(1)
{
/*主菜单*/
printf("\n------ 学生成绩管理系统------\n");
printf("1. 增加学生记录\n");
printf("2. 修改学生记录\n");
printf("3. 删除学生记录\n");
printf("4. 按姓名查询学生记录\n");
printf("5. 按平均成绩排序\n");
printf("6. 退出\n");
printf("请选择(1-6):");
scanf("%d",&choice);
getchar();
switch(choice)
{
case 1:
Student_Insert();
break;
case 2:
Student_Modify();
break;
case 3:
Student_Delete();
break;
case 4:
Student_Select();
break;
case 5:
Student_SortByAverage();
Student_Display();
break;
case 6:
exit(0);
break;
}
IO_WriteInfo();
}
}

② 用c语言编写学生信息管理系统

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define N 200
int input(struct Student stu[N]);
void save(struct Student stu[N],int n);
int load(struct Student stu[N]);
void output(struct Student stu[N],int n);
int insert(struct Student stu_save[],int n);
void sort(struct Student stu_save[],int n);
void find(struct Student stu_save[],int n);
int delete_stu(struct Student stu_save[],int n);
typedef struct Student
{
char num[20];
char name[20];
char sex;
int age;
float score[3];
float tolscore;
float ave;
}STU;
int main()
{
int total=0,a;
STU stu[N];
printf("☆☆☆☆☆学籍管理系统☆☆☆☆☆\n\n");
do{
printf("\n**********************************\n");
printf("1-导入学生信息\n2-加载学生信息\n3-保存学生信息\n4-按学号插入学生\n5-给学生排序\n6-查找学生\n7-删除学生\n8-输出当前学生数据\n9-退出\n");
printf("**********************************\n");
printf("请按键选择:");
scanf("%d",&a);
switch(a)
{
case 1:

total=input(stu);
break;
case 2: total=load(stu);break;
case 3:save(stu,total);break;
case 4: total+=insert(stu,total);break;
case 5:sort(stu,total);break;
case 6:find(stu,total);break;
case 7:total-=delete_stu(stu,total);break;
case 8:output(stu,total);break;
case 9:exit(0);break;
default:printf("输入错误,请重新输入!\n");break;
}
//system("cls");
}while(1);
}
int input(struct Student stu[])
{
int i,j,n;
float sum;
printf("请输入要导入的学生人数\n");
scanf("%d",&n);
printf("请输入学生的学号、姓名、性别、年龄及三门课成绩\n");
for(i=0;i<n;i++)
{

scanf("%s",stu[i].num);
scanf("%s",stu[i].name);
scanf(" %c",&stu[i].sex); //%c前的空格用于接收上一个字符串后的空格、回车、制表符,etc
scanf("%d",&stu[i].age);
sum=0;
for(j=0;j<3;j++)
{
scanf("%f",&stu[i].score[j]);
sum+=stu[i].score[j];
}
stu[i].tolscore=sum;
stu[i].ave=sum/3.0f;
}

return (n);
}

void save(struct Student stu[],int n)
{
FILE *fp;
int i;
char filename[20];
printf("请输入文件名:");
scanf("%s",filename);
if(strchr(filename,'.')==NULL)
strcat(filename,".dat");
if((fp=fopen(filename,"wb"))==NULL)
{
printf("Cannot open this file\n");
system("pause");
return;
}
fwrite(&n,sizeof(int),1,fp);
for(i=0;i<n;i++)
fwrite(&stu[i],sizeof(struct Student),1,fp);
fclose(fp);
printf("保存成功!");
system("pause");
return;
}
int load(struct Student stu_save[])
{
FILE *fp;
int i,n;
char filename[20];
printf("请输入要加载的文件名: ");
//getchar();
scanf("%s",filename);
// gets(filename);
if(strchr(filename,'.')==NULL)
strcat(filename,".dat");
if((fp=fopen(filename,"rb"))==NULL)
{
printf("Cannot open this file\n");
system("pause");
return 0;
}
fread(&n,sizeof(int),1,fp);
for(i=0;i<n;i++)
fread(&stu_save[i],sizeof(struct Student),1,fp);
fclose(fp);
system("cls");
printf("文件加载成功!数据如下");
output(stu_save,n);
return n;
}
void output(struct Student stu_save[],int n)
{
int i,j;
// system("cls");
printf("\n学号\t姓名\t性别\t年龄\t成绩一\t成绩二\t成绩三\t总分\t平均分\n");
for(i=0;i<n;i++)
{
printf("%s\t",stu_save[i].num);
printf("%s\t",stu_save[i].name);
printf("%c\t",stu_save[i].sex);
printf("%d\t",stu_save[i].age);
for(j=0;j<3;j++)
printf("%g\t",stu_save[i].score[j]);
printf("%g\t",stu_save[i].tolscore);
printf("%.2f",stu_save[i].ave);
putchar(10);
}
system("pause");
return;
}
int insert(struct Student stu_save[],int n)
{
int i,j,num=0;
float sum=0;
struct Student s;
char flag;
if(n>200)
{
printf("空间已满,无法插入!\n");
return 0;
}
// load(stu_save,n-1);
do{

printf("\n请依次输入学号、姓名、性别、年龄及三门课成绩\n");
scanf("%s",s.num);
scanf("%s",s.name);
scanf(" %c",&s.sex); //%c前的空格用于接收上一个字符串后的空格、回车、制表符,etc
scanf("%d",&s.age);
for(j=0;j<3;j++)
scanf("%f",&s.score[j]);
sum=0;
for(j=0;j<3;j++)
sum+=s.score[j];
s.tolscore=sum;
s.ave=sum/3;
num++;
for(i=n+num-1;strcmp(stu_save[i-1].num,s.num)>0&&i>0;i--)
stu_save[i]=stu_save[i-1];
stu_save[i]=s;
printf("插入成功!");

fflush(stdin);
do
{
printf("继续插入?(y/n)");

flag=getch();
}while(flag!='y'&&flag!='n');
}while(flag=='y');

system("pause");
//save(stu_save,n);
return num;
}
void sort(struct Student stu_save[],int n)
{
int a,i,j;
struct Student t;
system("cls");
printf("\n1-按序号排序\n2-按成绩排序\n请选择:");
scanf("%d",&a);
while(a!=1&&a!=2)
{
printf("输入有误,请重新输入!\n");
scanf("%d",&a);
}
//load(stu_save,n);
if(a==1)
{
for(i=0;i<n-1;i++)
for(j=0;j<n-i-1;j++)
{
if(strcmp(stu_save[j].num,stu_save[j+1].num)>0)
{
t=stu_save[j];
stu_save[j]=stu_save[j+1];
stu_save[j+1]=t;
}
}
}
else
{
for(i=0;i<n-1;i++)
for(j=0;j<n-i-1;j++)
{
if(stu_save[j].ave<stu_save[j+1].ave)
{
t=stu_save[j];
stu_save[j]=stu_save[j+1];
stu_save[j+1]=t;
}
}
}
// save(stu_save,n);
printf("排序成功!\n");
output(stu_save,n);
return;
}
void find(struct Student stu_save[],int n)
{
char ch;
do{
int i,j,w=1;
char search[20];
//load(stu_save,n);
printf("请输入学生的学号或姓名");
scanf("%s",search);
for(i=0;i<n;i++)
{
if(strcmp(stu_save[i].num,search)==0||strcmp(stu_save[i].name,search)==0)
{
printf("查找成功,该学生的信息为:\n");
printf("%s\t",stu_save[i].num);
printf("%s\t",stu_save[i].name);
printf("%c\t",stu_save[i].sex);
printf("%d\t",stu_save[i].age);
for(j=0;j<3;j++)
printf("%g\t",stu_save[i].score[j]);
printf("%g\t",stu_save[i].tolscore);
printf("%.2f",stu_save[i].ave);
putchar(10);
w=0;
break;
}
}
if(w)
printf("查找失败\n");

do
{
printf("\n按Y继续查找,按N返回上级菜单\n");
ch=getch();
}while(ch!='y'&&ch!='n');
if(ch=='n')
return;
}while(ch=='y');
}
int delete_stu(struct Student stu_save[],int n)
{
int i,w=1;
char search[20];
// load(stu_save,n);
printf("\n请输入要删除学生的姓名或学号\n");
scanf("%s",search);
for(i=0;i<n;i++)
if(strcmp(stu_save[i].num,search)==0||strcmp(stu_save[i].name,search)==0)
{
w=0;
break;
}
if(w)
{
printf("无此学生!\n");
return 0;
}
for(;i<n-1;i++)
stu_save[i]=stu_save[i+1];
printf("删除成功!\n");
// save(stu_save,n-1);
return 1;
}

之前随便写的 忘了有没有调试 有问题再私信找我 采纳哦~~

③ C语言设计 学生学籍系统

#include"stdio.h"
#include"stdlib.h"
#include"string.h"
intshoudsave=0;/**/
structstudent
{
charnum[10];/*学号*/
charname[20];
charsex[4];
charyuan;
intban;
charneartime[10];/*最近更新时间*/
};

typedefstructnode
{
structstudentdata;
structnode*next;
}Node,*Link;

voidmenu()
{
printf("********************************************************************************");
printf(" 1登记学生资料 2删除学生资料 ");
printf(" 3查询学生资料 4修改学生资料 ");
printf(" 5保存学生资料 0退出系统 ");
printf("******************************************************************************** ");
}

voidprintstart()
{
printf("----------------------------------------------------------------------- ");
}
voidWrong()
{
printf(" =====>提示:输入错误! ");
}

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

voidprintc()/*本函数用于输出中文*/
{
printf("学号 姓名性别学院班级 ");
}

voidprinte(Node*p)/*本函数用于输出英文*/
{
printf("%-12s%s %s %c %d ",p->data.num,p->data.name,p->data.sex,p->data.yuan,p->data.ban);
}

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

voidAdd(Linkl)/*增加学生*/
{
Node*p,*r,*s;
charnum[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修改'! ",num);
printstart();
printc();
printe(s);
printstart();
printf(" ");
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("请你输入学院:");
scanf("%c",&p->data.yuan);
getchar();
printf("请你输入班级:");
scanf("%d",&p->data.ban);
getchar();
/*信息输入已经完成*/
p->next=NULL;
r->next=p;
r=p;
shoudsave=1;}

}

voidQur(Linkl)/*查询学生*/
{
intsel;
charfindmess[20];
Node*p;

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

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

}
voidDel(Linkl)/*删除*/
{
intsel;
Node*p,*r;
charfindmess[20];
if(!l->next)
{
printf(" =====>提示:没有资料可以删除! ");
return;
}
printf(" =====>1按学号删除 =====>2按姓名删除 ");
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(" =====>提示:该学生已经成功删除! ");
shoudsave=1;
}
else
Nofind();
}
elseif(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(" =====>提示:该学生已经成功删除! ");
shoudsave=1;
}
else
Nofind();
}
else
Wrong();
}

voidModify(Linkl)
{
Node*p;
charfindmess[20];
if(!l->next)
{
printf(" =====>提示:没有资料可以修改! ");
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("请你输入新的学院:",p->data.yuan);
scanf("%c",&p->data.yuan);
getchar();
printf("请你输入新的班级(原来是%d):",p->data.ban);
scanf("%d",&p->data.ban);
getchar();
printf(" =====>提示:资料修改成功! ");
shoudsave=1;
}
else
Nofind();

}

voidSave(Linkl)
{
FILE*fp;
Node*p;
intflag=1,count=0;
fp=fopen("c:\student","wb");
if(fp==NULL)
{
printf(" =====>提示:重新打开文件时发生错误! ");
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(" =====>提示:文件保存成功.(有%d条记录已经保存.) ",count);
shoudsave=0;
}
fclose(fp);
}

voidmain()
{
Linkl;/*连表*/
FILE*fp;/*文件指针*/
intsel;
charch;
charjian;

intcount=0;
Node*p,*r;
printf(" 学生成绩管理系统 -------建筑电气及智能化0801 ");
l=(Node*)malloc(sizeof(Node));
l->next=NULL;
r=l;

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

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(" =====>提示:记录导入完毕,共导入%d条记录. ",count);

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

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

④ C语言课程设计:学生学籍管理系统。有谁有代码给我做个参考吗谢谢了,C语言和C++的都可以。

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

typedef struct stud //学生信息结构
{
long num;
char name[20];
float score;
}Stud;

typedef struct node
{
Stud student;
struct node *next;
}Node;
Node *head=NULL;
void read(void);
void inser(long b);
void print();
void find(long b);
void searchname(char *s);
Node * del(long n);
void sort(int flag);
void menu();

void main()
{
char choose;
int flag=1;

while (flag)
{
menu(); //调用功能菜单函数,显示菜单项。
printf(" 请选择:");
choose=getchar();

switch(choose)
{ 1
case '1': read(); //调用建立链表的函数;输出链表信息;
print();
printf("\nPress any key Continue ");
//getchar();
getchar();
break;
case '2': //调用按学号查找学生信息的函数;并输出查找结果信息;
long c;
printf("input the number you want to find:");
scanf("%ld",&c);
find(c);
printf("\nPress any key Continue.");
getchar();
break;
case '3':
//调用按姓名查找学生信息的函数;并输出查找结果信息;
char s[20];
printf("input the name you want to find:");
scanf("%s",s);
searchname(s);
printf("\n Press any key Continue.");
getchar();
getchar();
break;
case '4':
//调用根据学号删除某个学生信息的函数;并输出删除后的链表信息;
Node *h;
long n;
printf("input the number you want to delete:");
scanf("%ld",&n);
h=del(n);
if(h==NULL) printf("No find the student \n");
else print();
printf("\n Press any key Continue.");
getchar();
getchar();
break;
case '5':
//调用插入新的学生信息的函数;并输出插入后的链表信息;
long a;
printf("input the number for the new:\n");
scanf("%ld",&a);
inser(a); 2
print();
printf("\n Press any key Continue.");
getchar();
getchar();
break;
case '6':
//调用按分数降序排序输出的函数;并输出排序后的链表信息;
sort(1);
print();
sort(0);
printf("\nPress any key Continue.");
getchar();
getchar();
break;
case '0':
//结束程序运行!
flag=0;
printf("\n *** The End! ***\n");
break;
default: printf("\n Wrong Selection !(选择错误,重选)\n");
getchar();
}
}
}

void menu() //综合作业功能菜单
{
printf(" \n 学 生 信 息 管 理 系 统\n");
printf(" \n 菜 单\n\n");
printf(" \n 1. 建 立 链 表 并 显 示 \n");
printf(" \n 2. 查 找 某 学 号 的 学 生 信 息 \n");
printf(" \n 3. 查 找 某 姓 名 的 学 生 信 息 \n");
printf(" \n 4. 删 除 某 个 学 号 的 学 生\n");
printf(" \n 5. 插 入 新 的 学 生 信 息 \n");
printf(" \n 6. 按 分 数 降 序 排 序 输 出 \n");
printf(" \n 0. 退 出\n\n");
}

void read(void)
{
long a;
printf("input the number:");
scanf("%ld",&a);
while(a>0){ 3
inser(a);
printf("input the number:");
scanf("%ld",&a);
}
}
void inser(long b)
{

Node *last,*current,*p;
current=head;
while(current!=NULL&&b>current->student.num){
last=current;
current=current->next;
}

if(current==NULL||b<current->student.num){
printf("input the name,score:");
p=(Node *)malloc(sizeof(Node));
p->student.num=b;
scanf("%s%f",p->student.name,&p->student.score);
p->next=NULL;
if(current==head){
p->next=head;
head=p;
}
else{
p->next=current;
last->next=p;
}
}
else if(b==current->student.num)
printf("error input a different number:");

}

void print()
{
Node *p=head;
printf("学号 姓名 成绩:\n");
while(p!=NULL){
printf("%ld %s %f\n",p->student.num,p->student.name,p->student.score);
p=p->next;
} 4
printf("\n");
}
void find(long b)
{
Node *p=head;
while(p!=NULL&&b!=p->student.num)
p=p->next;
if(!p) printf("No found\n");
else {
printf("学号 姓名 成绩\n");
printf("%ld %s %f\n",p->student.num,p->student.name,p->student.score);
}

}

void searchname(char *s)
{
Node *p=head;
int flag=0;
printf("学号 姓名 成绩:\n");
while(p!=NULL)
{
if(strcmp(p->student.name,s)==0)
{
printf("%ld %s %f\n",p->student.num,p->student.name,p->student.score);
flag=1;
p=p->next;
continue;
}
else p=p->next;
}
if(!flag) printf("No find");
}
Node * del(long n)
{
Node *p=head,*last;
while(p->student.num!=n){
last=p;
p=p->next;
}
if(p==NULL) return p;
else if(p==head) head=p->next;
else last->next=p->next; 5
return head;
}
void sort(int flag)
{
/*flag==1 按分数排序 else 按学号排序*/
Node *p1,*p2,*k;
float t1;
long t2;
char s[20];
for(p1=head;p1->next;p1=p1->next)
{
k=p1;
for(p2=p1->next;p2;p2=p2->next)
if(flag==1&&k->student.score<p2->student.score||!flag&&k->student.num>p2->student.num)
k=p2;
if(k!=p1){
t1=p1->student.score;
p1->student.score=k->student.score;
k->student.score=t1;
t2=p1->student.num;
p1->student.num=k->student.num;
k->student.num=t2;
strcpy(s,p1->student.name);
strcpy(p1->student.name,k->student.name);
strcpy(k->student.name,s);
}
}
}
给你看看

⑤ c语言课程设计学籍管理系统

这个是我曾经做的,上面功课和你的不一样,把汉字改下就行了,还有那个人数,人数和排名最后一名数字一样,你运行一下就清楚了
#include<stdio.h>
#include<malloc.h>
#define M "%-6s%-6d%-6d%-6d%-6d%-6d%-7d%-6d\n"
#define H p->name,p->num,p->grade.Escore,p->grade.Mscore,p->grade.Cscore,p->grade.Pscore,p->grade.Allscore,p->grade.Allrank
typedef struct score{
int Escore;
int Mscore;
int Cscore;
int Pscore;
int Allscore;
int Allrank;
}Sco;
typedef struct student{
char name [20];
int num;
struct score grade;
struct student *next;
}*stu;
struct student *Create(struct student *head)
{
int i,n;
printf("请输入学生个数;");
scanf("%d",&n);
printf("请输入信息和成绩\n");
printf("姓名,学号,英语,高数,C语言,体育:");
printf("\n");
stu p,q;
p=q=(stu)malloc(sizeof(student));
head=p;
for(i=0;i<n;i++)
{
p->next=q;
p=q;
scanf("%s%d%d%d%d%d",q->name,&q->num,&q->grade.Escore,&q->grade.Mscore,&q->grade.Cscore,&q->grade.Pscore);
q->grade.Allscore=q->grade.Escore+q->grade.Mscore+q->grade.Cscore+q->grade.Pscore;
q=(stu)malloc(sizeof(student));
}
p->next=NULL;
return head;
}
struct student *Change(struct student *head)
{
int n,i,k;
stu p;
p=head;
printf("请输入要修改的学号:");
scanf("%d",&i);
printf("1.英语 2.高数 3.C语言 4.体育\n");
printf("请输入要修改的成绩:");
scanf("%d",&n);
while(p)
{
if(i==p->num)
switch(n)
{
case 1:
printf("请输入英语分数:");
scanf("%d",&k);
p->grade.Escore=k;
break;
case 2:
printf("请输入高数分数:");
scanf("%d",&k);
p->grade.Mscore=k;
break;
case 3:
printf("请输入C语言分数:");
scanf("%d",&k);
p->grade.Cscore=k;
break;
case 4:
printf("请输入体育分数:");
scanf("%d",&k);
p->grade.Pscore=k;
break;
}
if(i==p->num) break;
if(p->next)
p=p->next;
}
p->grade.Allscore=p->grade.Escore+p->grade.Mscore+p->grade.Cscore+p->grade.Pscore;
return head;
}
struct student *Insert(struct student *head)
{
stu p,q;
p=q=(stu)malloc(sizeof(student));
p=head;
printf("请输入姓名和学号:\n");
scanf("%s%d",q->name,&q->num);
printf("请输入英语,高数,C语言,体育成绩:\n");
scanf("%d%d%d%d",&q->grade.Escore,&q->grade.Mscore,&q->grade.Cscore,&q->grade.Pscore);
q->grade.Allscore=q->grade.Escore+q->grade.Mscore+q->grade.Cscore+q->grade.Pscore;
while(p->next)
{
p=p->next;
}
p->next=q;
p=p->next;
p->next=NULL;
return head;
}
struct student *Delet(struct student *head)
{
stu p,q,m;
int n;
printf("请输入要删除的学号:");
scanf("%d",&n);
p=head;
if(n==p->num)
{
q=p;
head=p->next;
free(p);
}
else
{
q=p->next;
while(q)
if(q->next==NULL&&n==q->num)
{
m=q;
free(q);
p->next=NULL;
q=NULL;
}
else if(q->next!=NULL&&n==q->num)
{
p->next=q->next;
free(q);
q=NULL;
}
else
{
if(q->next!=NULL)
{
p=q;
q=q->next;
}
}
}
return head;
}
void Look(struct student *head)
{
stu p;
int n,i,k;
p=head;
printf("1.按学号查找 2.按分数查找\n");
printf("请输入查找的类别:");
scanf("%d",&n);
if(n==1)
{
printf("请输入要查找的学号:");
scanf("%d",&i);
while(p)
{
if(i==p->num)
{
printf("姓名 学号 英语 高数 C语言 体育 总成绩 排名\n");
printf(M,H);
}
if(i==p->num) break;
if(p->next)
p=p->next;
}
}
if(n==2)
{
printf("1.英语 2.高数 3.C语言 4.体育 5.总分\n");
printf("请输入要查找的课程:");
scanf("%d",&i);
switch(i)
{
case 1:
printf("请输入要查找的英语最低分数:");
scanf("%d",&k);
printf("姓名 学号 英语 高数 C语言 体育 总成绩 排名\n");
while(p)
{
if(k<=p->grade.Escore)
printf(M,H);
p=p->next;
}
break;
case 2:
printf("请输入要查找的高数最低分数:");
scanf("%d",&k);
printf("姓名 学号 英语 高数 C语言 体育 总成绩 排名\n");
while(p)
{
if(k<=p->grade.Mscore)
printf(M,H);
p=p->next;
}
break;
case 3:
printf("请输入要查找C语言语最低分数:");
scanf("%d",&k);
printf("姓名 学号 英语 高数 C语言 体育 总成绩 排名\n");
while(p)
{
if(k<=p->grade.Cscore)
printf(M,H);
p=p->next;
}
break;
case 4:
printf("请输入要查找的体育最低分数:");
scanf("%d",&k);
printf("姓名 学号 英语 高数 C语言 体育 总成绩 排名\n");
while(p)
{
if(k<=p->grade.Pscore)
printf(M,H);
p=p->next;
}
break;
case 5:
printf("请输入要查找的总分最低分数:");
scanf("%d",&k);
printf("姓名 学号 英语 高数 C语言 体育 总成绩 排名\n");
while(p)
{
if(k<=p->grade.Allscore)
printf(M,H);
p=p->next;
}
break;
}
}

}
struct student *Rank(struct student *head,struct student *p,int j)
{
int i;
stu q;
i=p->grade.Allscore;
q=head;
while(q)
{
if(q->grade.Allscore>i)
j++;
if(!q->next)break;
q=q->next;
}
p->grade.Allrank=j;
while(p)
{
if(!p->next)break;
{
p=p->next;
Rank(head,p,1);
}
}
return head;

}
void Rankshow(struct student *head,int j)
{
int i;
stu p,q;
q=head;
p=head;
i=j;
printf("姓名 学号 英语 高数 C语言 体育 总成绩 排名\n");
while(q)
{
while(p)
if(i==p->grade.Allrank)
{
printf(M,H);
p=p->next;
}
else
p=p->next;
p=head;
i++;
if(!q->next)break;
q=q->next;
}
}
void show(struct student *head)
{
stu p;
printf("姓名 学号 英语 高数 C语言 体育 总成绩 排名");
printf("\n");
p=head;
while(p)
{
printf(M,H);
p=p->next;
}
}
void main()
{
int n;
struct student *head,*p;
stu L;
printf("综合素质测评系统\n");
printf("1.数据录入\n");
printf("2.数据修改\n");
printf("3.插入操作\n");
printf("4.删除操作\n");
printf("5.查找操作\n");
printf("6.排序操作\n");
printf("7.数据显示\n");
printf("0.退出系统\n");
printf("请输入操作:");
scanf("%d",&n);
while(n!=0)
{
switch(n)
{
case 0:
break;
case 1:
L=Create(head);
Rank(L,L,1);
printf("请输入操作:");
break;
case 2:
Change(L);
Rank(L,L,1);
printf("请输入操作:");
break;
case 3:
L=Insert(L);
Rank(L,L,1);
printf("请输入操作:");
break;
case 4:
L=Delet(L);
Rank(L,L,1);
printf("请输入操作:");
break;
case 5:
Look(L);
printf("请输入操作:");
break;
case 6:
Rank(L,L,1);
Rankshow(L,1);
printf("请输入操作:");
break;
case 7:
show(L);
printf("请输入操作:");
break;
}
scanf("%d",&n);
}
}

⑥ 用c语言编写一个学生学籍管理系统

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

#include<iomanip>
using namespace std;

class student
{
protected:
int number;
char name[20];
char sex[6];
char place[20];
char nation[6];
char birth[20];
char party[10];
char id[20];
double score[3];
public:
student *next;
student(){ }
~student(){ }
char* getname(){ return name; }
int getnumber(){ return number;}
double getscore(int i) { return score[3];}
float getg(){ return (score[0]+score[1]+score[2]); }
void input()
{
int e=1;
cout<<"\t\t\t按提示输入:"<<endl;
cout<<"\t\t输入编号: ";
cin>>number;
cout<<"\t\t输入姓名: ";
cin>>name;
do
{
cout<<"\t\t输入性别: ";
cin>>sex;
if(strcmp(sex,"男")==0 || strcmp(sex,"女")==0)
{
cout<<"\t\t输入籍贯: ";
cin>>place;
cout<<"\t\t输入民族: ";
cin>>nation;
cout<<"\t\t输入生日: ";
cin>>birth;
cout<<"\t\t输入政治面貌: ";
cin>>party;
cout<<"\t\t输入身份证号: ";
cin>>id;
cout<<"\t\t输入数学分数: ";
cin>>score[0];
cout<<"\t\t输入英语分数: ";
cin>>score[1];
cout<<"\t\t输入计算机分数: ";
cin>>score[2];
e=0;
}
else
{
cout<<"\t\t\t无此类型性别!重新输入!"<<endl;
e=1;
}
}while(e);
return ;
}
void input(ifstream & is)
{
is>>number>>name>>sex>>place>>nation>>birth>>party>>id
>>score[0]>>score[1]>>score[2];
is.get();
}
void output()
{
cout<<"学生基本信息如下:"<<endl;
cout<<"编号:"<<number
<<" 姓名:"<<name
<<" 性别:"<<sex
<<" 籍贯:"<<place
<<" 民族:"<<nation
<<" 生日:"<<birth
<<" 政治面貌:"<<party<<endl
<<"身份证号:"<<id
<<" 数学:"<<score[0]
<<" 英语:"<<score[1]
<<" 计算机:"<<score[2]
<<" 总分:"<<getg()<<endl<<endl;
}
void output(ofstream & os)
{
os<<setw(6)<<number
<<setw(15)<<name
<<setw(6)<<sex
<<setw(20)<<place
<<setw(6)<<nation
<<setw(20)<<birth
<<setw(20)<<party
<<setw(20)<<id
<<setw(6)<<score[0]
<<setw(6)<<score[1]
<<setw(6)<<score[2]<<endl;
}
};

class school
{
public:
school(){ head=new student; head->next=NULL; key=0; }
~school(){ delete head; }
void input();
void mend();
void del();
int find(student **p,int num,char *pn="^");
void found();
void show();
void count();
void save();
void begin();
void clear();
char mainmenu();
int getkey(){ return key;}
void setkey(int k){ key=k; }
private:
student *head;
int key;
};
//录入函数
void school::input()
{
student *p,*p2=NULL;
p=head;
int n;
while(p->next)
p=p->next;
while(n)
{
p2=new student;
p2->input();
p->next=p2;
p2->next=NULL;
p=p->next;
school::setkey(1);
cout<<"\t\t\t按1继续,按0返回 : ";
cin>>n;
}
}
//子查找函数
int school::find(student **p1,int num,char *pn)
{
student *p;
p=head;
while(p->next)
{
(*p1)=p;
if( (p->next)->getnumber()==num||!strcmp( (p->next)->getname(),pn ) )
return 1;
p=p->next;
}
return 0;
}
//查找函数
void school::found()
{
student *p;
int num=-1,n=9;
char name[20]="^";
do
{
cout<<"\t\t1:按编号查找,2:按姓名查找: ";
cin>>n;
}while(n<1||n>2);
if(n==1)
{
cout<<"\t\t\t输入编号: ";
cin>>num;
}
if(n==2)
{
cout<<"\t\t\t输入姓名: ";
cin>>name;
}
if(!find(&p,num,name) )
{
cout<<"\t\t找不到你要查找的内容!"<<endl;
return;
}
(p->next)->output();
}
//删除函数
void school::del()
{
student *p,*p2;
int num;
cout<<"\t\t\t输入编号: ";
cin>>num;
if( !find(&p,num,"^") )
{
cout<<"\t\t找不到你要删除的内容!"<<endl;
return;
}
(p->next)->output();
p2=p->next;
p->next=p2->next;
delete p2;
school::setkey(1);
}
//显示函数
void school::show()
{
student *p;
p=head;
while(p->next)
{
(p->next)->output();
p=p->next;
}
}
//修改函数
void school::mend()
{
student *p;
int num=-1,n;
char name[20]="^";
do
{
cout<<"\t\t1:按编号修改,2:按姓名修改: ";
cin>>n;
}while(n<1||n>2);
if(n==1)
{
cout<<"\t\t\t输入编号: ";
cin>>num;
}
if(n==2)
{
cout<<"\t\t\t输入姓名: ";
cin>>name;
}
if( !find(&p,num,name) )
{
cout<<"\t\t找不到你要修改的内容!"<<endl;
return;
}
(p->next)->output();
(p->next)->input();
school::setkey(1);
}
//保存函数
void school::save()
{
student *p;
p=head;
ofstream os("student.txt",ios::out);
if (school::getkey()==1)
{
while(p->next)
{
(p->next)->output(os);
p=p->next;
}
}
cout<<"\t\t\t文件已保存! "<<endl;
school::setkey(0);
}
//初始化函数
void school::begin()
{
student *p,*p2;
p=head;
clear();
long t;
ifstream is("student.txt",ios::in);
if(!is)
{
ofstream os("student.txt",ios::out);
os.close();
return ;
}
int num=-1;
while(1)
{
num=-1;
t=is.tellg();
is>>num;
is.seekg(t);
if(num<0)
{
is.close();
return;
}
p2=new student;
p2->input(is);
p->next=p2;
p2->next=NULL;
p=p->next;
}
}
//清空函数
void school::clear()
{
student *p,*p2;
p=head->next;
while( p )
{
p2=p;
p=p->next;
delete p2;
}
}
//统计函数
void school::count()
{
student *p;
p=head;
int n=0;
double g[3]={0,0,0};
float j[3]={0,0,0};
while(p->next)
{
p=p->next;
n++;
for(int i=0;i<3;i++)
{
g[++i]=g[i]+( p->getscore(i) );
(p->getscore(i) )>=60? j[i++] : 0 ;
}
}
cout<<"\t\t\b\b\b\b数学总分:"<<g[0]<<" 平均分:"<<g[0]/n
<<" 及格率:"<<j[0]/n<<endl<<"\t\t\b\b\b\b英语总分:"<<g[1]
<<" 平均分:"<<g[1]/n<<" 及格率:"<<j[1]/n<<endl
<<"\t\t\b\b\b\b计算机总分: "<<g[2]<<" 平均分: "<<g[2]/n
<<" 及格率:"<<j[2]/n<<endl;
}
//主选菜单函数
char school::mainmenu()
{
char n[6];
cout<<"\n\n ☆☆☆☆欢迎进入高校学籍管理系统☆☆☆☆"<<endl<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" * * 1: 录入学生信息 * *"<<endl
<<" * * 2: 显示学生信息 * *"<<endl
<<" * * 3: 查找学生信息 * *"<<endl
<<" * * 4: 删除学生信息 * *"<<endl
<<" * * 5: 修改学生信息 * *"<<endl
<<" * * 6: 统计学生成绩 * *"<<endl
<<" * * 7: 保存学生信息 * *"<<endl
<<" * * 0: 退出系统 * *"<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" 请选择:";
cin>>n;
return n[0];
}
//主函数
void main()
{
school pp;
int k=1;
char n;
pp.begin();
while(k==1)
{
n=pp.mainmenu();
switch(n)
{
case '1':pp.input(); break;
case '2':pp.show(); break;
case '3':pp.found(); break;
case '4':pp.del(); break;
case '5':pp.mend(); break;
case '6':pp.count(); break;
case '7':pp.save(); break;
case '0':
if(pp.getkey()==1)
{
cout<<"\t\t\t是否保存? 1 : 保存 0:不保存 : ";
cin>>k;
if(k==1)
pp.save();
}
pp.clear();
k=0;
break;
}
}
}

⑦ c语言程序设计——学籍管理

"学生学籍管理"的C程序

#include<stdlib.h>
#include<stdio.h>
#include<malloc.h>
struct list{
int num;
char name[256];
int china;
int english;
int math;
struct list *next;
};
typedef struct list node;
typedef node *link;
void printf_list(link head)
{
link pointer;
pointer=head;
while(pointer!=NULL)
{
printf("number:%d\n",pointer->num);
printf("name:%s\n",pointer->name);
printf("china:%d\n",pointer->china);
printf("english:%d\n",pointer->english);
printf("math:%d\n",pointer->math);
pointer=pointer->next;
}
}
link creat_list(link head)
{
int cnum;
char cname[256];
int cchina;
int cenglish;
int cmath;
link pointer, newd;
int i;
head=(link)malloc(sizeof(node));
if(head==NULL)
{ printf("memory allocate failure!!\n");
exit(0);}
else{
printf("please input number:");
scanf("%d",&cnum);
printf("please input name:");
scanf("%s",&cname);
printf("please input china:");
scanf("%d",&cchina);
printf("please input english:");
scanf("%d",&cenglish);
printf("please input math:");
scanf("%d",&cmath);
head->num=cnum;
for(i=0;i<256;i++)
{
head->name[i]=cname[i];
}
head->china=cchina;
head->english=cenglish;
head->math=cmath;
head->next=NULL;
pointer=head;
while(1)
{
newd=(link)malloc(sizeof(node));
if(newd==NULL){
printf("memory allocate failure!!\n");
exit(0);}
printf("please input number:");
scanf("%d",&cnum);
if(cnum==0){
break; }
printf("please input name:");
scanf("%s",cname);
printf("please input china:");
scanf("%d",&cchina);
printf("please input english:");
scanf("%d",&cenglish);
printf("please input math:");
scanf("%d",&cmath);
newd->num=cnum;
for(i=0;i<256;i++){
newd->name[i]=cname[i];}
newd->china=cchina;
newd->english=cenglish;
newd->math=cmath;
newd->next=NULL;
pointer->next=newd;
pointer=newd;
}
}
return head;
}
void search_chengji(int key1,link head)
{
link pointer;
pointer=head;
while(pointer!=NULL)
{
if(pointer->num==key1)
{
printf("number:%d\n",pointer->num);
printf("name:%s\n",pointer->name);
printf("china:%d\n",pointer->china);
printf("english:%d\n",pointer->english);
printf("math:%d\n",pointer->math);
}
pointer=pointer->next;
}
}
link modify_chengji(link head,int key3)
{

link pointer;
char xname[256];
int xchina;
int xenglish;
int xmath;
int choose,i;
pointer=head;
printf("enter 0 exit modefiy\n");
printf("enter 1 modefiy name\n");
printf("enter 2 modefiy china\n");
printf("enter 3 modefiy english\n");
printf("enter 4 modefiy math\n");
scanf("%d",&choose);
switch(choose)
{
case 1:
printf("please input name:");
scanf("%s",&xname);
break;
case 2:
printf("please input china:");
scanf("%d",&xchina);
break;
case 3:
printf("please input english:");
scanf("%d",&xenglish);
break;
case 4:
printf("please input math:");
scanf("%d",&xmath);
break;
}
while(1){
pointer=pointer->next;
if(pointer->num==key3)
{
if(choose==1)
{ for(i=0;i<256;i++)
{
pointer->name[i]=xname[i];
}
break;
}
else if(choose==2)
{ pointer->china=xchina;
break;}
else if(choose==3)
{ pointer->english=xenglish;
break;
}
else if(choose==4)
{pointer->math=xmath;
break;}
}
}
return head;
}
link delete_chengji(link head,int key2)
{
link pointer;
link back;
pointer=head;
while(1)
{
if(head->num==key2)
{ head=pointer->next;
free(pointer);
break;
}
back=pointer;
pointer=pointer->next;
if(pointer->num==key2)
{
back->next=pointer->next;
free(pointer);
break;}
}
return head;
}
link insert_chengji(link head,link newd,int key3)
{
link pointer;
pointer=head;
while(1)
{
if(pointer==NULL){
newd->next=head;
head=newd;
break;}
if(pointer->num==key3){
newd->next=pointer->next;
pointer->next=newd;
break;}
pointer=pointer->next;
}
return head;
}
void pingjufen(link head)
{
link pointer;
int pchina,ppchina;
int penglish,ppenglish;
int pmath,ppmath;
int count;
pchina=0;
penglish=0;
pmath=0;
count=0;
pointer=head;
while(1)
{
pchina=pchina+pointer->china;
penglish=penglish+pointer->english;
pmath=pmath+pointer->math;
count=++count;
if(pointer->next==NULL)
{
break;
}
pointer=pointer->next;
}
ppchina=pchina/count;
ppenglish=penglish/count;
ppmath=pmath/count;
printf("china ping jun fen:%d\n",ppchina);
printf("english ping jun fen:%d\n",ppenglish);
printf("math ping jun fen:%d\n",ppmath);
}
void main()
{
for(;;)
{
link head;
link newd;
int key;
int keynum;
printf("0>exit the programm.\n");
printf("1>create list.\n");
printf("2>search chengji.\n");
printf("3>modify chengji.\n");
printf("4>delete chengji.\n");
printf("5>add chengji.\n");
printf("6>pingjunfeng.\n");
printf("7>print chengji.\n");
scanf("%d",&key);
switch(key){
case 0:
exit(0);
case 1:
head=creat_list(head);
if(head!=NULL)
{ printf_list(head);}
break;
case 2:
printf("please input 0 Exit.\n");
printf("please input number for search:");
scanf("%d",&keynum);
if(keynum==0){
break; }
search_chengji(keynum,head);
break;
case 3:
printf("please input number for modify:");
scanf("%d",&keynum);
head=modify_chengji(head,keynum);
if(head!=NULL)
{
printf_list(head);
}
break;
case 4:
printf("please input 0 exit\n");
printf("please input number for delete:");
scanf("%d",&keynum);
if(keynum==0){
break; }
head=delete_chengji(head,keynum);
break;
case 5:
if(head!=NULL){
newd=(link)malloc(sizeof(node));
printf("please input number:");
scanf("%d",&newd->num);
if(newd->num==0){
break;}
printf("please input name:");
scanf("%s",&newd->name);
printf("please input china:");
scanf("%d",&newd->china);
printf("please input english:");
scanf("%d",&newd->english);
printf("please input math:");
scanf("%d",&newd->math);
printf("please input the data number for insert:");
scanf("%d",&keynum);
head=insert_chengji(head,newd,keynum);
if(head!=NULL) {
printf_list(head);}
}
break;
case 6:
pingjufen(head);
break;
case 7:
printf_list(head);
break;
}
}
}

⑧ C语言设计一个学生学籍管理系统,要求文件形式保存,且用到链表

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

//链表结点结构体声明
typedefstructsubjects
{
charname[20];
floatscore;
}sub;

typedefstructstudent
{
intnum;
charname[20];
subsubject[3];
structstudent*next;
}stu,*pstu;

#defineSIZEsizeof(stu)

//函数申明
pstuLoadInfo();
voidPrintMenu();
pstuAddStu(pstu);
pstuDeleStu(pstu);
pstuRwrStu(pstu);
voidFindStu(pstu,char);
voidCount(pstu,char*,float,float);
voidRank(pstu,char*);
voidSaveQuit(pstu);

//主函数
intmain()
{
floatscore1,score2;
charn,j;
charsubname[20];
pstuhead,ptr;

head=LoadInfo();
ptr=head->next;

//创建菜单,进入选择循环
while(1)
{
PrintMenu();
printf("请输入您的选择编号:");
scanf("%d",&n);
getchar();
switch(n)
{
case1:
{
system("cls");
j=0;
while(4!=j)
{
printf("欢迎进入信息管理版块! ");
printf("251、添加学生 ");
printf("252、删除学生 ");
printf("253、修改学生信息 ");
printf("254、返回 ");
printf("请输入您的选择编号: ");
scanf("%d",&j);
getchar();

if(1==j)head=AddStu(head);
elseif(2==j)head=DeleStu(head);
elseif(3==j)head=RwrStu(head);
elseif(4==j);
elseprintf("输入有误,请重新输入! ");

}
printf("请输入回车键返回主菜单!");//此处本意按任意键返回,但是任意键的话,需要按键A,再按回车确定
getchar(); //则会连续收到两个按键,造成错误读入,可以改进scanf接收字符串,
system("cls"); //以下所有getchar()、system("cls")同理
break;
}
case2:
{
//信息查询
system("cls");
printf("欢迎进入信息查询版块! ");
printf("请输入要查询的学生编号:");
scanf("%d",&j);
getchar();
//printf("%d ",j); //检测输入是否成功,调试程序用
FindStu(head,j); //查询并输出
printf(" 请输入回车键返回主菜单!");
getchar();
system("cls");
break;
}
case3:
{
//成绩统计
system("cls");
printf("欢迎进入成绩统计版块! ");
printf("请输入科目:");
scanf("%s",&subname);
getchar();
printf("请输入分数范围(score1,score2):");
scanf("%f,%f",&score1,&score2);
getchar();
/*printf("%s%5.2f%5.2f ",subname,
score1,score2);*///检测输入是否成功,调试程序用
Count(head,subname,score1,score2); //统计并输出
printf("请输入回车键返回主菜单!");
getchar();
system("cls");
break;
}
case4:
{
//成绩排序
system("cls");
printf("欢迎进入成绩排序版块,请输入科目:");
scanf("%s",&subname);
getchar();
Rank(head,subname); //排序并输出
printf(" 请输入回车键返回主菜单! ");
getchar();
system("cls");
break;
}
case5:
{
//保存退出
SaveQuit(head); //文件操作,保存并退出
free(head);
return0;
}
default:
{
printf("输入有误,按回车键重新选择! "); //主菜单错误输出检测
getchar();
system("cls");
}
}
}


}

//加载data数据,文件操作
pstuLoadInfo()
{
intnum;
charname[20];
charsub1[20];
charsub2[20];
charsub3[20];
floatscore1;
floatscore2;
floatscore3;

charfilename[]="D:\编程学习\编程实践\c语言课程设计1学生信息管理\data.txt";//文件名,此处为简化编程,采用固定地址名称,未作输入
FILE*fp;
pstuhead,ptr;

//创建带表头结点的空单链表head,用来存放载入信息
head=(pstu)malloc(SIZE);
ptr=head;
ptr->next=NULL;


//加载data文件,存入head链表
if(NULL==(fp=fopen(filename,"r"))) //判断文件是否存在及可读
{
printf("error!");
exit(0);
}

while(!feof(fp))
{
fscanf(fp,"%d%s%s%f%s%f%s%f ",&num,&name,
&sub1,&score1,&sub2,&score2,&sub3,&score3);//读取一行,采用格式化读取,避免了其他各种读取方法的数据处理问题
//该方法缺点明显,对数据格式要求教研,故data文件规定数据格式
ptr->next=(pstu)malloc(SIZE);
ptr=ptr->next;
ptr->next=NULL;

ptr->num=num;
strcpy(ptr->name,name);
strcpy(ptr->subject[0].name,sub1);
ptr->subject[0].score=score1;
strcpy(ptr->subject[1].name,sub2);
ptr->subject[1].score=score2;
strcpy(ptr->subject[2].name,sub3);
ptr->subject[2].score=score3;

}

fclose(fp); //关闭文件,已得到保存data信息的链表head

returnhead;
}


//打印主菜单
voidPrintMenu()
{
printf("*************************************** ");
printf("枫枫学生信息管理系统 ");
printf("*************************************** ");
putchar(' ');
printf("菜单 ");
printf("251、信息管理 ");
printf("252、信息查询 ");
printf("253、成绩统计 ");
printf("254、成绩排序 ");
printf("255、保存退出 ");
}

//添加学生
pstuAddStu(pstux)
{
charnamestu[20];
char*p;
charsubname1[20],subname2[20],subname3[20];
pstuhead,ptr;

head=x;
ptr=head;

while(NULL!=ptr->next) //遍历链表,找到链尾结点
{
ptr=ptr->next;
}

ptr->next=(pstu)malloc(SIZE); //默认在链表末追加添加信息
ptr=ptr->next;
ptr->next=NULL;

printf("请输入添加学生的信息: ");

printf("请输入添加学生的学号:");
scanf("%d",&ptr->num);
getchar();

printf("请输入添加学生的姓名:");
scanf("%s",namestu);
getchar();
p=namestu;
strcpy(ptr->name,p);

printf("请输入添加学生的科目1名称:");
scanf("%s",&subname1);
getchar();
p=subname1;
strcpy(ptr->subject[0].name,p);

printf("请输入添加学生的科目1成绩:");
scanf("%f",&ptr->subject[0].score);
getchar();

printf("请输入添加学生的科目2名称:");
scanf("%s",&subname2);
getchar();
p=subname2;
strcpy(ptr->subject[1].name,p);

printf("请输入添加学生的科目2成绩:");
scanf("%f",&ptr->subject[1].score);
getchar();

printf("请输入添加学生的科目3名称:");
scanf("%s",&subname3);
getchar();
p=subname3;
strcpy(ptr->subject[2].name,p);

printf("请输入添加学生的科目3成绩:");
scanf("%f",&ptr->subject[2].score);
getchar();

putchar(' ');
returnhead;
}

//删除学生
pstuDeleStu(pstux)
{
intnum;
pstuhead,ptr,qtr;

head=x;
ptr=head->next;
qtr=head;

printf("请输入要删除的学生的学号:");
scanf("%d",&num);
getchar();

while(ptr!=NULL)
{
if(ptr->num!=num) //遍历查找链表结点,未找到跳过该结点
{
ptr=ptr->next;
qtr=qtr->next;
}
else //找到则删除结点
{
ptr=ptr->next;
qtr->next=ptr;
break;
}
}

printf("该学生信息已删除! ");
returnhead;
}

//修改学生信息
pstuRwrStu(pstux)
{
charnamestu[20];
char*p;
charsubname1[20],subname2[20],subname3[20];
intnum;
pstuhead,ptr;

head=x;
ptr=head->next;

printf("请输入要修改的学生的学号:");
scanf("%d",&num);
getchar();

while(ptr!=NULL)
{
if(ptr->num==num)
{
printf("已找到该学生信息,请填入修改项目:");

printf("请输入修改学生的姓名:");
scanf("%s",namestu);
getchar();
p=namestu;
strcpy(ptr->name,p);

printf("请输入修改学生的科目1名称:");
scanf("%s",subname1);
getchar();
p=subname1;
strcpy(ptr->subject[0].name,p);

printf("请输入修改学生的科目1成绩:");
scanf("%f",&ptr->subject[0].score);
getchar();

printf("请输入修改学生的科目2名称:");
scanf("%s",subname2);
getchar();
p=subname2;
strcpy(ptr->subject[1].name,p);

printf("请输入修改学生的科目2成绩:");
scanf("%f",&ptr->subject[1].score);
getchar();

printf("请输入修改学生的科目3名称:");
scanf("%s",subname3);
getchar();
p=subname3;
strcpy(ptr->subject[2].name,p);

printf("请输入修改学生的科目3成绩:");
scanf("%f",&ptr->subject[2].score);
getchar();

printf("该学生信息已修改! ");
break;
}
else
{
ptr=ptr->next;
}
}

returnhead;
}

//查找学生,参数为链表指针,和学生学号
//不好,应该将学号输入放进子函数,简化主函数结构,减少子函数参数
voidFindStu(pstux,chary)
{
pstuhead,ptr;

head=x;
ptr=head->next;

while(ptr!=NULL)
{
if(ptr->num==(int)y) //因主函数中为节省空间,学号输入采用char数据,故强行准换
{
printf("已找到该学生信息! 如下:");
printf("%03d%s%s%5.2f%s%5.2f%s%5.2f ",
ptr->num,ptr->name,ptr->subject[0].name,ptr->subject[0].score,ptr->subject[1].name,ptr->subject[1].score,ptr->subject[2].name,ptr->subject[2].score); break; //注意此处找到并输出信息后要手动退出循环
}
else
{
ptr=ptr->next;
}
}
if(ptr==NULL) //查询成功检测,while循环中若找到,则ptr停留在当前学生的结点上
{
printf("未能找到该学生信息! ");
}
}


//统计科目分数区间段的学生,参数为链表指针,科目名称,分数区间上下限
//同理,参数的录入应放入子函数,简化结构和编程
voidCount(pstux,char*y,floatq,floatp)
{
pstuhead,ptr;
charname[20];
charflag=0; //手动设置的查找结果flag

head=x;
ptr=head->next;
strcpy(name,y);

//printf("%s%5.2f%5.2f ",name,q,p); //检测输入参数的传递,调试程序用

while(ptr!=NULL) //开始查找统计,科目查找用strcmp函数比较科目字符串,返回值0为字符串相等
{ //此处while循环体中,重复的查找步骤太多,应设置科目匹配flag,参照rank()函数
if(strcmp(name,ptr->subject[0].name)==0) //通过flag将科目确认放在while之外,循环体内只做分数区间的扫描和输出
{
if(q<=ptr->subject[0].score&&ptr->subject[0].score<=p)
{
printf("%03d%s%s%5.2f ",ptr->num,ptr->name,ptr->subject[0].name,ptr->subject[0].score);
flag++;
}
}
if(strcmp(name,ptr->subject[1].name)==0)
{
if(q<=ptr->subject[1].score&&ptr->subject[1].score<=p)
{
printf("%03d%s%s%5.2f ",ptr->num,ptr->name,ptr->subject[1].name,ptr->subject[1].score);
flag++;
}
}
if(strcmp(name,ptr->subject[2].name)==0)
{
if(q<=ptr->subject[2].score&&ptr->subject[2].score<=p)
{
printf("%03d%s%s%5.2f ",ptr->num,ptr->name,ptr->subject[2].name,ptr->subject[2].score);
flag++;
}
}

ptr=ptr->next;
}

if(flag==0)
{
printf("未能找到该课程该区间分数段的学生! ");
}
}


//学科成绩排名,采用交换数据的方法,参数为链表指针,科目名称
//同理参数问题
//链表排序问题,此处用交换结点数据方法,还有其他多种排序方法
//如,交换结点,辅助指针数组排序(未实现,过程繁杂),插入法排序等
voidRank(pstux,char*y)
{
pstuhead,ptr,qtr;
charname[20];
charlen=0;
charflag=0; //简化算法,设置科目查找结果判断值,flag=0表示科目输入为未知科目,不存在
inti=0; //i、j循环次数控制参数
intj=0;
chartemp_name[20]; //数据交换时的暂存信息变量
floattemp0,temp1,temp2;
inttemp_num;

strcpy(name,y);
head=x;

ptr=head->next;
while(ptr!=NULL) //测链表长度,不包括表头结点
{
ptr=ptr->next;
len++;
}
ptr=head->next; //指针ptr用过之后记得回原位


//开始查找科目
if(strcmp(name,ptr->subject[0].name)==0) flag=1;
if(strcmp(name,ptr->subject[1].name)==0) flag=2;
if(strcmp(name,ptr->subject[2].name)==0) flag=3;
if(flag==0)
{
printf("未找到该科目!");
return;
}

//开始排序,冒泡法比较各结点数据
//此处3个并列的if用switchcase更清晰结构
if(n==1)
{
for(i=0;i<len;i++)
{
ptr=head->next->next; //每一次内循环之后,ptr、qtr必然在最后两个节点上
qtr=head->next; //故在进行内循环之前,要重新复位ptr、qtr
for(j=0;j<len-i-1;j++)
{
if(qtr->subject[0].score<ptr->subject[0].score)
{
temp_num=qtr->num; //交换数据,因数据格式(科目顺序)明确规定,故不再做科目名称的替换
strcpy(temp_name,qtr->name);
temp0=qtr->subject[0].score;
temp1=qtr->subject[1].score;
temp2=qtr->subject[2].score;

qtr->num=ptr->num;
strcpy(qtr->name,ptr->name);
qtr->subject[0].score=ptr->subject[0].score;
qtr->subject[1].score=ptr->subject[1].score;
qtr->subject[2].score=ptr->subject[2].score;

ptr->num=temp_num;
strcpy(ptr->name,temp_name);
ptr->subject[0].score=temp0;
ptr->subject[1].score=temp1;
ptr->subject[2].score=temp2;
}
qtr=qtr->next;
ptr=ptr->next;
}
}
}

if(n==2)
{
for(i=0;i<len;i++)
{
ptr=head->next->next;
qtr=head->next;
for(j=0;j<len-i-1;j++)
{
if(qtr->subject[1].score<ptr->subject[1].score)
{
temp_num=qtr->num;
strcpy(temp_name,qtr->name);
temp0=qtr->subject[0].score;
temp1=qtr->subject[1].score;
temp2=qtr->subject[2].score;

qtr->num=ptr->num;
strcpy(qtr->name,ptr->name);
qtr->subject[0].score=ptr->subject[0].score;
qtr->subject[1].score=ptr->subject[1].score;
qtr->subject[2].score=ptr->subject[2].score;

ptr->num=temp_num;
strcpy(ptr->name,temp_name);
ptr->subject[0].score=temp0;
ptr->subject[1].score=temp1;
ptr->subject[2].score=temp2;
}
qtr=qtr->next;
ptr=ptr->next;
}
}
}

if(n==3)
{
for(i=0;i<len;i++)
{
ptr=head->next->next;
qtr=head->next;
for(j=0;j<len-i-1;j++)
{
if(qtr->subject[2].score<ptr->subject[2].score)
{
temp_num=qtr->num;
strcpy(temp_name,qtr->name);
temp0=qtr->subject[0].score;
temp1=qtr->subject[1].score;
temp2=qtr->subject[2].score;

qtr->num=ptr->num;
strcpy(qtr->name,ptr->name);
qtr->subject[0].score=ptr->subject[0].score;
qtr->subject[1].score=ptr->subject[1].score;
qtr->subject[2].score=ptr->subject[2].score;

ptr->num=temp_num;
strcpy(ptr->name,temp_name);
ptr->subject[0].score=temp0;
ptr->subject[1].score=temp1;
ptr->subject[2].score=temp2;
}
qtr=qtr->next;
ptr=ptr->next;
}
}
}

//输出排序过后的链表
ptr=head->next;
while(ptr!=NULL)
{
printf("%03d%s%s%5.2f%s%5.2f%s%5.2f ",
ptr->num,ptr->name,ptr->subject[0].name,ptr->subject[0].score,
ptr->subject[1].name,ptr->subject[1].score,
ptr->subject[2].name,ptr->subject[2].score);
ptr=ptr->next;
}
}


//保存文件并退出,文件操作
voidSaveQuit(pstux)
{
pstuhead,ptr;
FILE*fp;
charfilename[]="D:\编程学习\编程实践\c语言课程设计1学生信息管理\data.txt";
head=x;
ptr=head->next;

if(NULL==(fp=fopen(filename,"w"))) //判断文件是否存在及可读
{
printf("error!");
exit(0);
}

while(ptr!=NULL) //遍历链表结点,按data约定格式输出数据
{
fprintf(fp,"%03d%s%s%5.2f%s%5.2f%s%5.2f ",
ptr->num,ptr->name,ptr->subject[0].name,ptr->subject[0].score,