#define NULL 0
#define STUDENT struct student
#define TEACHER struct teacher
#define LENSTU sizeof(struct student)
#define LENTH sizeof(struct teacher)
#include <stdio.h>
TEACHER
{
int tno;
char tname[20];
char cname[20];
char dept[20];
TEACHER *next;
};
struct course
{
char tname[20];
char cname[20];
int score;
};
STUDENT /*用动态链表实现学生信息的存储,定义链表接点*/
{
int sno;
char sname[20];
int age;
char sex[10];
char dept[20];
struct course cs[3];
STUDENT *next;
};
/*界面初始化,菜单函数*/
int menuselect()
{
char str[10];
clrscr();
printf("\n\n\n\n********************************************************************************\n");
printf(" 学生成绩管理系统\n");
printf("*************************************菜单***************************************\n");
printf("\t\t\t 1. 学生管理\n");
printf("\t\t\t 2. 授课管理\n");
printf("\t\t\t 3. 退出系统\n");
printf("\n\t\t 作者:陈华 \n");
printf("********************************************************************************\n");
do{
printf("\n\t\t\t请选择(1~3):");
scanf("%s",str);
}while(strcmp(str,"1")!=0&&strcmp(str,"2")!=0&&strcmp(str,"3")!=0); /*菜单选择*/
if(strcmp(str,"1")==0) return 1;
else if (strcmp(str,"2")==0) return 2;
else if (strcmp(str,"3")==0) return 3;
}
/*二级菜单学生界面*/
int stumenu()
{
char str[10];
clrscr(); /*清屏*/
printf("********************************************************************************\n");
printf(" 学生管理\n");
printf("*************************************菜单***************************************\n");
printf("\t\t\t1. 学生信息录入\n");
printf("\t\t\t2. 查询学生信息\n");
printf("\t\t\t3. 学生成绩录入\n");
printf("\t\t\t4. 成绩查询\n");
printf("\t\t\t5. 删除学生信息\n");
printf("\t\t\t6. 排序\n");
printf("\t\t\t7. 保存\n");
printf("\t\t\t8. 打开\n");
printf("\t\t\t9. 返回上一菜单\n");
printf("********************************************************************************\n");
do{
printf("\n\t\t\t请选择(1~9):");
scanf("%s",str);
}while(strcmp(str,"1")!=0&&strcmp(str,"2")!=0&&strcmp(str,"3")!=0&&strcmp(str,"4")!=0&&strcmp(str,"5")!=0&&strcmp(str,"6")!=0&&strcmp(str,"7")!=0&&strcmp(str,"8")!=0&&strcmp(str,"9")!=0); /*菜单选择*/
if(strcmp(str,"1")==0) return 1;
else if (strcmp(str,"2")==0) return 2;
else if (strcmp(str,"3")==0) return 3;
else if (strcmp(str,"4")==0) return 4;
else if (strcmp(str,"5")==0) return 5;
else if (strcmp(str,"6")==0) return 6;
else if (strcmp(str,"7")==0) return 7;
else if (strcmp(str,"8")==0) return 8;
else if (strcmp(str,"9")==0) return 9;
}
/*二级授课信息界面*/
int thmenu()
{
char str[10];
clrscr(); /*清屏*/
printf("********************************************************************************\n");
printf(" 教师管理\n");
printf("*************************************菜单***************************************\n");
printf("\t\t\t1. 授课信息录入\n");
printf("\t\t\t2. 打印授课信息\n");
printf("\t\t\t3. 删除授课信息\n");
printf("\t\t\t4. 保存\n");
printf("\t\t\t5. 打开\n");
printf("\t\t\t6. 返回上一菜单\n");
printf("********************************************************************************\n");
do{
printf("\n\t\t\t请选择(1~6):");
scanf("%s",str);
}while(strcmp(str,"1")!=0&&strcmp(str,"2")!=0&&strcmp(str,"3")!=0&&strcmp(str,"4")!=0&&strcmp(str,"5")!=0&&strcmp(str,"6")!=0); /*菜单选择*/
if(strcmp(str,"1")==0) return 1;
else if (strcmp(str,"2")==0) return 2;
else if (strcmp(str,"3")==0) return 3;
else if (strcmp(str,"4")==0) return 4;
else if (strcmp(str,"5")==0) return 5;
else if (strcmp(str,"6")==0) return 6;
}
/*录入*/
/*学生信息录入*/
STUDENT *enterstu(STUDENT *h)
{
int i,sno;
char s[20];
STUDENT *p,*q;
clrscr();
for(;;)
{
p=(STUDENT *)malloc(LENSTU);
if(p==NULL) return NULL;
printf("输入学号(遇到 0 结束输入):");
while(scanf("%d",&sno)==0)
{
printf(" 学号错误!\n输入学号(遇到 0 结束输入):");
scanf("%d",&sno);
scanf("%s",s);
}
if(sno==0)
break; /*如果学号为0则结束输入,否则继续录入*/
q=h;
while(q)
{
if(q->sno==sno){printf("学号为%d的学生已经存在,请重新输入!\n",sno);free(p);break;}
q=q->next;
}
if(!q)
{ p->sno=sno;
printf("输入姓名:");scanf("%s",p->sname);
printf("输入年龄:");
while(scanf("%d",&p->age)==0)
{
printf(" 年龄错误!\n输入年龄:");
scanf("%d",&p->age);
scanf("%s",s);
}
printf("输入性别:");scanf("%s",p->sex);
printf("输入部门:");scanf("%s",p->dept);
for(i=0;i<3;i++) /*对成绩的初始化为0*/
{
strcpy((*p).cs[i].tname," ");
strcpy((*p).cs[i].cname," ");
(*p).cs[i].score=0;
}
p->next=h; /*为了方便插入操作,将头结点做为新输入结点的后继结点*/
h=p; /*新输入结点为新的头结点*/
}
}
return(h);
}
/*授课信息录入*/
TEACHER *enterth(TEACHER *h)
{
int tno;
char s[20];
TEACHER *p,*q;
clrscr();
for(;;)
{
p=(TEACHER *)malloc(LENTH);
if(p==NULL) return NULL;
printf("输入教师职工号(遇到 0 结束输入): ");
while(scanf("%d",&tno)==0)
{
printf("输入错误!");
printf("输入教师职工号(遇到 0 结束输入): ");
scanf("%d",&tno);
scanf("%s",s);
}
if(tno==0)
break; /*如果教师号为0则结束输入,否则继续录入*/
q=h;
while(q)
{
if(q->tno==tno){printf("教师号为%d的教师已经存在,请重新输入!\n",tno);free(p);break;}
q=q->next;
}
if(!q)
{
p->tno=tno;
printf("输入教师名:");scanf("%s",p->tname);
printf("输入课程名:");scanf("%s",p->cname);
printf("输入部门:"); scanf("%s",p->dept);
p->next=h; /*为了方便插入操作,将头结点做为新输入结点的后继结点*/
h=p; /*新输入结点为新的头结点*/
}
}
return(h);
}
/*学生信息查询*/
void querystu(STUDENT *h)
{
int i,n,sno,count;
char s[20],sname[20],dept[20];
char str[10];
STUDENT *p;
clrscr();
do
{
printf("查询条件(遇到 0 结束输入):\n( 打印学生信息:1 学号查询输入:2 姓名查询输入:3 系别查询:4 )");
scanf("%s",str);
if(strcmp(str,"0")==0)
break;
}while( strcmp(str,"1")!=0 && strcmp(str,"2")!=0 && strcmp(str,"3")!=0 && strcmp(str,"4")!=0 );
if(strcmp(str,"1")==0) n=1;
else if (strcmp(str,"2")==0) n=2;
else if (strcmp(str,"3")==0) n=3;
else if (strcmp(str,"4")==0) n=4;
switch(n)
{
case 1:
p=h;
printf("学号 姓名 年龄 性别 部门 :\n");
while(p!=NULL) /*链表的遍历*/
{
{ printf(" %d",p->sno);
printf(" %s",p->sname);
printf(" %d",p->age);
printf(" %s",p->sex);
printf(" %s",p->dept);
printf("\n");
}
p=p->next;
}
getch();
break;
case 2:
for(;;)
{
printf("输入学号(遇到 0 结束输入):");
while(scanf("%d",&sno)==0)
{
printf(" 学号错误!\n输入学号(遇到 0 结束输入):");
scanf("%d",&sno);
scanf("%s",s);
}
if(sno==0)
break;
p=h;
评论0