|
|
|
|
# StudentManagementSystem
|
|
|
|
|
|
|
|
|
|
# **分组实验报告**
|
|
|
|
|
**小组成员:**何童(组长)、张健、张逸儒、吴涛、黄宇豪、江昱升、谭勇、梅开明
|
|
|
|
|
### **1.题目**
|
|
|
|
|
实现一个简易的学生信息管理系统,其中学生信息包括:学号、姓名、性别、年龄、专业等。要求系统能提供建立、查询、删除、增加和排序等功能。(可以自行增加完善系统功能,比如:可以增加其他学生信息用于学生的评优评奖等)
|
|
|
|
|
### **2.需求分析**
|
|
|
|
|
需求分析:
|
|
|
|
|
|
|
|
|
|
1) 系统功能:
|
|
|
|
|
\* 建立:能够在系统中新建学生信息,包括学号、姓名、性别、年龄、专业等内容。
|
|
|
|
|
\* 查询:能够根据学号、姓名、专业等查找学生信息,并以列表方式展示搜索结果。
|
|
|
|
|
\* 删除:能够删除指定学生的信息,包括学号、姓名、性别、年龄、专业等内容。
|
|
|
|
|
\* 增加:能够添加新的学生信息,包括学号、姓名、性别、年龄、专业等内容。
|
|
|
|
|
|
|
|
|
|
2) 用户界面:
|
|
|
|
|
\* 界面设计简洁明了,易于操作。
|
|
|
|
|
\* 用户可在操作界面直观地查看、编辑、删除和增加学生信息。
|
|
|
|
|
\* 用户可根据选择的排序方式对学生信息进行排序。
|
|
|
|
|
\* 系统提供各种适用的提示信息,方便用户操作。
|
|
|
|
|
|
|
|
|
|
3) 数据存储:
|
|
|
|
|
\* 学生信息应以记录形式存储,可以使用结构体数组等方式进行存储。
|
|
|
|
|
\* 学号是学生信息的唯一标识,因此要确保学号具有唯一性,避免出现重复的学生信息。
|
|
|
|
|
### **3.概要设计**
|
|
|
|
|
1)数据结构:
|
|
|
|
|
\* 结构体 `Date`:用于存储日期,包括年、月、日。
|
|
|
|
|
\* 结构体 `Student`:用于存储一个学生的信息,包括学号、姓名、性别、年龄、专业和生日,其中生日是另一个结构体 `Date`。
|
|
|
|
|
2)实现过程:
|
|
|
|
|
1. 定义结构体 `Date` 和 结构体 `Student`。
|
|
|
|
|
2. 定义一个结构体 `Student` 的数组 `student`。
|
|
|
|
|
3. 实现菜单界面函数 `menu()`,通过 `printf` 函数对菜单文字进行输出。
|
|
|
|
|
4. 实现添加学生信息函数 `addStudent()`,通过 `scanf` 函数对学生的各项信息进行输入保存。
|
|
|
|
|
5. 实现查询学生信息函数 `searchStudent()`,通过 `scanf` 函数读入 1 或 2,根据是要求根据学号查询还是根据姓名查询来选择执行相应的代码。
|
|
|
|
|
6. 实现删除学生信息函数 `deleteStudent()`,通过 `scanf` 函数读入 1 或 2,根据是要求根据学号删除还是根据姓名删除来选择执行相应的代码。
|
|
|
|
|
7. 实现列出所有学生信息函数 `listStudent()`,通过 `printf` 函数对所有学生的信息进行列出输出。
|
|
|
|
|
8. 实现退出系统函数 `shutdown()`,将变量 `run` 的值赋为 0,从而退出系统。
|
|
|
|
|
9. 主函数按照菜单选项进行函数的调用,直至退出系统。
|
|
|
|
|
|
|
|
|
|
### **4.详细设计**
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
1. **数据结构**
|
|
|
|
|
|
|
|
|
|
`
|
|
|
|
|
`struct Date {
|
|
|
|
|
int year;
|
|
|
|
|
int month;
|
|
|
|
|
int day;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Student {
|
|
|
|
|
int ID;
|
|
|
|
|
char name[20];
|
|
|
|
|
char sex[2]; // 男/女
|
|
|
|
|
int age;
|
|
|
|
|
char major[20];
|
|
|
|
|
struct Date birthday;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**2.函数声明**:
|
|
|
|
|
|
|
|
|
|
void menu();
|
|
|
|
|
void addStudent();
|
|
|
|
|
void listStudent();
|
|
|
|
|
void searchStudent();
|
|
|
|
|
void deleteStudent();
|
|
|
|
|
void shutdown();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**3.函数实现:**
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#define N 99
|
|
|
|
|
|
|
|
|
|
static int run;
|
|
|
|
|
static int num;
|
|
|
|
|
static struct Student student[N];
|
|
|
|
|
|
|
|
|
|
void menu() {
|
|
|
|
|
printf("\n\n");
|
|
|
|
|
printf("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n");
|
|
|
|
|
printf("\*-----------------数据结构第十一组-------------------\n");
|
|
|
|
|
printf("\* 学生信息管理系统 \*\n");
|
|
|
|
|
printf("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n");
|
|
|
|
|
printf("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*系统功能菜单\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n");
|
|
|
|
|
printf("---------------------- --------------------------\n");
|
|
|
|
|
printf("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n");
|
|
|
|
|
printf("\*\* 1、增加学生信息 2、查询学生信息 \*\*\n");
|
|
|
|
|
printf("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n");
|
|
|
|
|
printf("\*\* 3、删除学生信息 4、列出所有学生信息 \*\*\n");
|
|
|
|
|
printf("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n");
|
|
|
|
|
printf("\*\* 5、退出系统 \*\*\n");
|
|
|
|
|
printf("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n");
|
|
|
|
|
printf("---------------------- --------------------------\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addSTudent(){ //增加学生信息
|
|
|
|
|
|
|
|
|
|
` `int i = 0;
|
|
|
|
|
|
|
|
|
|
` `while(1){
|
|
|
|
|
|
|
|
|
|
` `if(student[i].ID == 0&&i!=N){//找一个空位置存放该学生信息
|
|
|
|
|
|
|
|
|
|
` `scanf:
|
|
|
|
|
|
|
|
|
|
` `printf("请输入学生学号:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%d",&student[i].ID);
|
|
|
|
|
|
|
|
|
|
` `for(int j=0;j<N;j++){
|
|
|
|
|
|
|
|
|
|
` `if(student[i].ID == student[j].ID&&i!=j){
|
|
|
|
|
|
|
|
|
|
` `printf("该学生学号已经存在,请重新输入\n");
|
|
|
|
|
|
|
|
|
|
` `goto scanf;
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `printf("请输入学生姓名:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%s",student[i].name);
|
|
|
|
|
|
|
|
|
|
` `printf("请输入学生生日(格式年/月/日):");
|
|
|
|
|
|
|
|
|
|
` `scanf("%d/%d/%d",&student[i].birthday.year,&student[i].birthday.month,&student[i].birthday.day);
|
|
|
|
|
|
|
|
|
|
` `printf("请输入学生性别:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%s",student[i].sex);
|
|
|
|
|
|
|
|
|
|
` `printf("请输入学生年龄:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%d",&student[i].age);
|
|
|
|
|
|
|
|
|
|
` `printf("请输入学生专业:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%s",student[i].major);
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `i++;
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `printf("添加成功\n");
|
|
|
|
|
|
|
|
|
|
` `system("pause");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void listStudent(){
|
|
|
|
|
|
|
|
|
|
` `printf("姓名\t学号\t性别\t年龄\t专业\t\t生日\n");
|
|
|
|
|
|
|
|
|
|
` `for(int i=0;i<N;i++){
|
|
|
|
|
|
|
|
|
|
` `if(student[i].ID != 0){
|
|
|
|
|
|
|
|
|
|
` `printf("%s\t%d\t%s\t%d\t%s\t%d年%d月%d日\n",student[i].name,student[i].ID,student[i].sex,student[i].age,student[i].major,student[i].birthday.year,student[i].birthday.month,student[i].birthday.day);
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `system("pause");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void searchStudent(){
|
|
|
|
|
|
|
|
|
|
` `int tab;
|
|
|
|
|
|
|
|
|
|
` `int ID;
|
|
|
|
|
|
|
|
|
|
` `char name[20];
|
|
|
|
|
|
|
|
|
|
` `printf("\n\n");
|
|
|
|
|
|
|
|
|
|
` `printf("===================================\n");
|
|
|
|
|
|
|
|
|
|
` `printf("\*\*1.根据ID查找 \*\*2.根据姓名查找\n");
|
|
|
|
|
|
|
|
|
|
` `printf("=====输入其他任意数字返回主菜单====\n");
|
|
|
|
|
|
|
|
|
|
` `printf("===================================\n");
|
|
|
|
|
|
|
|
|
|
` `printf("请输入菜单编号:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%d",&tab);
|
|
|
|
|
|
|
|
|
|
` `switch (tab) {
|
|
|
|
|
|
|
|
|
|
` `case 1:
|
|
|
|
|
|
|
|
|
|
` `int flag1 = 0;
|
|
|
|
|
|
|
|
|
|
` `printf("请输入要查找的ID:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%d",&ID);
|
|
|
|
|
|
|
|
|
|
` `for(int i=0;i<N;i++){
|
|
|
|
|
|
|
|
|
|
` `if(student[i].ID == ID){
|
|
|
|
|
|
|
|
|
|
` `printf("%s\t%d\t%s\t%d\t%s\t%d年%d月%d日\n",student[i].name,student[i].ID,student[i].sex,student[i].age,student[i].major,student[i].birthday.year,student[i].birthday.month,student[i].birthday.day);
|
|
|
|
|
|
|
|
|
|
` `flag1 = 1;
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `if(flag1 == 0){
|
|
|
|
|
|
|
|
|
|
` `printf("查无此人\n");
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `case 2:
|
|
|
|
|
|
|
|
|
|
` `int flag2 = 0;
|
|
|
|
|
|
|
|
|
|
` `printf("请输入要查找的姓名:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%s",name);
|
|
|
|
|
|
|
|
|
|
` `for(int i=0;i<N;i++){
|
|
|
|
|
|
|
|
|
|
` `if(strcmp(student[i].name,name)==0){
|
|
|
|
|
|
|
|
|
|
` `printf("%s\t%d\t%s\t%d\t%s\t%d年%d月%d日\n",student[i].name,student[i].ID,student[i].sex,student[i].age,student[i].major,student[i].birthday.year,student[i].birthday.month,student[i].birthday.day);
|
|
|
|
|
|
|
|
|
|
` `flag2 = 1;
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `if(flag2 == 0){
|
|
|
|
|
|
|
|
|
|
` `printf("查无此人\n");
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `default:
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `system("pause");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deleteStudent(){
|
|
|
|
|
|
|
|
|
|
` `int tab;
|
|
|
|
|
|
|
|
|
|
` `int ID;
|
|
|
|
|
|
|
|
|
|
` `char name[20];
|
|
|
|
|
|
|
|
|
|
` `printf("\n\n");
|
|
|
|
|
|
|
|
|
|
` `printf("===================================\n");
|
|
|
|
|
|
|
|
|
|
` `printf("\*\*1.根据ID删除 \*\*2.根据姓名删除\n");
|
|
|
|
|
|
|
|
|
|
` `printf("=====输入其他任意数字返回主菜单====\n");
|
|
|
|
|
|
|
|
|
|
` `printf("==========不建议根据姓名删除=======\n");
|
|
|
|
|
|
|
|
|
|
` `printf("===================================\n");
|
|
|
|
|
|
|
|
|
|
` `printf("请输入菜单编号:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%d",&tab);
|
|
|
|
|
|
|
|
|
|
` `switch (tab) {
|
|
|
|
|
|
|
|
|
|
` `case 1:
|
|
|
|
|
|
|
|
|
|
` `int flag1 = 0;
|
|
|
|
|
|
|
|
|
|
` `printf("请输入要删除的ID:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%d",&ID);
|
|
|
|
|
|
|
|
|
|
` `for(int i=0;i<N;i++){
|
|
|
|
|
|
|
|
|
|
` `if(student[i].ID == ID){
|
|
|
|
|
|
|
|
|
|
` `student[i] = student[N];
|
|
|
|
|
|
|
|
|
|
` `flag1 = 1;
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `if(flag1 == 0){
|
|
|
|
|
|
|
|
|
|
` `printf("查无此人\n");
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `case 2:
|
|
|
|
|
|
|
|
|
|
` `int flag2 = 0;
|
|
|
|
|
|
|
|
|
|
` `printf("请输入要删除的姓名:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%s",name);
|
|
|
|
|
|
|
|
|
|
` `for(int i=0;i<N;i++){
|
|
|
|
|
|
|
|
|
|
` `if(strcmp(student[i].name,name)==0){
|
|
|
|
|
|
|
|
|
|
` `student[i] = student[N];
|
|
|
|
|
|
|
|
|
|
` `flag2 = 1;
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `if(flag2 == 0){
|
|
|
|
|
|
|
|
|
|
` `printf("查无此人\n");
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `default:
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void shutdown(){
|
|
|
|
|
|
|
|
|
|
` `run = 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char \*argv[]) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
` `run = 1;
|
|
|
|
|
|
|
|
|
|
` `while(run){
|
|
|
|
|
|
|
|
|
|
` `system("cls");
|
|
|
|
|
|
|
|
|
|
` `menu();
|
|
|
|
|
|
|
|
|
|
` `printf("请输入菜单编号:");
|
|
|
|
|
|
|
|
|
|
` `scanf("%d",&num);
|
|
|
|
|
|
|
|
|
|
` `switch (num) {
|
|
|
|
|
|
|
|
|
|
` `case 1:
|
|
|
|
|
|
|
|
|
|
` `addSTudent();
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `case 2:
|
|
|
|
|
|
|
|
|
|
` `searchStudent();
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `case 3:
|
|
|
|
|
|
|
|
|
|
` `deleteStudent();
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `case 4:
|
|
|
|
|
|
|
|
|
|
` `listStudent();
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `case 5:
|
|
|
|
|
|
|
|
|
|
` `shutdown();
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `default:
|
|
|
|
|
|
|
|
|
|
` `printf("输入错误,请重新输入");
|
|
|
|
|
|
|
|
|
|
` `break;
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `}
|
|
|
|
|
|
|
|
|
|
` `return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### **5.测试结果**
|
|
|
|
|
**1.添加功能**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**2.查询功能**
|
|
|
|
|
|
|
|
|
|
**3.删除功能**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**4.列出信息功能**
|
|
|
|
|
|
|
|
|
|
### **6.总结**
|
|
|
|
|
通过本次上机,我们小组成员分工合作,分组后组长给每个人分配了每个人的任务,虽然过程中有着些许波折,但毕竟是第一次,没有那么完美的默契,最后在齐心协力下,每个人高效的完成了各自的系统各部分功能的实现,此次上机提高了我们协作开发的能力,以及沟通能力等等,在各个方面都有了很大的提升,这次合作的经历也为我们以后程序员合作开发有了一定的启蒙,也感受到了许多人合作开发出属于自己的东西的兴奋感,在未来工作中,庞大的项目往往不是一个人就能完成的,更多的是需要团队的力量,这次分组合作让我们都受益匪浅。
|