用c语言设计一个学生成绩管理系统
该系统要实现的功能为:成绩录入:输入学生的学号、姓名及三门课成绩;成绩查询:按学号查询学生记录、查询不及格学生的记录;成绩统计:计算学生的平均分、根据学生的平均分高低,对学生的数据进行排序后输出;对学生单科 成绩排序,输出学生姓名与该科成绩。
/* ************************************************************************
* Filename: student_system.c
* Description:
* Version: 1.0
* Created: 2016年03月30日 17时27分11秒
* Revision: none
* Compiler: gcc
* Author: YOUR NAME (),
* Company:
* ************************************************************************/
#include <stdio.h>
#include <stdlib.h>
typedef struct stu
{
int num;
char name[20];
int score;
struct stu *next;
}STU;
void link_add_end(STU **head,STU *p_new)
{
p_new->next = *head;
*head = p_new;
}
void link_print(STU **head)
{
if(*head == NULL)
{
return;
}
STU *p_mov = *head;
while(p_mov != NULL)
{
printf("num==%d score==%d name==%s\n",p_mov->num,p_mov->score,p_mov->name);
p_mov=p_mov->next;
}
}
void link_find_num(STU **head,int num)
{
STU *p_mov = *head;
while(p_mov != NULL)
{
if(p_mov->num == num)
{
printf("num==%d score==%d name==%s\n",p_mov->num,p_mov->score,p_mov->name);
}
p_mov=p_mov->next;
}
}
void link_find_name(STU **head,char name[])
{
STU *p_mov = *head;
while(p_mov != NULL)
{
if(strcmp(p_mov->name,name)==0)
{
printf("num==%d score==%d name==%s\n",p_mov->num,p_mov->score,p_mov->name);
}
p_mov=p_mov->next;
}
}
void link_delete_num(STU **head,int num)
{
STU *p_mov = *head;
STU *p_sav = p_mov;
while(p_mov != NULL)
{
if(p_mov->num == num)
{
if(p_mov == *head)
{
*head = p_mov->next;
free(p_mov);
}else if(p_mov->next == NULL)
{
p_sav->next=NULL;
free(p_mov);
}else
{
p_sav->next=p_mov->next;
free(p_mov);
}
}
p_sav=p_mov;
p_mov=p_mov->next;
}
}
void add(STU **head)
{
STU *p_new;
p_new = (STU *)malloc(sizeof(STU));
printf("请输入 学号 分数 姓名\n ");
printf("例如 1 99 张三\n ");
scanf("%d %d %s",&p_new->num,&p_new->score,p_new->name);
getchar();
link_add_end(head,p_new);
}
void prin(STU **head)
{
link_print(head);
}
void find(STU **head)
{
int num;
char name[20];
char cmd[20];
printf("1 find for num\n");
printf("2 find for name\n");
gets(cmd);
if(strcmp("1",cmd) == 0)
{
printf("please input find for num");
scanf("%d",&num);
getchar();
link_find_num(head,num);
}else if(strcmp("2",cmd)==0)
{
printf("please input find for name\n");
gets(name);
link_find_name(head,name);
}else
{
printf("error!!");
return;
}
}
void delete(STU **head)
{
int num;
printf("please input delete for num\n");
scanf("%d",&num);
getchar();
link_delete_num(head,num);
}
void help()
{
printf("************************\n");
printf("*add add link *\n");
printf("*prt print link *\n");
printf("*fid find link *\n");
printf("*del delete link *\n");
printf("*help print help *\n");
printf("************************\n");
}
int main(int argc, char *argv[])
{
char cmd_key[20];
STU *head=NULL;
int i;
typedef void (*FUN)(STU **);
typedef struct cmd_fun
{
char key_cmd[20];
FUN fun;
}CMD;
CMD cmd[]={{"add",add},
{"prt",prin},
{"fid",find},
{"del",delete}};
help();
while(1)
{
gets(cmd_key);
if(strcmp(cmd_key,"help")==0)
{
help();
}
for(i=0; i<4; i++)
{
if(strcmp(cmd[i].key_cmd,cmd_key)==0)
{
cmd[i].fun(&head);
}
}
}
return 0;
}