c语言课程设计

班级档案管理系统
一、问题描述:
对一个有N个学生的班级,通过该系统实现对该班级学生的基本信息进行录入、显示、修改、删除、保存等操作的管理。
二、功能要求:
1. 本系统采用一个包含N个数据的结构体数组,每个数据的结构应当包括:学号、姓名、性别、年龄、备注。
2. 本系统显示这样的菜单:
请选择系统功能项:
a. 学生基本信息录入
b. 学生基本信息显示
c. 学生基本信息保存
d. 学生基本信息删除
e. 学生基本信息修改(要求先输入密码)
f. 学生基本信息查询
(1) 按学号查询
(2) 按姓名查询
(3) 按性别查询
(4) 按年龄查询
g. 退出系统
3. 执行一个具体的功能之后,程序将重新显示菜单。
4. 将学生基本信息保存到文件中。
5. 进入系统之前要先输入密码。
三、算法提示:
1. 数据结构:结构体类型数组
2. 数据库结构:下表构成该系统的基本数据库。
姓名 学号 性别 年龄 备注
char char char int char
四、测试数据:
学生人数N=10

刚为别人做了一个,和你这个很像,不过用的是单项链表方式而不是array.
自己修改下满足你的要求吧

#include <stdio.h>
#include <string.h>
#include <stddef.h>

struct StudentCard {
int index; //学生号
char name[80]; //姓名
int age; //年龄
char sex[80]; //性别
int classroom; //班级
char school[80]; //学校
char birthday[80]; //出生年月
struct StudentCard *next; //到下一个学生卡,链表
};

typedef struct StudentCard ELEMENT; //自定义符号
typedef ELEMENT *LINK;

LINK add(LINK head){ //加入一个新的学生信息,该函数将返回一个struct的指针
int index,age,classroom;
char name[80],sex[80],school[80],birthday[80];
printf("Please input index number: ");
scanf("%d",&index);
printf("Please input name: ");
scanf("%s",name);
printf("Please input age: ");
scanf("%d",&age);
printf("Please input sex(nan or nv): ");
scanf("%s",sex);
printf("Please input classroom: ");
scanf("%d",&classroom);
printf("Please input school: ");
scanf("%s",school);
printf("Please input birthday :");
scanf("%s",birthday);

if (!head){ //如果是头链表为空的情况,也就是输入第一个学生卡
head=malloc(sizeof(ELEMENT));
head->index=index;
head->age=age;
head->classroom=classroom;
strcpy(head->name,name);
strcpy(head->sex,sex);
strcpy(head->school,school);
strcpy(head->birthday,birthday);
head->next=NULL; //下一个元素为NULL,空
printf("Successful!\n");
return head; //返回头链
}
else{
LINK tail=head;//用一个哨兵指针指向头元素
while ((tail)&&(tail->index!=index))
//在tail为NULL并且tail的index不与用户输入的index相等之前,tail一直跳到下一个元素
tail=tail->next;
if (tail) //如果存在这个tail
printf("index has already existed! Failed!\n");
else{
tail=head;//再次初始化
while (tail->next) //当哨兵的下一个元素存在时,哨兵跳到哨兵下一个元素
tail=tail->next;
//当上面这个循环结束后,此时tail的下一个元素必定为NULL
tail->next=malloc(sizeof(ELEMENT));//创建新的元素
tail=tail->next; //跳转到下一个新创建的元素
tail->index=index;
tail->age=age;
tail->classroom=classroom;
strcpy(tail->name,name);
strcpy(tail->sex,sex);
strcpy(tail->school,school);
strcpy(tail->birthday,birthday);
tail->next=NULL;
printf("Successful!\n");
return head;
}
}
}

void Print_ALL(LINK head){//该函数输出所有学生信息
LINK tail=head;
if (!head) //如果头元素为NULL,就是链表无一个元素
printf("Empty List!\n");
else{
printf("Indx\tName\tAge\tSex\tClass\tSchool\tBirth\n");
while (tail){//知道哨兵为NULL之前,一直输出哨兵的内容
printf("%d\t%s\t",tail->index,tail->name);
printf("%d\t%s\t%d\t",tail->age,tail->sex,tail->classroom);
printf("%s\t%s\n",tail->school,tail->birthday);
tail=tail->next;
}
}
};

void Print_DEPEND_INDEX(LINK head){ //该函数输出指定的学生号的学生信息
int tem;
LINK tail=head;
printf("Please input the index number of student: ");
scanf("%d",&tem);
if (!head)
printf("Empty List!\n");
else{
while ((tail)&&(tail->index!=tem))
tail=tail->next;
if (!tail)
printf("student not existed!\n");
else{
printf("Indx\tName\tAge\tSex\tClass\tSchool\tBirth\n");
printf("%d\t%s\t",tail->index,tail->name);
printf("%d\t%s\t%d\t",tail->age,tail->sex,tail->classroom);
printf("%s\t%s\n",tail->school,tail->birthday);
}
}
}

