相信许多童鞋的第一次都给了这个项目吧,嘿嘿……嘿 0.0
这里提供了一份源码供大家参考,请自行食用。
项目功能:
(1)help函数,打印菜单,获取帮助信息。
(2)insert函数:插入数据信息。
(3)sort函数:对已有信息进行排序。
(4)find函数:索引查找信息。
(5)output函数:遍历信息。
(6)delete函数:通过索引删除信息。
初始化界面:
运行界面:
到这里,我猜有人要说:"你啰嗦***呢?我不会自己 *** 作吗,还不快把源码给朕呈上来?”
TNND
源码参上:
main.c文件
#include"student.h"
int main()
{
printf(" 欢迎使用学生信息管理系统\n");
Help();
STU *head=NULL;
while(1)
{
printf(" 请输入 *** 作指令: ");
char str[32]=" ";
scanf("%s",str);
if(strcmp(str,"insert")==0)
{
printf(" 请输入学生信息(学号 姓名 性别 年龄 四科成绩):\n");
STU tmp;
printf(" ");
scanf("%d %s %s %d %d %d %d %d",&tmp.num,tmp.name,tmp.sex,&tmp.age,&tmp.score_Chinese,&tmp.score_Math,&tmp.score_Computer,&tmp.score_English);
tmp.score_average=(tmp.score_Chinese+tmp.score_Computer+tmp.score_English+tmp.score_Math)/4.0;
tmp.score_sum=tmp.score_Chinese+tmp.score_Computer+tmp.score_English+tmp.score_Math;
head=Insert(head,tmp);
}
else if(strcmp(str,"sort")==0)
{
Sort_num(head);
}
else if(strcmp(str,"find")==0)
{
STU *pf=NULL;
int num;
printf(" 按照学号查找为1,按照姓名查找为2\n");
int t;
printf(" ");
scanf("%d",&t);
if(t==1)
{
printf(" 请输入查询学生的学号:\n");
printf(" ");
scanf("%d",&num);
pf=Find_num(head,num);
}
else if(t==2)
{
printf(" 请输入查询学生的姓名:\n");
char n_name[32];
printf(" ");
scanf("%s",n_name);
STU *pi=head;
while(pi!=NULL&&strcmp(pi->name,n_name)!=0)
{
pi=pi->next;
}
if(pi!=NULL)
{
pf=Find_num(head,pi->num);
}
}
pf=Find_num(head,num);
if(pf!=NULL)
{
printf(" 学号 姓名 性别 年龄 语文成绩 电脑成绩 数学成绩 英语成绩 平均成绩 总成绩 \n");
printf(" %d %s %s %d %d %d %d %d %.2f %d\n",pf->num,pf->name,pf->sex,pf->age,pf->score_Chinese,pf->score_Math,pf->score_Computer,pf->score_English,pf->score_average,pf->score_sum);
}
else
{
printf(" 未查询到该学生信息\n");
}
}
else if(strcmp(str,"output")==0)
{
output_a(head);
}
else if(strcmp(str,"delete")==0)
{
int num;
printf(" 请输入删除学生信息的学号:\n");
printf(" ");
scanf("%d",&num);
head=Delete_num(head,num);
}
else if(strcmp(str,"quit")==0)
{
printf(" 成功退出程序\n");
break;
}
else
{
printf(" 输出错入指令,请重新输入\n");
}
}
return 0;
}
student.h文件
#ifndef STUDENT_H
#define STUDENT_H
#include
#include
#include
typedef struct Student
{
//数据域
int num;
char name[20];
char sex[10];
int age;
int score_Chinese;
int score_Math;
int score_Computer;
int score_English;
double score_average;
int score_sum;
//指针域
struct Student *next;
}STU;
void Help(void);
STU* Insert(STU *head,STU tmp);//
void Sort_num(STU *head);
STU* Find_num(STU *head,int num);//按照学号查找
void output_a(STU *head);//
STU * Delete_num(STU *head,int num);//按照学号删除
#endif
student.c文件
#include"student.h"
extern void Help(void)
{
printf(" ---------------------------------------------------------- \n");
printf(" | (1)添加信息 insert |\n");
printf(" | (2)信息排序 sort |\n");
printf(" | (3)查找信息 find |\n");
printf(" | (4)删除信息 delete |\n");
printf(" | (5)遍历信息 output |\n");
printf(" | (6)退出程序 quit |\n");
printf(" ---------------------------------------------------------- \n");
return ;
}
STU* Insert(STU *head,STU tmp)
{
STU *pi=(STU*)calloc(1,sizeof(STU));
if(pi==NULL)
{
perror("calloc");
exit(-1);//如果申请失败直接结束程序
}
*pi=tmp;
pi->next=NULL;
if(head==NULL)
{
head=pi;
}
else
{
STU *pf=head;
while(pf->next!=NULL)
{
pf=pf->next;
}
pf->next=pi;
pi->score_average=(pi->score_Computer+pi->score_English+pi->score_Math+pi->score_Chinese)/4;
pi->score_sum=pi->score_Computer+pi->score_English+pi->score_Math+pi->score_Chinese;
}
return head;
}
void Sort_num(STU *head)
{
if(head==NULL)
{
printf(" 信息库为空\n");
}
else
{
STU *pi=head;
STU *pj=head;
//选择法排序
while(pi->next!=NULL)
{
STU *min=pi;
pj=pi->next;
while(pj!=NULL)
{
if(min->num>pj->num)
{
min=pj;
}
pj=pi->next;
}
if(pi!=pj)
{
//交换数据
STU tmp=*pi;
*pi=*min;
*min=tmp;
//交换指针
tmp.next=pi->next;
pi->next=pj->next;
pj->next=tmp.next;
}
pi=pi->next;
}
}
return ;
}
STU* Find_num(STU *head,int num)
{
STU *pf=head;
if(head==NULL)
{
printf(" 信息库为空\n");
}
else
{
while(pf!=NULL&&pf->num!=num)
{
pf=pf->next;
}
}
return pf;
}
void output_a(STU *head)
{
STU *pf=head;
if(head==NULL)
{
printf(" 信息库为空\n");
}
else
{
printf(" 学号 姓名 性别 年龄 语文成绩 电脑成绩 数学成绩 英语成绩 平均成绩 总成绩 \n");
while(pf!=NULL)
{
printf(" %d %s %s %d %d %d %d %d %.2f %d\n",pf->num,pf->name,pf->sex,pf->age,pf->score_Chinese,pf->score_Math,pf->score_Computer,pf->score_English,pf->score_average,pf->score_sum);
pf=pf->next;
}
}
return ;
}
STU* Delete_num(STU *head,int num)
{
STU *pf=head;
STU *pi=NULL;
if(head==NULL)
{
printf(" 信息库为空\n");
}
else
{
while(pf->next!=NULL&&pf->num!=num)
{
pi=pf;
pf=pf->next;
}
if(pf->num==num)
{
if(pf==head)//头部删除
{
head=head->next;
//free(pf);
}
else//删除中尾部节点
{
pi->next=pf->next;
//free(pf);
}
free(pf);
printf(" 信息删除成功\n");
}
else
{
printf(" 未查询到该学生信息\n");
}
}
return head;
}
到这里,作为戏精的我已经忍不住开始得瑟了,又拯救哪个小伙伴的世界嘞?
木哈哈哈哈!!! 哈?看到这了竟还想要白嫖???那个……我承认刚才说话声音有点大,给个赞吧0.0
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)