Update main.c

main
p6xmqsebw 6 months ago
parent 64299376be
commit a9cf74e4f1

@ -1,6 +1,203 @@
#include <stdio.h>
int main()
{
return 0;
#include <stdlib.h>
#include <string.h>
#define N 99
static int run;
static int num;
struct Date{
int year;
int month;
int day;
};
struct Student{
int ID;
char name[20];
char sex[1];
int age;
char major[20];
struct Date birthday;
};
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;
}
Loading…
Cancel
Save