简单的学生管理系统给大家参考下
#include<stdio.h>#include<malloc.h>
#include<string.h>
#include<conio.h>
#include<windows.h>
struct Student
{
int sNo;
char sName[20];
int sAge;
};
struct List
{
struct Student student;
struct List* pNext;
};
struct List* pHead = NULL;
//增加学生
void Insert()
{
struct List* pNew=(struct List*)malloc(sizeof(struct List));
printf("请输入学生信息(1111 张三 20):");
scanf("%d %s %d",&pNew->student.sNo,pNew->student.sName,&pNew->student.sAge);
pNew->pNext=pHead;
pHead=pNew;
}
//遍历学生信息
void Traversal()
{
struct List* p=pHead;
printf("学号 姓名 年龄\n");
while(p!=NULL)
{
printf("%-3d %4s %3d\n",p->student.sNo,p->student.sName,p->student.sAge);
p=p->pNext;
}
printf("\n");
}
//查找学生信息
void Find()
{
struct List* p=pHead;
int sNo;
printf("请输入要查找的学号:");
scanf("%d",&sNo);
while(p!=NULL)
{
if(p->student.sNo == sNo)
{
printf("%d %s %d\n",p->student.sNo,p->student.sName,p->student.sAge);
return;
}
p=p->pNext;
}
printf("找不到要查找的学生\n");
}
//删除学生信息
void Del()
{
struct List* p=pHead;
struct List* q=p;
int sNo;
printf("请输入要删除学生的学号:");
scanf("%d",&sNo);
while(p!=NULL&&p->student.sNo !=sNo )
{
q=p;
p=p->pNext;
}
if(p!=NULL&&p->student.sNo == sNo )
{
q->pNext=p->pNext;
if(p == pHead)
{
pHead = pHead->pNext;
}
free(p);
}
else
{
printf("找不到要删除的学生\n");
}
}
//修改学生信息
void Update()
{
struct List* p=pHead;
int sNo;
printf("请输入要修改学生的学号:");
scanf("%d",&sNo);
while(p!=NULL&&p->student.sNo !=sNo )
{
p=p->pNext;
}
if(p!=NULL&&p->student.sNo == sNo )
{
printf("请输入学生信息(1111 张三 20):");
scanf("%d %s %d",&p->student.sNo,p->student.sName,&p->student.sAge);
}
else
{
printf("找不到要修改的学生\n");
}
}
int main()
{
bool q = true;
while(q)
{
printf("---------学生管理系统-------\n");
printf("-------(1)增加学生信息------\n");
printf("-------(2)删除学生信息------\n");
printf("-------(3)查找学生信息------\n");
printf("-------(4)修改学生信息------\n");
printf("-------(5)显示学生信息------\n");
printf("------------q退出-----------\n");
char c=getchar();
switch(c)
{
case '1':
Insert();
break;
case '2':
Del();
break;
case '3':
Find();
break;
case '4':
Update();
break;
case '5':
Traversal();
break;
case 'q':
q = false;
break;
default:
break;
}
c = getche();
system("cls");
}
return 0;
}
[此贴子已经被作者于2017-3-15 22:12编辑过]