void Print_DEPEND_CLASS(LINK head){ //该函数输出指定的班级的学生信息
int tem;
LINK tail=head;
printf("Please input classroom: ");
scanf("%d",&tem);
if (!head)
printf("Empty List!\n");
else{
while ((tail)&&(tail->classroom!=tem))
tail=tail->next;
if (!tail)
printf("No such classroom!\n");
else{
printf("Indx\tName\tAge\tSex\tClass\tSchool\tBirth\n");
while (tail){
if (tail->classroom==tem){
printf("%d\t%s\t",tail->index,tail->name);
printf("%d\t%s\t%d\t",tail->age,tail->sex,tail->classroom);
printf("%s\t%s\n",tail->school,tail->birthday);
}
tail=tail->next;
}
}
}
}

void Print_DEPEND_SEX(LINK head){ //该函数输出男或女同学信息
char tem[80];
printf("please input sex(nan or nv): ");
scanf("%s",tem);
if (!head)
printf("Empty List!\n");
else{
LINK tail=head;
while ((tail)&&(strcmp(tem,tail->sex)!=0))
//当不相等或者tail有效时,tail跳到下一个元素
tail=tail->next;
if (!tail)
printf("No %s student!\n",tem);
else{
tail=head;
printf("Indx\tName\tAge\tSex\tClass\tSchool\tBirth\n");
while (tail){
if (strcmp(tem,tail->sex)==0){
printf("%d\t%s\t",tail->index,tail->name);
printf("%d\t%s\t%d\t",tail->age,tail->sex,tail->classroom);
printf("%s\t%s\n",tail->school,tail->birthday);
}
tail=tail->next;
}
}
}
}

LINK Edit(LINK head){ //该函数用来修改信息
int tem;
LINK tail=head;
printf("Please input index of student: ");
scanf("%d",&tem);
if (!head){
printf("Empty List!\n");
return NULL;
}
else{
while ((tail)&&(tail->index!=tem))
tail=tail->next;
if (!tail){
printf("No such student!\n");
return head;
}
else{
printf("Please input name: ");
scanf("%s",tail->name);
printf("Please input age: ");
scanf("%d",&tail->age);
printf("Please input sex(nan or nv): ");
scanf("%s",tail->sex);
printf("Please input classroom: ");
scanf("%d",&tail->classroom);
printf("Please input school: ");
scanf("%s",tail->school);
printf("Please input birthday :");
scanf("%s",tail->birthday);
printf("Edit successful!\n");
return head;
}
}
}

LINK DELETE(LINK head){ //该函数用来删除学生信息
int tem;
LINK tail=head;
printf("Please input index of student: ");
scanf("%d",&tem);
if (!head){
printf("Empty List!\n");
return NULL;
}
else if ((head->index==tem)&&(!head->next)){//当头元素满足并且链表只有一个元素
printf("Deleted!\n");
return NULL;
}
else if ((head->index==tem)&&(head->next)){//当头元素满足并且链表有许多元素
printf("Deleted!\n");
return head->next;
}
else{ //当满足条件的元素在链表中间或者结尾
while ((tail)&&(tail->index!=tem))
tail=tail->next;
if (!tail){
printf("No such student!\n");
return head;
}
else{
if (!tail->next){//当满足条件的元素在链表结尾
LINK tail2=head;//新的哨兵
while (tail2->next!=tail)
tail2=tail2->next;
tail2->next=NULL; //直接指向为NULL,表示链表尾,跳过tail
printf("Deleted!\n");
return head;
}
else{ //当满足条件的元素在链表中间
LINK tail2=head;//新的哨兵
while (tail2->next!=tail)
tail2=tail2->next;
tail2->next=tail->next; //跳过tail这个元素
printf("Deleted!\n");
return head;
}
}
}
}

void Display_MENU(){
printf("\t*********studentcard management system*********\n");
printf("\t1.Input student's informations (add a student)\n");
printf("\t2.Print all students' informations\n");
printf("\t3.Input index number,print selected student's information\n");
printf("\t4.Input classroom number,print informations of those students\n");
printf("\t5.Input index number, modify information\n");
printf("\t6.Input index number, remove information\n");
printf("\t7.Print nan or nv informations\n");
printf("\t8.Display Menu\n");
printf("\t9.Exit\n");
printf("\t***********************************************\n");
}

int main(){
LINK head=NULL; //链表头的初始化
int asker;
Display_MENU();
while(1){
printf(">>");
scanf("%d",&asker);
if (asker==1)//加入新学生信息
head=add(head);
else if (asker==2)//输出所有学生信息
Print_ALL(head);
else if (asker==3) //输入学生号,输出学生信息
Print_DEPEND_INDEX(head);
else if (asker==4) //输入班级,输出学生信息
Print_DEPEND_CLASS(head);
else if (asker==5) //输入学生号,修改学生信息
head=Edit(head);
else if (asker==6) //输入学生号,删除学生信息
DELETE(head);
else if (asker==7) //输入男或女,输出学生信息
Print_DEPEND_SEX(head);
else if (asker==8) //显示菜单
Display_MENU();
else if (asker==9) //退出程序,也就是退出while(1)循环
break;
else
printf("please select correct number!\n");
}
printf("system log-out!\n");
return 0;
}
温馨提示:答案为网友推荐,仅供参考