本代码供读者学习使用,请不要随意转载。
一、设计题目:学生成绩管理系统
二、目的与要求
每位学生记录包含有学号、姓名、性别、出生日期、三门功课的成绩(高等数学、大学英语、C语言)、总分和平均分
系统菜单:
(1)录入学生记录
(2)添加学生记录
(3)删除学生记录
(4)修改学生记录(要求输入密码)
(5)查找学生记录(按学号、按姓名)
(6)按总分对记录进行降序排列
(7)将当前结果显示或打印,重新保存进数据文件中
(8)输出所有学生信息
(9)计算班级平均分
(10)修改管理员密码(未保存至文件,程序关闭后失效)
(11)C语言挂科人数
(0)结束程序
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include<math.h>
#define LEN sizeof(struct student)
struct student
{
struct student *next;
long num;
char name[8];
char sex[4];
int year;
int month;
int day;
float c;
float math;
float eng;
float sum;
};
int n;
struct student * creat() //建立基础的学生信息库
{
struct student * head,*p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
printf("输入学生的学号为0时,停止录入.\n");
printf("请输入学生学号:");
scanf("%ld",&p1->num);
if(p1->num!=0)
{
printf("请输入学生姓名:");scanf("%s",p1->name);
printf("请输入学生性别:");scanf("%s",p1->sex);
printf("请输入学生生日:\n");
printf("年:");scanf("%d",&p1->year);
printf("月:");scanf("%d",&p1->month);
printf("日:");scanf("%d",&p1->day);
printf("c语言:");scanf("%f",&p1->c);
printf("高数:");scanf("%f",&p1->math);
printf("英语:");scanf("%f",&p1->eng);
p1->sum=p1->c+p1->eng+p1->math;
printf("\n");
}
while(p1->num!=0)
{
n=n+1;
if(n==1)
{
head=p1;
}
else
{
p2->next=p1;
}
p2=p1;
p1=(struct student *)malloc(LEN);
printf("请输入学生学号:");
scanf("%ld",&p1->num);
if(p1->num!=0)
{
printf("请输入学生姓名:");scanf("%s",p1->name);
printf("请输入学生性别:");scanf("%s",p1->sex);
printf("请输入学生生日:\n");
printf("年:");scanf("%d",&p1->year);
printf("月:");scanf("%d",&p1->month);
printf("日:");scanf("%d",&p1->day);
printf("c语言:");scanf("%f",&p1->c);
printf("高数:");scanf("%f",&p1->math);
printf("英语:");scanf("%f",&p1->eng);
p1->sum=p1->c+p1->eng+p1->math;
printf("\n");
}
}
p2->next=NULL;
return head;
}
struct student * del(struct student *head,long num) //删除学生信息
{
struct student *p1,*p2;
if(head==NULL)
{
printf("\nlist null!\n");
return head;
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
printf("你删除的学生信息为:\n");
printf("学号:%ld\n",p1->num);
printf("姓名:%s\n",p1->name);
printf("性别:%s\n",p1->sex);
printf("生日:\n");
printf("年:%d\n",p1->year);
printf("月:%d\n",p1->month);
printf("日:%d\n",p1->day);
printf("c语言:%5.2f\n",p1->c);
printf("高数:%5.2f\n",p1->math);
printf("英语:%5.2f\n",p1->eng);
p1->sum=p1->c+p1->math+p1->eng;
printf("总分:%5.2f\n",p1->sum);
printf("\n");
n=n-1;
}
else
printf("输入有误!\n");
return head;
}
struct student * insert (struct student *head,struct student *stud) //添加学生信息
{
struct student * p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}