#define _CRT_SECURE_NO_WARNINGS
/*************************************************************
项 目 名:学生管理系统
作 者:零起点
编译环境:vs2015
版 本:3.0
工 能:1.输入数据
2.查看数据
3.修改数据
4.删除数据
5.插入数据
因为我没有时间去写 6.保存数据 如果赶兴趣请您自己写写 TXT文件
**************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define account_number "123456789"//定义账号
#define password "123456" //定义密码
//创建学生
typedef struct student
{
char Student_ID[6];//学生学号
char name[9];//学生姓名
char sex[3];//学生性别
unsigned int age;//学生年龄
float score;//入学成绩
struct student * pNext;
}NODE,*PNODE;
void main_window(void);
PNODE Create_linked_list(void);
void Output_linked_list(PNODE Student_library);
int statistics(PNODE pHew);//
void seqencing(PNODE pHew);
void delete_list(PNODE pHead);
void insert_list(PNODE pHead);
void revise(PNODE pHead);
int main(void)
{
char ch[10], ch1[7];
//简单的登录系统
printf("用户名:");
scanf("%s", ch);
printf("密 码:");
scanf("%s", ch1);
if (strcmp(ch, account_number) == 0)
if (strcmp(ch1, password) == 0)
main_window();
else
printf("密码错误!!!");
else
printf("用户和密码错误!!!");
system("pause");
return 0;
}
//进入主窗口
void main_window(void)
{
char ch;
PNODE pHead = NULL;
B:
system("mode con cols=150 lines=40");//修改窗口大小
printf("\n\n\t\t\t\t\t\t\t学生管理系统\n");
printf("\t\t\t\t\t\t┏━━━━━━━━━━━━┓\n");
printf("\t\t\t\t\t\t┃ 1.输入数据 ┃\n");
printf("\t\t\t\t\t\t┃ 2.查看数据 ┃\n");
printf("\t\t\t\t\t\t┃ 3.修改数据 ┃\n");
printf("\t\t\t\t\t\t┃ 4.删除数据 ┃\n");
printf("\t\t\t\t\t\t┃ 5.插入数据 ┃\n");
//printf("\t\t\t\t\t\t┃ 6.保存数据 ┃\n");
printf("\t\t\t\t\t\t┗━━━━━━━━━━━━┛\n");
printf("请输入你需要的功能:");
A:
scanf(" %c", &ch);
switch (ch)
{
case '1':pHead = Create_linked_list(); goto B; break;
case '2':Output_linked_list(pHead); goto B; break;
case '3':revise(pHead); goto B; break;
case '4':delete_list(pHead); goto B; break;
case '5':insert_list(pHead); goto B; break;
//case '6':break;
default:printf("输入错误,请从新输入:");goto A;break;
}
}
//创建链表
PNODE Create_linked_list()
{
int len = 0;
char ch;
printf("请输入学生个数:len = ");
scanf("%d", &len);
PNODE Student_library = (PNODE)malloc(sizeof(NODE));//动态分配内存
if (Student_library == NULL)//判断是否分配成功
{
printf_s("分配内存失败!");
exit(-1);
}
PNODE pTail = Student_library;//把首节点赋给 pTail
pTail->pNext = NULL;//把首节点下一个节点 赋值空
for (int i = 0; i < len; ++i)
{
char Student_ID[6];//学号
char name[9];//姓名
char sex[3];//性别
unsigned int age;//年龄
float score;//入学成绩
fflush(stdin);
printf("请输入第%d学生的学号:", i + 1);
scanf("%s", Student_ID);//临时赋值
printf("请输入第%d学生的姓名:", i + 1);
scanf("%s", name);
printf("请输入第%d学生的性别:", i + 1);
scanf("%s", sex);
printf("请输入第%d学生的年龄:", i + 1);
scanf("%d", &age);
printf("请输入第%d学生的入学成绩:", i + 1);
scanf("%f", &score);
PNODE pHew = (PNODE)malloc(sizeof(NODE));
if (pHew == NULL)
{
printf_s("分配内存失败!");
exit(-1);
}
strcpy(pHew->Student_ID, Student_ID);
strcpy(pHew->name, name);
strcpy(pHew->sex, sex);
pHew->age = age;
pHew->score = score;
pTail->pNext = pHew;
pHew->pNext = NULL;
pTail = pHew;
}
printf("Y/N是否继续:");
scanf(" %c", &ch);
if(ch=='Y'||ch=='y')
return Student_library;
}
void Output_linked_list(PNODE Student_library)
{
char ch;
printf("Y/N是否按成绩排序输出:");
scanf(" %c", &ch);
if (ch == 'Y' || ch == 'y')
seqencing(Student_library);
PNODE g;
if(Student_library !=NULL)
g = Student_library->pNext;
else
g = NULL;
printf("\t\t\t┏━━━┳━━━━┳━━━┳━━━┳━━━━━┓\n");
printf("\t\t\t┃%-6s┃%-8s┃%-6s┃%-5s ┃%-8s ┃\n", "学号", "姓名", "性别", "年龄", "入学成绩");
while (g != NULL)
{
printf("\t\t\t┣━━━╋━━━━╋━━━╋━━━╋━━━━━┫\n");
printf("\t\t\t┃%-6s┃%-8s┃%-6s┃%-5d ┃%-8.1f ┃\n",g->Student_ID,g->name, g->sex, g->age,g->score);
g =g->pNext;
}
printf("\t\t\t┗━━━┻━━━━┻━━━┻━━━┻━━━━━┛\n");
printf("Y/N是否继续:");
scanf(" %c", &ch);
if (ch == 'Y' || ch == 'y')
return;
else
exit(-1);
return;
}
int statistics(PNODE pHew)
{
PNODE p;
int len = 0;
if (pHew != NULL)
p = pHew->pNext;
else
p = NULL;
while (p!=NULL)
{
++len;
p = p->pNext;
}
return len;
}
void seqencing(PNODE pHew)
{
int i, j;
int len = statistics(pHew);
PNODE P, Q;
for(i=0,P=pHew->pNext;i<len;++i,P->pNext)
for (j = i + 1, Q = P->pNext; j < len; ++j, Q->pNext)
{
if (P->score < Q->score)
{
char Student_ID[6];
char name[9];
char sex[3];
unsigned int age;
float score;
strcpy(Student_ID, Q->Student_ID);
strcpy(Q->Student_ID, P->Student_ID);
strcpy(P->Student_ID, Student_ID);
strcpy(name, Q->name);
strcpy(Q->name, P->name);
strcpy(P->name, name);
strcpy(sex, Q->sex);
strcpy(Q->sex, P->sex);
strcpy(P->sex, sex);
age = Q->age;
Q->age = P->age;
P->age = age;
score = Q->score;
Q->score = P->score;
P->score = score;
}
}
return;
}
void delete_list(PNODE pHead)
{
char ch;
int i = 0, len = statistics(pHead);
char Student_ID[6];
PNODE e=pHead, p = pHead;
printf("请输入输出学生的学号:");
scanf("%s", Student_ID);
while (strcmp(Student_ID,p->Student_ID)!=0&&i<=len)//找到节点的位置
{
p = p->pNext;
++i;
}
if (i < len)
{
for (int a = 1; a < i; ++a)
e = e->pNext;
printf("Y\N是否删除数据:\n");
printf("\t\t\t┏━━━┳━━━━┳━━━┳━━━┳━━━━━┓\n");
printf("\t\t\t┃%-6s┃%-8s┃%-6s┃%-5d ┃%-8.1f ┃\n", p->Student_ID, p->name, p->sex, p->age, p->score);
printf("\t\t\t┗━━━┻━━━━┻━━━┻━━━┻━━━━━┛\n");
scanf(" %c", &ch);
if (ch == 'Y' || ch == 'y')
{
PNODE q = e->pNext;
e->pNext = e->pNext->pNext;
free(q);
q = NULL;
}
p = NULL;
return;
}
else
printf("没有查找到数据!!");
return;
}
void insert_list(PNODE pHead)
{
char Student_ID[6];
int i = 0,len = statistics(pHead);
PNODE p = pHead;
printf("请输入插入学生前的学号:");
scanf("%s", Student_ID);
while (strcmp(Student_ID, p->Student_ID) != 0 && i < len)
{
p->pNext;
i++;
}
PNODE pNew = (PNODE)malloc(sizeof(NODE));
if (pNew == NULL)
{
printf("内存分配失败!\n");
exit(-1);
}
printf("请输入学生学号:");
scanf("%s", pNew->Student_ID);
printf("请输入学生姓名:");
scanf("%s",pNew->name );
printf("请输入学生性别:");
scanf("%s",pNew->sex );
printf("请输入学生年龄:");
scanf("%d", &pNew->age);
printf("请输入学生入学成绩:");
scanf("%f", &pNew->score);
PNODE q = p->pNext;
p->pNext = pNew;
pNew->pNext = q;
return;
}
void revise(PNODE pHead)
{
char Student_ID[6];
PNODE p = pHead;
printf("请输入学生学号:");
scanf(" %s", Student_ID);
while (strcmp(Student_ID,p->Student_ID)!=0)
p=p->pNext;
printf("请输入学生学号:");
scanf("%s", p->Student_ID);
printf("请输入学生姓名:");
scanf("%s", p->name);
printf("请输入学生性别:");
scanf("%s", p->sex);
printf("请输入学生年龄:");
scanf("%d", &p->age);
printf("请输入学生入学成绩:");
scanf("%f", &p->score);
return;
}
/*************************************************************
项 目 名:学生管理系统
作 者:零起点
编译环境:vs2015
版 本:3.0
工 能:1.输入数据
2.查看数据
3.修改数据
4.删除数据
5.插入数据
因为我没有时间去写 6.保存数据 如果赶兴趣请您自己写写 TXT文件
**************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define account_number "123456789"//定义账号
#define password "123456" //定义密码
//创建学生
typedef struct student
{
char Student_ID[6];//学生学号
char name[9];//学生姓名
char sex[3];//学生性别
unsigned int age;//学生年龄
float score;//入学成绩
struct student * pNext;
}NODE,*PNODE;
void main_window(void);
PNODE Create_linked_list(void);
void Output_linked_list(PNODE Student_library);
int statistics(PNODE pHew);//
void seqencing(PNODE pHew);
void delete_list(PNODE pHead);
void insert_list(PNODE pHead);
void revise(PNODE pHead);
int main(void)
{
char ch[10], ch1[7];
//简单的登录系统
printf("用户名:");
scanf("%s", ch);
printf("密 码:");
scanf("%s", ch1);
if (strcmp(ch, account_number) == 0)
if (strcmp(ch1, password) == 0)
main_window();
else
printf("密码错误!!!");
else
printf("用户和密码错误!!!");
system("pause");
return 0;
}
//进入主窗口
void main_window(void)
{
char ch;
PNODE pHead = NULL;
B:
system("mode con cols=150 lines=40");//修改窗口大小
printf("\n\n\t\t\t\t\t\t\t学生管理系统\n");
printf("\t\t\t\t\t\t┏━━━━━━━━━━━━┓\n");
printf("\t\t\t\t\t\t┃ 1.输入数据 ┃\n");
printf("\t\t\t\t\t\t┃ 2.查看数据 ┃\n");
printf("\t\t\t\t\t\t┃ 3.修改数据 ┃\n");
printf("\t\t\t\t\t\t┃ 4.删除数据 ┃\n");
printf("\t\t\t\t\t\t┃ 5.插入数据 ┃\n");
//printf("\t\t\t\t\t\t┃ 6.保存数据 ┃\n");
printf("\t\t\t\t\t\t┗━━━━━━━━━━━━┛\n");
printf("请输入你需要的功能:");
A:
scanf(" %c", &ch);
switch (ch)
{
case '1':pHead = Create_linked_list(); goto B; break;
case '2':Output_linked_list(pHead); goto B; break;
case '3':revise(pHead); goto B; break;
case '4':delete_list(pHead); goto B; break;
case '5':insert_list(pHead); goto B; break;
//case '6':break;
default:printf("输入错误,请从新输入:");goto A;break;
}
}
//创建链表
PNODE Create_linked_list()
{
int len = 0;
char ch;
printf("请输入学生个数:len = ");
scanf("%d", &len);
PNODE Student_library = (PNODE)malloc(sizeof(NODE));//动态分配内存
if (Student_library == NULL)//判断是否分配成功
{
printf_s("分配内存失败!");
exit(-1);
}
PNODE pTail = Student_library;//把首节点赋给 pTail
pTail->pNext = NULL;//把首节点下一个节点 赋值空
for (int i = 0; i < len; ++i)
{
char Student_ID[6];//学号
char name[9];//姓名
char sex[3];//性别
unsigned int age;//年龄
float score;//入学成绩
fflush(stdin);
printf("请输入第%d学生的学号:", i + 1);
scanf("%s", Student_ID);//临时赋值
printf("请输入第%d学生的姓名:", i + 1);
scanf("%s", name);
printf("请输入第%d学生的性别:", i + 1);
scanf("%s", sex);
printf("请输入第%d学生的年龄:", i + 1);
scanf("%d", &age);
printf("请输入第%d学生的入学成绩:", i + 1);
scanf("%f", &score);
PNODE pHew = (PNODE)malloc(sizeof(NODE));
if (pHew == NULL)
{
printf_s("分配内存失败!");
exit(-1);
}
strcpy(pHew->Student_ID, Student_ID);
strcpy(pHew->name, name);
strcpy(pHew->sex, sex);
pHew->age = age;
pHew->score = score;
pTail->pNext = pHew;
pHew->pNext = NULL;
pTail = pHew;
}
printf("Y/N是否继续:");
scanf(" %c", &ch);
if(ch=='Y'||ch=='y')
return Student_library;
}
void Output_linked_list(PNODE Student_library)
{
char ch;
printf("Y/N是否按成绩排序输出:");
scanf(" %c", &ch);
if (ch == 'Y' || ch == 'y')
seqencing(Student_library);
PNODE g;
if(Student_library !=NULL)
g = Student_library->pNext;
else
g = NULL;
printf("\t\t\t┏━━━┳━━━━┳━━━┳━━━┳━━━━━┓\n");
printf("\t\t\t┃%-6s┃%-8s┃%-6s┃%-5s ┃%-8s ┃\n", "学号", "姓名", "性别", "年龄", "入学成绩");
while (g != NULL)
{
printf("\t\t\t┣━━━╋━━━━╋━━━╋━━━╋━━━━━┫\n");
printf("\t\t\t┃%-6s┃%-8s┃%-6s┃%-5d ┃%-8.1f ┃\n",g->Student_ID,g->name, g->sex, g->age,g->score);
g =g->pNext;
}
printf("\t\t\t┗━━━┻━━━━┻━━━┻━━━┻━━━━━┛\n");
printf("Y/N是否继续:");
scanf(" %c", &ch);
if (ch == 'Y' || ch == 'y')
return;
else
exit(-1);
return;
}
int statistics(PNODE pHew)
{
PNODE p;
int len = 0;
if (pHew != NULL)
p = pHew->pNext;
else
p = NULL;
while (p!=NULL)
{
++len;
p = p->pNext;
}
return len;
}
void seqencing(PNODE pHew)
{
int i, j;
int len = statistics(pHew);
PNODE P, Q;
for(i=0,P=pHew->pNext;i<len;++i,P->pNext)
for (j = i + 1, Q = P->pNext; j < len; ++j, Q->pNext)
{
if (P->score < Q->score)
{
char Student_ID[6];
char name[9];
char sex[3];
unsigned int age;
float score;
strcpy(Student_ID, Q->Student_ID);
strcpy(Q->Student_ID, P->Student_ID);
strcpy(P->Student_ID, Student_ID);
strcpy(name, Q->name);
strcpy(Q->name, P->name);
strcpy(P->name, name);
strcpy(sex, Q->sex);
strcpy(Q->sex, P->sex);
strcpy(P->sex, sex);
age = Q->age;
Q->age = P->age;
P->age = age;
score = Q->score;
Q->score = P->score;
P->score = score;
}
}
return;
}
void delete_list(PNODE pHead)
{
char ch;
int i = 0, len = statistics(pHead);
char Student_ID[6];
PNODE e=pHead, p = pHead;
printf("请输入输出学生的学号:");
scanf("%s", Student_ID);
while (strcmp(Student_ID,p->Student_ID)!=0&&i<=len)//找到节点的位置
{
p = p->pNext;
++i;
}
if (i < len)
{
for (int a = 1; a < i; ++a)
e = e->pNext;
printf("Y\N是否删除数据:\n");
printf("\t\t\t┏━━━┳━━━━┳━━━┳━━━┳━━━━━┓\n");
printf("\t\t\t┃%-6s┃%-8s┃%-6s┃%-5d ┃%-8.1f ┃\n", p->Student_ID, p->name, p->sex, p->age, p->score);
printf("\t\t\t┗━━━┻━━━━┻━━━┻━━━┻━━━━━┛\n");
scanf(" %c", &ch);
if (ch == 'Y' || ch == 'y')
{
PNODE q = e->pNext;
e->pNext = e->pNext->pNext;
free(q);
q = NULL;
}
p = NULL;
return;
}
else
printf("没有查找到数据!!");
return;
}
void insert_list(PNODE pHead)
{
char Student_ID[6];
int i = 0,len = statistics(pHead);
PNODE p = pHead;
printf("请输入插入学生前的学号:");
scanf("%s", Student_ID);
while (strcmp(Student_ID, p->Student_ID) != 0 && i < len)
{
p->pNext;
i++;
}
PNODE pNew = (PNODE)malloc(sizeof(NODE));
if (pNew == NULL)
{
printf("内存分配失败!\n");
exit(-1);
}
printf("请输入学生学号:");
scanf("%s", pNew->Student_ID);
printf("请输入学生姓名:");
scanf("%s",pNew->name );
printf("请输入学生性别:");
scanf("%s",pNew->sex );
printf("请输入学生年龄:");
scanf("%d", &pNew->age);
printf("请输入学生入学成绩:");
scanf("%f", &pNew->score);
PNODE q = p->pNext;
p->pNext = pNew;
pNew->pNext = q;
return;
}
void revise(PNODE pHead)
{
char Student_ID[6];
PNODE p = pHead;
printf("请输入学生学号:");
scanf(" %s", Student_ID);
while (strcmp(Student_ID,p->Student_ID)!=0)
p=p->pNext;
printf("请输入学生学号:");
scanf("%s", p->Student_ID);
printf("请输入学生姓名:");
scanf("%s", p->name);
printf("请输入学生性别:");
scanf("%s", p->sex);
printf("请输入学生年龄:");
scanf("%d", &p->age);
printf("请输入学生入学成绩:");
scanf("%f", &p->score);
return;
}