标签:c
#include <stdio.h> #define M 10 void modify(struct student *stu, int st);//修改函数 void input(struct student *stu, int st);//输入函数 void (display(struct student *stu, int N));//显示函数 struct student{ int number; //学号 char name[M]; //姓名 char gender[M]; //性别 char place[M]; //籍贯 int grade; //年级 char major[5]; //专业 int Class; //班级 char course[M];//课程 }stu[30];//构造一个名字为 Student 的结构体 int main() { int i; int a;//添加的学生个数 int ad;//添加的学生序号(第几个学生) int op;//根据输入的数字确定执行的运算 int st;//修改的学生的序号 int flag=0;//计数标志 struct student stu[30] = { {101, "aaa", "x", "shanghai", 15, "CS", 01, "chinese"}, {102, "aab", "y", "beijing", 16, "DN", 02, "English"}, {103, "aac", "x", "sichuan", 14, "CS", 03, "math"}, {104, "aad", "x", "chengdu", 13, "CS", 04, "chinese"}, {105, "aae", "y", "dandong", 13, "DN", 01, "English"}, {106, "aaf", "x", "shanghai", 15, "CS", 01, "chinese"}, {107, "aag", "y", "beijing", 16, "DN", 02, "English"}, {108, "aah", "x", "sichuan", 14, "CS", 03, "math"}, {109, "aai", "x", "chengdu", 13, "CS", 04, "chinese"}, {110, "aaj", "y", "dandong", 13, "DN", 01, "English"} }; do{ printf("-1, 退出\n"); printf("1, 输入\n"); printf("2, 修改\n"); printf("3, 显示\n"); scanf("%d", &op); switch(op){ //根据输入的数字确定执行的运算 case -1: printf("您没有进行任何操作!\n"); flag=1; case 1: printf("(1-10)请输入添加学生的个数:"); scanf("%d", &a); for(i=0, ad=11; i<a; i++, ad++){ printf("对第%d个学生进行添加操作:\n", ad); input(&stu[ad], ad);//调用输入函数 } break; case 2: printf("请输入需要修改的学生的序号(1-10):"); scanf("%d", &st); st = st-1; modify(&stu[st], st);//调用修改函数 break; case 3: display(stu, M);//调用显示函数 break; default: printf("Unknown operator!\n"); } if(flag) break; }while(op); return 0; } //修改函数 void modify(struct student *stu, int st) { int att; printf("(1)number\n"); printf("(2)name\n"); printf("(3)gender\n"); printf("(4)place\n"); printf("(5)grade\n"); printf("(6)major\n"); printf("(7)Class\n"); printf("(8)course\n"); printf("请输入需要修改的数据(1-8):"); scanf("%d", &att); switch(att) { case 1: printf("student[%d] 原来的学号为%d\n", st, stu[st].number); printf("修改为:"); scanf("%d", &stu[st].number); printf("student[%d] 修改后的学号为%d\n", st, stu[st].number); break; case 2: printf("student[%d] 原来的姓名为%s\n", st, stu[st].name); printf("修改为:"); scanf("%s", &stu[st].name); printf("student[%d] 修改后的姓名为%s\n", st, stu[st].name); break; case 3: printf("student[%d] 原来的性别为%c\n", st, stu[st].gender); printf("修改为:"); scanf("%c", &stu[st].gender); printf("student[%d] 修改后的性别为%c\n", st, stu[st].gender); break; case 4: printf("student[%d] 原来的籍贯为%s\n", st, stu[st].place); printf("修改为:"); scanf("%s", &stu[st].place); printf("student[%d] 修改后的籍贯为%s\n", st, stu[st].place); break; case 5: printf("student[%d] 原来的年级为%d\n", st, stu[st].grade); printf("修改为:"); scanf("%d", &stu[st].grade); printf("student[%d] 修改后的年级为%d\n", st, stu[st].grade); break; case 6: printf("student[%d] 原来的专业为%s\n", st, stu[st].major); printf("修改为:"); scanf("%s", &stu[st].major); printf("student[%d] 修改后的专业为%s\n", st, stu[st].major); break; case 7: printf("student[%d] 原来的班级为%d\n", st, stu[st].Class); printf("修改为:"); scanf("%d", &stu[st].Class); printf("student[%d] 修改后的班级为%d\n", st, stu[st].Class); break; case 8: printf("student[%d] 原来的课程为%s\n", st, stu[st].course); printf("修改为:"); scanf("%s", &stu[st].course); printf("student[%d] 修改后的课程为%s\n", st, stu[st].course); break; default: printf("Unknown operator!\n"); } } //输入函数 void input(struct student *stu, int st) { printf("请输入添加学生的:\n"); printf("学号:"); scanf("%d", &stu[st].number); printf("姓名:"); scanf("%s", &stu[st].name); printf("性别:"); scanf("%s", &stu[st].gender); printf("籍贯:"); scanf("%s", &stu[st].place); printf("年级:"); scanf("%d", &stu[st].grade); printf("专业:"); scanf("%s", &stu[st].major); printf("班级:"); scanf("%d", &stu[st].Class); printf("学习课程:"); scanf("%s", &stu[st].course); printf("|-----------------------------------------------------------------------------------------------------|\n"); printf("| number | name | gender | place | grade | major | Class | course |\n"); printf("|------------|------------|------------|-------------|-----------|-----------|----------|-------------|\n"); printf("| %d %s %s %s %d %s %d %s \n", stu[st].number, stu[st].name, stu[st].gender, stu[st].place, stu[st].grade, stu[st].major, stu[st].Class, stu[st].course); printf("|-----------------------------------------------------------------------------------------------------|\n"); } //显示函数 void display(struct student *stu, int N) { int i; printf("+*****************************************************************************************************+\n"); printf("| number | name | gender | place | grade | major | Class | course |\n"); for(i=0; i<N; i++){ printf("|------------|------------|------------|-------------|-----------|-----------|----------|-------------|\n"); printf("| %d %s %s %s %d %s %d %s \n", stu[i].number, stu[i].name, stu[i].gender, stu[i].place, stu[i].grade, stu[i].major, stu[i].Class, stu[i].course); } printf("+*****************************************************************************************************+\n"); }
本文出自 “12090619” 博客,请务必保留此出处http://12100619.blog.51cto.com/12090619/1944659
标签:c
原文地址:http://12100619.blog.51cto.com/12090619/1944659