学生管理系统 学生信息包括:学号、姓名、性别、年龄
1.功能概述:
1)查询学生信息 按学号或姓名查询
2)添加学生信息
3)修改学生信息
4)删除学生信息
5)对学生按照学号排序并输出其信息
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 30
typedef struct Student node; //利用链表结构存储学生信息
struct Student
{
/*数据域*/
int num;//学号
char name[20];//姓名
char sex[10];//性别
int age;//年龄
/*指针域*/
node* next;//指向下一个学生
};
void Show()
{
printf("================================主菜单================================\n");
printf("1,添加学生信息 \n");
printf("2,查询学生信息 (按学号或姓名查询) \n");
printf("3,修改学生信息\n");
printf("4,删除学生信息\n");
printf("5,对学生按照学号排序并输出其信息 \n");
printf("======================================================================\n");
}
/*输入n个学生信息*/
node* Input(int n)
{
node* p = NULL;
node* head =NULL;
int i = 1;
while(i <= n)
{
printf("------------------------------------\n");
if(!head){
head = p =(node *)malloc(sizeof(struct Student));
/*输入学生基本信息*/
printf("输入学生学号:\t");
scanf("%d",&p->num);
printf("输入学生姓名:\t");
scanf("%s", p->name);
printf("输入学生性别:\t");
scanf("%s", p->sex);
printf("输入学生年龄:\t");
scanf("%d", &p->age);
p->next = NULL;
}else{
p->next = (node*)malloc(sizeof(struct Student));
/*输入学生基本信息*/
printf("输入学生学号:\t");
scanf("%d",&p->next->num);
printf("输入学生姓名:\t");
scanf("%s", p->next->name);
printf("输入学生性别:\t");
scanf("%s", p->next->sex);
printf("输入学生年龄:\t");
scanf("%d", &p->next->age);
p->next->next = NULL;
p = p->next;
}
++i;
}
return head;
}
/*添加学生信息*/
node* Add(node* p)
{
system("cls");
show();
int n;
printf("\n请输入添加几个学生的信息:\t");
scanf("%d",&n);
if(p==NULL){
node* p = Input(n);
return p;
}
node* head = p;
while(n>0){
if(p->next==NULL){
printf("\n");
p->next = (node*)malloc(sizeof(struct Student));
/*输入学生基本信息*/
printf("输入学生学号:\t");
scanf("%d",&p->next->num);
printf("输入学生姓名:\t");
scanf("%s", p->next->name);
printf("输入学生性别:\t");
scanf("%s", p->next->sex);
printf("输入学生年龄:\t");
scanf("%d", &p->next->age);
p->next->next = NULL;
n--;//次数减一
}
p = p->next;
}
return head;
}
/*寻找学生信息*/
node* Search(node* p)
{
system("cls");
show();
if(!p){
printf("\n无 法 查 询!\n");
return NULL;
}
int k;//n下岗了
node* p1 = p;
printf("\n请输入您需要查找的学生学号:\t");
scanf("%d", &k);
while(p1){
if(p1->num==k){
printf("\n------------------------------------\n");
printf("学生学号:%5d\n学生姓名:%5s\n学生性别:%5s\n学生年龄:%5d\n\n",p1->num,p1->name,p1->sex,p1->age);
printf("\n查 询 成 功 !\n");
return p;
}
p1 = p1->next