文档库 最新最全的文档下载
当前位置:文档库 › 教务管理系统部分源代码

教务管理系统部分源代码

#include
#include
#include
struct teacher_node{
int ID;
char name[20];
char password[20];
char sex[10];
int age;
struct teacher_node * next;
};
struct student_node{
int ID;
int name[20];
char password[20];
char class[20];
char sex[10];
int age;
int chinese;
int math;
int C;
struct students_node * next;
};
struct teacher_node * Create_Tea_Doc(); //创建学生信息链表
struct teacher_node * Add_Tea_Doc(struct teacher_node * head , struct teacher_node * teacher); //插入教师信息操作
struct teacher_node * Del_Tea_Doc(struct teacher_node * head , int ID); //删除教师信息操作
void Rev_Tea_Doc(struct teacher_node * head , int ID); //修改教师信息操作
void Search_Tea_Doc(struct teacher_node * head , int ID); //查找教师信息操作
void Show_Tea_Doc(struct teacher_node * head); //显示所有教师信息操作
struct student_node * Create_Stu_Doc(); //创建教师信息链表
struct student_node * Add_Stu_Doc(struct student_node * head , struct student_node * student); //插入学生信息操作
struct student_node * Del_Stu_Doc(struct student_node * head , int ID); //删除学生信息操作
void Rev_Stu_Doc(struct student_node * head , int ID); //修改学生信息操作
void Search_Stu_Doc(struct student_node * head , int ID); //查找学生信息操作
void Show_Stu_Doc(struct student_node * head); //显示所有学生信息操作
main()
{
void admin_login();
void teacher_login();
void student_login();
int status;
printf("===================================\n");
printf("欢迎使用学生管理系统,请选择:\n1.管理员登录\n2.教师登录\n3.学生登录\n");
printf("===================================\n");
scanf("%d",&status);

switch(status){
case 1:
admin_login();
break;
case 2:
// teacher_login();
break;
case 3:
// student_login();
break;
default:
printf("输入错误!\n");
break;
}
}
void admin_login()
{
void admin_operate();
char admin[20];
char password[20];
printf("===================================\n");
printf(" 管理员登录\n");
printf("用户名:");
scanf("%s",admin);
printf("密码:");
scanf("%s",password);
printf("===================================\n");
if((strcmp(admin,"hyacinth")==0)&&(strcmp(password,"zjb19940425")==0))
{
printf("欢迎管理员hyacinth登录\n");
admin_operate();
}
else
printf("用户名或密码错误!\n");
}
void admin_operate()
{
struct student_node *head1,*p1;
struct teacher_node *head2,*p2;
int choice,ID,age,chinese,math,C;
char name[20];
char class[20];
char sex[10];
int size1=sizeof(struct student_node);
int size2=sizeof(struct teacher_node);

head1=Create_Stu_Doc();
head2=Create_Tea_Doc();
do{
printf("===================================\n");
printf("请选择所需要的操作:\n");
printf("1.添加学生\n2.删除学生\n3.修改学生信息\n4.

查找学生\n5.显示全部学生\n6.添加教师\n7.删除教师\n8.修改教师信息\n9.查找教师\n10.显示全部教师\n");
printf("===================================\n");
scanf("%d",&choice);
switch(choice){
case 1:
printf("===================================\n");
printf("请录入以下学生信息:\n");
printf("班级:"); scanf("%s",class);
printf("学号:"); scanf("%d",&ID);
printf("姓名:"); scanf("%s",name);
printf("性别:"); scanf("%s",sex);
printf("年龄:"); scanf("%d",&age);
printf("语文成绩:"); scanf("%d",&chinese);
printf("数学成绩:"); scanf("%d",&math);
printf("C语言成绩:"); scanf("%d",&C);
printf("===================================\n");
p1=(struct student_node * )malloc(size1);
strcpy(p1->class,class);
p1->ID=ID;
strcpy(p1->name,name);
strcpy(p1->sex,sex);
p1->age=age;
p1->chinese=chinese;
p1->math=math;
p1->C=C;
head1=Add_Stu_Doc(head1,p1);
printf("添加成功!\n");
break;
case 2:
printf("请输入要删除的学生学号:\n");
scanf("%d",&ID);
head1=Del_Stu_Doc(head1,ID);
printf("删除成功!\n");
break;
case 3:
printf("请输入要修改的学生学号:\n");
scanf("%d",&ID);
Rev_Stu_Doc(head1,ID);
printf("修改成功!\n");
break;
case 4:
printf("请输入要查找学生的学号:\n");
scanf("%d",&ID);
Search_Stu_Doc(head1,ID);
break;
case 5:
Show_Stu_Doc(head1);
break;
case 6:
printf("===================================\n");
printf("请录入以下教师信息:\n");
printf("工号:"); scanf("%d",&ID);
printf("姓名:"); scanf("%s",name);
printf("性别:"); scanf("%s",sex);
printf("年龄:"); scanf("%d",&age);
printf("===================================\n");
p2=(struct teacher_node * )malloc(size2);
printf("======1\n");
p2->ID=ID;
printf("======2\n");
strcpy(p2->name,name);
printf("======3\n");
strcpy(p2->sex,sex);
printf("======4\n");
p2->age=age;
printf("======5\n");
head2=Add_Tea_Doc(head2,p2);
printf("添加成功!\n");
break;
case 7:
printf("请输入要删除的教师编号:\n");
scanf("%d",&ID);
head2=Del_Tea_Doc(head2,ID);
printf("删除成功!\n");
break;
case 8:
printf("请输入要修改的教师编号:\n");
scanf("&d",&ID);
Rev_Tea_Doc(head2,ID);
printf("修改成功!\n");
break;
case 9:
printf("请输入要查找的教师编号:\n");
scanf("%d",&ID);
Search_Tea_Doc(head2,ID);
break;
case 10:
Show_Tea_Doc(head2);
break;
default:
printf("输入错误!\n"); break;
}
}while(1);
}
//创建学生链表
struct student_node * Crea

te_Stu_Doc()
{
struct student_node * head1,*p1;
int ID,age,chinese,math,C;
char class[20];
char name[20];
char sex[10];
int size1=sizeof(struct student_node);
head1=NULL;
return head1;
}
//添加学生信息操作
struct student_node * Add_Stu_Doc(struct student_node * head1,struct student_node *student)
{
struct student_node *ptr,*ptr1,*ptr2;
ptr2=head1;
ptr=student;
if(head1==NULL){
head1=ptr;
head1->next=NULL;
}
else{
while((ptr->ID>ptr2->ID)&&(ptr2->next!=NULL)){
ptr1=ptr2;
ptr2=ptr2->next;
}
if(ptr->ID<=ptr2->ID){
if(head1==ptr2)
head1=ptr;
else
ptr1->next=ptr;
ptr->next=ptr2;
}
else{
ptr2->next=ptr;
ptr->next=NULL;
}
}
return head1;
}
//删除学生信息操作
struct student_node * Del_Stu_Doc(struct student_node * head1,int ID)
{
struct student_node *ptr1,*ptr2;
while(head1!=NULL&&head1->ID==ID){ //要被删除的结点是表头结点
ptr2=head1;
head1=head1->next;
free(ptr2);
}
if(head1==NULL) //链表为空
return NULL;

//要被删除的结点为非表头结点
ptr1=head1;
ptr2=head1->next;
while(ptr2!=NULL){
if(ptr2->ID==ID){
ptr1->next=ptr2->next;
free(ptr2);
}
else
ptr1=ptr2;
ptr2=ptr1->next;
}
return head1;
}
//修改学生信息操作
void Rev_Stu_Doc(struct student_node * head1,int ID ){
struct student_node *p;
int i;
Search_Stu_Doc(head1,ID);
printf("===================================\n");
printf("请选择要修改的内容:\n1.班级\n2.姓名\n3.性别\n4.年龄\n5.语文成绩\n6.数学成绩\n7.C语言成绩\n");
printf("===================================\n");
scanf("%d",&i);
printf("请输入修改后的数据:");
for(p=head1;p!=NULL;p=p->next){
if(p->ID==ID){
switch(i){
case 1: scanf("%s",(p->class)); break;
case 2: scanf("%s",(p->name)); break;
case 3: scanf("%s",(p->sex)); break;
case 4: scanf("%d",&(p->age)); break;
case 5: scanf("%d",&(p->chinese)); break;
case 6: scanf("%d",&(p->math)); break;
case 7: scanf("%d",&(p->C)); break;
default: printf("输入错误!\n"); break;
}
}
}
}
//查找学生信息操作
void Search_Stu_Doc(struct student_node * head1,int ID){
struct student_node * ptr;
printf("===================================\n");
for(ptr=head1;ptr!=NULL;ptr=ptr->next){
if(ptr->ID==ID)
printf("该学生的信息如下:\n学号:%d\n姓名:%s\n班级:%s\n性别:%s\n年龄:%d\n语文成绩:%d\n数学成绩:%d\nC语言成绩:%d\n",ptr->ID,ptr->name,ptr->class,ptr->sex,ptr->age,ptr->chinese,ptr->math,ptr->C);
}
printf("===================================\n");
}
//显示全部学生信息操作
void Show_Stu_Doc(struct student_node * head1){
struct student_node * ptr;
if(head1==NULL){
printf("很抱歉,数据库中暂无信息!\n");
return;
}
printf("===============================================================================\n");
printf("学号 姓名 班级 性别 年龄

语文成绩 数学成绩 C语言成绩\n");
for(ptr=head1;ptr!=NULL;ptr=ptr->next)
printf("%d %s %s %s %d %d %d %d\n",ptr->ID,ptr->name,ptr->class,ptr->sex,ptr->age,ptr->chinese,ptr->math,ptr->C);
}
//创建教师信息链表
struct teacher_node * Create_Tea_Doc()
{
struct teacher_node * head2,*p2;
int ID,age;
char name[20];
char sex[10];
int size2=sizeof(struct teacher_node);
head2=NULL;
return head2;
}
//添加教师信息操作
struct teacher_node * Add_Tea_Doc(struct teacher_node * head2,struct teacher_node *teacher){
struct teacher_node *ptr,*ptr1,*ptr2;
ptr2=head2;
ptr=teacher;
if(head2==NULL){
head2=ptr;
head2->next=NULL;
}
else{
while((ptr->ID>ptr2->ID)&&(ptr2->next!=NULL)){
ptr1=ptr2;
ptr2=ptr2->next;
}
if(ptr->ID<=ptr2->ID){
if(head2==ptr2)
head2=ptr;
else
ptr1->next=ptr;
ptr->next=ptr2;
}
else{
ptr2->next=ptr;
ptr->next=NULL;
}
}
return head2;
}
//删除教师信息操作
struct teacher_node * Del_Tea_Doc(struct teacher_node * head2,int ID){
struct teacher_node *ptr1,*ptr2;
while(head2!=NULL&&head2->ID==ID){
if(ptr2->ID==ID){
ptr1->next=ptr2->next;
free(ptr2);
}
else
ptr1=ptr2;
ptr2=ptr1->next;
}
return head2;
}
//修改教师信息操作
void Rev_Tea_Doc(struct teacher_node * head2,int ID){
struct teacher_node *p;
int i;
Search_Tea_Doc(head2,ID);
printf("===================================\n");
printf("请选择要修改的内容:\n1.姓名\n2.性别\n3.年龄\n");
printf("===================================\n");
scanf("%d",&i);
printf("请输入修改后的数据:");
for(p=head2;p!=NULL;p=p->next){
if(p->ID==ID){
switch(i){
case 1: scanf("%s",(p->name)); break;
case 2: scanf("%s",(p->sex)); break;
case 3: scanf("%d",(p->age)); break;
default: printf("输入错误!\n"); break;
}
}
}
}
//查找教师信息操作
void Search_Tea_Doc(struct teacher_node * head2,int ID){
struct teacher_node * ptr;
printf("===================================\n");
for(ptr=head2;ptr!=NULL;ptr=ptr->next){
if(ptr->ID==ID)
printf("该教师的信息如下:\n工号:%d\n姓名:%s\n性别:%s\n年龄:%d\n",ptr->ID,ptr->name,ptr->sex,ptr->age);
}
printf("===================================\n");
}
//显示所有教师信息操作
void

Show_Tea_Doc(struct teacher_node * head2){
struct teacher_node * ptr;
if(head2==NULL){
printf("很抱歉,数据库中暂无信息!\n");
return;
}
printf("===================================\n");
printf(" 工号 姓名 性别 年龄");
for(ptr=head2;ptr!=NULL;ptr=ptr->next)
printf(" %d %s %s %d\n",ptr->ID,ptr->name,ptr->sex,ptr->age);
printf("===================================\n");
}

相关文档
相关文档 最新文档