本文主要是介绍毕业生信息管理系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100
typedef struct //定义的用于表示毕业生信息
{char num[20]; //学号char name[20]; //姓名char sex[3];//性别int age;//年龄int classno;//班级char major[20];//专业char status[20];//就业情况char more[20];//备注
}Student;typedef struct
{Student data[N];//数组int length;//顺序表长度
}SqList;//界面设计
void welcomePrint();//界面
//功能设计
void add(SqList *L1);//添加毕业生信息
void select_num(SqList *L1);//按学号查询
void select_name(SqList *L1);//按姓名查询
void select_all(SqList *L1);//查询所有毕业生
void delete_student(SqList *L1);//删除
void change(SqList *L1);//修改
void sort_no(SqList *L1);//按照学号排序void read(SqList *L1);//文件读毕业生信息
void write(SqList *L1);//文件写毕业生信息int main()
{char x;SqList *L1;L1 = (SqList*)malloc(sizeof(SqList));L1->length = 0;read(L1);//文件读while (1){welcomePrint();//界面登陆printf("请输入你的选择:");scanf("%c", &x);switch (x){case '1':add(L1);//教师信息录入write(L1);//文件写入毕业生信息break;case '2':select_all(L1);//毕业生信息浏览break;case '3':select_num(L1);//按照学号查询break;case '4':select_name(L1);//按照姓名查询break;case '5':change(L1);//修改毕业生信息write(L1);//文件写入毕业生信息break;case '6':delete_student(L1);//删除毕业生信息write(L1);//文件写入毕业生信息break;case '7':sort_no(L1);//按照学号进行排序break;case '0':return 0;default:printf("输入有误,请重新选择!\n");break;}getchar();system("pause");}return 0;
}void welcomePrint()//游客登录界面
{system("cls");//清屏//system("color f5");printf("1、毕业生信息录入\n");printf("2、毕业生信息浏览\n");printf("3、按照学号查询\n");printf("4、按照姓名查询\n");printf("5、修改毕业生信息\n");printf("6、删除毕业生信息\n");printf("7、按照学号进行排序\n");printf("0、退出\n");
}void add(SqList *L1)//添加毕业生信息
{system("cls");if(L1->length>=N){printf("顺序表满,无法添加!\n");return ;}printf("请输入毕业生学号:");scanf("%s",L1->data[L1->length].num);//信息存入表尾printf("请输入毕业生姓名:");scanf("%s",L1->data[L1->length].name);printf("请输入毕业生性别:");scanf("%s",L1->data[L1->length].sex);printf("请输入毕业生年龄:");scanf("%d",&L1->data[L1->length].age);printf("请输入毕业生班级:");scanf("%d",&L1->data[L1->length].classno);printf("请输入毕业生专业:");scanf("%s",L1->data[L1->length].major);printf("请输入毕业生就业情况:");scanf("%s",L1->data[L1->length].status);printf("请输入备注:");scanf("%s",L1->data[L1->length].more);L1->length++;//表长+1printf("新增成功!\n");
}void select_all(SqList *L1)//查询所有毕业生信息
{int i;system("cls");if(L1->length==0){printf("无毕业生信息!\n");return;}printf("%-10s%-10s%-10s%-10s%10s%-20s%-20s%-20s\n","学号","姓名","性别","年龄","班级","专业","就业情况","备注");for(i=0;i<L1->length;i++)//遍历输出{printf("%-10s%-10s%-10s%-10d%10d%-20s%-20s%-20s\n",L1->data[i].num,L1->data[i].name,L1->data[i].sex,L1->data[i].age,L1->data[i].classno,L1->data[i].major,L1->data[i].status,L1->data[i].more);}
}void select_num(SqList *L1)//按学号查询
{int i;char no[20];system("cls");printf("请输入要查询的学号:");scanf("%s",no);if(L1->length==0){printf("无毕业生信息!\n");return;}for(i=0;i<L1->length;i++)//遍历输出{if(!strcmp(no,L1->data[i].num))//如果学号一样{printf("%-10s%-10s%-10s%-10s%10s%-20s%-20s%-20s\n","学号","姓名","性别","年龄","班级","专业","就业情况","备注");printf("%-10s%-10s%-10s%-10d%10d%-20s%-20s%-20s\n",L1->data[i].num,L1->data[i].name,L1->data[i].sex,L1->data[i].age,L1->data[i].classno,L1->data[i].major,L1->data[i].status,L1->data[i].more);break;}}if(i==L1->length)//查询到表尾都没有跳出循环{printf("无该毕业生信息!\n");}
}void select_name(SqList *L1)//按姓名查询
{int i,flag=0;char name[20];system("cls");printf("请输入要查询的姓名:");scanf("%s",name);if(L1->length==0){printf("无毕业生信息!\n");return;}for(i=0;i<L1->length;i++)//遍历输出{if(!strcmp(name,L1->data[i].name))//如果姓名一样{printf("%-10s%-10s%-10s%-10s%10s%-20s%-20s%-20s\n","学号","姓名","性别","年龄","班级","专业","就业情况","备注");printf("%-10s%-10s%-10s%-10d%10d%-20s%-20s%-20s\n",L1->data[i].num,L1->data[i].name,L1->data[i].sex,L1->data[i].age,L1->data[i].classno,L1->data[i].major,L1->data[i].status,L1->data[i].more);flag=1;//设置标志 表示查询到了}}if(flag==0)//查询到表尾都没有跳出循环{printf("无该毕业生信息!\n");}}void delete_student(SqList *L1)//删除毕业生
{int i,j;char no[20];system("cls");printf("请输入要删除的学号:");scanf("%s",no);if(L1->length==0){printf("无毕业生信息!\n");return;}for(i=0;i<L1->length;i++)//遍历输出{if(!strcmp(no,L1->data[i].num))//如果学号一样{printf("%-10s%-10s%-10s%-10s%10s%-20s%-20s%-20s\n","学号","姓名","性别","年龄","班级","专业","就业情况","备注");printf("%-10s%-10s%-10s%-10d%10d%-20s%-20s%-20s\n",L1->data[i].num,L1->data[i].name,L1->data[i].sex,L1->data[i].age,L1->data[i].classno,L1->data[i].major,L1->data[i].status,L1->data[i].more);break;}}if(i==L1->length)//查询到表尾都没有跳出循环{printf("无该毕业生信息!\n");return;}for(j=i;j<L1->length-1;j++){L1->data[j]=L1->data[j+1];//用后一个覆盖前面一个 达到删除的效果}L1->length--;//人数-1printf("删除成功!\n");
}
void change(SqList *L1)//改变毕业生信息
{int i;char no[20];system("cls");printf("请输入要修改的学号:");scanf("%s",no);if(L1->length==0){printf("无毕业生信息!\n");return;}for(i=0;i<L1->length;i++)//遍历输出{if(!strcmp(no,L1->data[i].num))//如果学号一样{printf("%-10s%-10s%-10s%-10s%10s%-20s%-20s%-20s\n","学号","姓名","性别","年龄","班级","专业","就业情况","备注");printf("%-10s%-10s%-10s%-10d%10d%-20s%-20s%-20s\n",L1->data[i].num,L1->data[i].name,L1->data[i].sex,L1->data[i].age,L1->data[i].classno,L1->data[i].major,L1->data[i].status,L1->data[i].more);break;}}if(i==L1->length)//查询到表尾都没有跳出循环{printf("无该毕业生信息!\n");return;}printf("请输入毕业生姓名:");scanf("%s",L1->data[i].name);printf("请输入毕业生性别:");scanf("%s",L1->data[i].sex);printf("请输入毕业生年龄:");scanf("%d",&L1->data[i].age);printf("请输入毕业生班级:");scanf("%d",&L1->data[i].classno);printf("请输入毕业生专业:");scanf("%s",L1->data[i].major);printf("请输入毕业生就业情况:");scanf("%s",L1->data[i].status);printf("请输入备注:");scanf("%s",L1->data[i].more);printf("修改成功!\n");
}void sort_no(SqList *L1)//学号排序
{int i,j;Student temp;for(i=0;i<L1->length;i++){for(j=i+1;j<L1->length;j++)//选择排序{if(strcmp(L1->data[i].num,L1->data[j].num)>0)//如果学号需要交换 放到前面i的位置{temp=L1->data[i];L1->data[i]=L1->data[j];L1->data[j]=temp;}}}select_all(L1);//排序完显示
}void read(SqList *L1)//文件读
{FILE *fp;int a = 0;//a,用来识别到底有没有删除数据.t,用来接收fsacnf函数的返回值(为-1是说明无数据)if ((fp = fopen("student.txt", "r+")) == NULL)//‘r’允许读{printf("文件打开失败!\n");return;}else{while (!feof(fp)){a = 1;fread(&L1->data[L1->length++],sizeof(Student),1,fp);}fclose(fp); //关闭文件if (a == 0){printf("文本无数据,毕业生信息读取失败\n");}else{L1->length--;}}
}void write(SqList *L1)//文件写
{FILE *fp;int t = 0;int i;if ((fp = fopen("student.txt", "w+")) == NULL){printf("文件打开失败!\n");return;}else{for (i = 0; i < L1->length; i++){t=1;fwrite(&L1->data[i],sizeof(Student),1,fp);}fclose(fp); //关闭文件if (t == 1){//printf("毕业生信息写入完成\n");}else{printf("毕业生信息写入失败\n");}}
}
这篇关于毕业生信息管理系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!