1.教师信息添加.h
cpp
void InputTeacher()
{
int c = 0;
system("cls");
printf("\t\t*************************************************\n");
printf("\t\t******** 欢迎来到教师信息添加系统 **********\n");
printf("\t\t*************************************************\n");
printf("\t\t******** 1.确定添加教师信息 **********\n");
printf("\t\t******** 2.放弃添加教师信息 **********\n");
printf("\t\t*************************************************\n");
printf("请输入您的选项:\n");
scanf("%d", &c);
getchar();
switch (c)
{
case 1:
{
int i;
//动态内存 分配返回值为void型指针(新开辟一个节点用来保存输入的值)
Node* pNewNode = (Node*)malloc(sizeof(Node));
pNewNode->pNext = NULL;
//头插法
if (g_pHead == NULL)//如果第一个节点为空,则新开辟的节点就是头
{
g_pHead = pNewNode;
}
else//如果第一个节点不为空 则把新开辟的节点插到头结点之前 使新开辟的节点成为头(先让新节点的指针域指向
{
pNewNode->pNext = g_pHead;//原来的头 然后再让他成为新的头)
g_pHead = pNewNode;
}
printf("请输入教师姓名:\n");
scanf("%s", pNewNode->teach.T_name);//将新添加的数据存到新开辟的节点里
getchar();
printf("请输入教师性别:\n");
scanf("%s", pNewNode->teach.T_sex);
getchar();
printf("请输入教师年龄:\n");
scanf("%d", &pNewNode->teach.T_age);
getchar();
printf("请输入教师积分:\n");
scanf("%d", &pNewNode->teach.T_score);
getchar();
printf("请输入教师住址:\n");
scanf("%s", pNewNode->teach.T_addr);
getchar();
//进度读取条
{
i = 6;
printf("\t\t玩命加载数据中:");
while (i-- > 0)
{
printf(".");
Sleep(500);
}
printf("\n");
}
printf("教师信息添加成功!\n");
system("pause");
system("cls");
break;
}
case 2:
system("pause");
system("cls");
break;
}
}
2. 教师信息显示.h
cpp
void PrintfTeacher()
{
int c = 0;
system("cls");
printf("\t\t*************************************************\n");
printf("\t\t******** 欢迎来到教师信息显示系统 **********\n");
printf("\t\t*************************************************\n");
printf("\t\t******** 1.确定显示教师信息 **********\n");
printf("\t\t******** 2.放弃显示教师信息 **********\n");
printf("\t\t*************************************************\n");
printf("请输入您的选项:\n");
scanf("%d", &c);
getchar();
switch (c)
{
case 1:
{
system("cls");
printf("\t\t*************************************************\n");
printf("\t\t******** 所有教师信息如下 **********\n");
printf("\t\t*************************************************\n");
printf("\t\t** 姓名 性别 年龄 积分 住址 **\n");
printf("\t\t*************************************************\n");
//遍历链表
Node* p = g_pHead;
while (p != NULL)
{
printf("\t\t%s\t\t%s\t%d\t%d\t%s\n",
p->teach.T_name,
p->teach.T_sex,
p->teach.T_age,
p->teach.T_score,
p->teach.T_addr);
p = p->pNext;
}
system("pause");
system("cls");
break;
}
case 2:system("pause");
system("cls");
break;
}
}
3.教师信息修改.h
cpp
void AfterTeacher()
{
int c = 0;
system("cls");
printf("\t\t*************************************************\n");
printf("\t\t******** 欢迎来到教师信息修改系统 **********\n");
printf("\t\t*************************************************\n");
printf("\t\t******** 1.确定修改教师信息 **********\n");
printf("\t\t******** 2.放弃修改教师信息 **********\n");
printf("\t\t*************************************************\n");
printf("请输入您的选项:\n");
scanf("%d", &c);
getchar();
switch (c)
{
case 1:
{
char XGname[20] = { 0 };
printf("请输入您要修改的教师的姓名:\n");
scanf("%s", XGname);
getchar();
//遍历链表
Node* p = g_pHead;
while (p != NULL)
{
if (strcmp(p->teach.T_name, XGname) == 0)
{
printf("请输入您将要修改的教师姓名:\n");
scanf("%s", p->teach.T_name);
getchar();
printf("请输入您将要修改的教师性别:\n");
scanf("%s", p->teach.T_sex);
getchar();
printf("请输入您将要修改的教师年龄:\n");
scanf("%d", &p->teach.T_age);
getchar();
printf("请输入您将要修改的教师积分:\n");
scanf("%d", &p->teach.T_score);
getchar();
printf("请输入您将要修改的教师住址:\n");
scanf("%s", p->teach.T_addr);
getchar();
printf("教师信息修改成功!\n");
}
else if (p == NULL)//strcmp(p->teach.T_name, XGname) != 0)
{
printf("没有查询到此人!\n");
}
p = p->pNext;
}
system("pause");
system("cls");
break;
}
case 2:
system("pause");
system("cls");
break;
}
}
4.教师信息删除.h
cpp
void DeleteTeacher()
{
int c = 0;
system("cls");
printf("\t\t*************************************************\n");
printf("\t\t******** 欢迎来到教师信息删除系统 **********\n");
printf("\t\t*************************************************\n");
printf("\t\t******** 1.确定删除教师信息 **********\n");
printf("\t\t******** 2.放弃删除教师信息 **********\n");
printf("\t\t*************************************************\n");
printf("请输入您的选项:\n");
scanf("%d", &c);
getchar();
switch (c)
{
case 1:
{
char SCname[20];
printf("请输入您要删除的教师的姓名:\n");
scanf("%s", SCname);
getchar();
Node* p1, * p2;
//判断是不是头结点
if (strcmp(g_pHead->teach.T_name, SCname) == 0)
{
int m = 0;
printf("您是确定要删除此人?(1-确定,2-再想想)\n");
scanf("%d", &m);
getchar();
if (m == 1)
{
p1 = g_pHead;
g_pHead = g_pHead->pNext;
free(p1);
printf("删除成功!\n");
system("pause");
system("cls");
}
else if (m == 2)
{
exit(0);
}
}
//不是头结点
Node* p = g_pHead;
while (p->pNext != NULL)
{
if (strcmp(p->pNext->teach.T_name, SCname) == 0)
{
int m = 0;
printf("您是确定要删除此人?(1-确定,2-再想想)\n");
scanf("%d", &m);
if (m == 1)
{
p2 = p->pNext;
p->pNext = p->pNext->pNext;
free(p2);
printf("删除成功!\n");
system("pause");
system("cls");
}
else if (m == 2)
{
system("pause");
system("cls");
}
}
p = p->pNext;
if (p->pNext == NULL)
{
break;
}
}
if (p->pNext == NULL)
{
printf("查无此人!\n");
}
system("pause");
system("cls");
break;
}
case 2:system("pause");
system("cls");
break;
}
}
5.教师信息查询.h
cpp
Node* FindTeacher()
{
int c = 0;
system("cls");
printf("\t\t*************************************************\n");
printf("\t\t******** 欢迎来到教师信息保存系统 **********\n");
printf("\t\t*************************************************\n");
printf("\t\t******** 1.确定保存教师信息 **********\n");
printf("\t\t******** 2.放弃保存教师信息 **********\n");
printf("\t\t*************************************************\n");
printf("请输入您的选项:\n");
scanf("%d", &c);
getchar();
switch (c)
{
case 1:
{
//验证系统
indentifying_Code();
char teachName[20] = { 0 };
printf("请输入您要查询的名称或姓氏:\n");
scanf("%s", teachName);
getchar();
//遍历链表
Node* p = g_pHead;
while (p != NULL)
{
if (strcmp(p->teach.T_name, teachName) == 0)// 如果输入的名称存在则显示该教师信息
{
printf("姓名:%s\t性别:%s\t年龄:%d\t积分:%d\t住址:%s\n",
p->teach.T_name,
p->teach.T_sex,
p->teach.T_age,
p->teach.T_score,
p->teach.T_addr);
}
else if (p == NULL)//strcmp(p->teach.T_name, teachName) != 0
{
printf("查无此人!\n");
}
p = p->pNext;//移动指针
}
system("pause");
system("cls");
return NULL;
break;
}
case 2:system("pause");
system("cls");
break;
}
}
6.菜单界面.h
cpp
//菜单界面
void showmenu()
{
printf("\t\t*******************************************\n");
printf("\t\t***** 欢迎使用教师信息管理系统 *******\n");
printf("\t\t*******************************************\n");
printf("\t\t*** 教师信息管理系统 *********\n");
printf("\t\t*******************************************\n");
printf("\t\t*** 1.教师信息添加 *********\n");
printf("\t\t*** 2.教师信息显示 *********\n");
printf("\t\t*** 3.教师信息保存 *********\n");
printf("\t\t*** 4.教师信息读取 *********\n");
printf("\t\t*** 5.教师信息查询 *********\n");
printf("\t\t*** 6.教师信息修改 *********\n");
printf("\t\t*** 7.教师信息删除 *********\n");
printf("\t\t*** 8.教师信息排序 *********\n");
printf("\t\t*** 9.教师信息积分计算 *********\n");
printf("\t\t*** 0.退出程序 *********\n");
printf("\t\t*******************************************\n");
printf("请按任意键进行操作:\n");
}
7.教师积分计算.h
cpp
void AddScoreTeacher()
{
char ADDname[20] = { 0 };
int ADDscore = 0;
printf("请输入将要增加积分的教师名称:\n");
scanf("%s", ADDname);
getchar();
printf("请输入将要添加的积分:\n");
scanf("%d", &ADDscore);
getchar();
//遍历链表
Node* p = g_pHead;
while (p != NULL)
{
if (strcmp(p->teach.T_name, ADDname) == 0) //如果输入的人名存在则把第二次的分数加到第一次的分数上(进行累加)
{
p->teach.T_score = p->teach.T_score + ADDscore;
}
else if (p == NULL)
{
printf("没有查询到此人!\n");
}
p = p->pNext;
}
system("pause");
system("cls");
}
8.教师信息读取.h
cpp
void ReadTeacher()
{
int c = 0;
system("cls");
printf("\t\t*************************************************\n");
printf("\t\t******** 欢迎来到教师信息读取系统 **********\n");
printf("\t\t*************************************************\n");
printf("\t\t******** 1.确定读取教师信息 **********\n");
printf("\t\t******** 2.放弃读取教师信息 **********\n");
printf("\t\t*************************************************\n");
printf("请输入您的选项:\n");
scanf("%d", &c);
getchar();
switch (c)
{
case 1:
{
//打开文件
FILE* fp = fopen("txt文本路径", "a+");//a+追加/读取打开文本文件 文件不存在时 建立新文件 存在时在原有文件后追加
if (fp == NULL)
{
printf("文件打开失败!\n");
exit(0);
}
//读文件
Teacher Teach;
Node* p = g_pHead;
while (fread(&Teach, sizeof(Teacher), 1, fp))
{
//创建一个新的节点
Node* pNewNode = (Node*)malloc(sizeof(Node));
pNewNode->pNext = NULL;
memcpy(pNewNode, &Teach, sizeof(Teacher));
//头插法
if (g_pHead == NULL)
{
g_pHead = pNewNode;
}
else
{
pNewNode->pNext = g_pHead;
g_pHead = pNewNode;
}
}
//关闭文件
fclose(fp);
printf("信息读取成功!\n");
system("pause");
system("cls");
break;
}
case 2:system("pause");
system("cls");
break;
}
}
9.教师信息保存.h
cpp
void SaveTeacher()
{
int c = 0;
system("cls");
printf("\t\t*************************************************\n");
printf("\t\t******** 欢迎来到教师信息保存系统 **********\n");
printf("\t\t*************************************************\n");
printf("\t\t******** 1.确定保存教师信息 **********\n");
printf("\t\t******** 2.放弃保存教师信息 **********\n");
printf("\t\t*************************************************\n");
printf("请输入您的选项:\n");
scanf("%d", &c);
getchar();
switch (c)
{
case 1:
{
//打开文件
FILE* fp = fopen("txt文本路径", "wb");//r只读,如果文件不存在,文件打开失败
if (fp == NULL)
{
printf("文件打开失败!\n");
exit(0);
}
//遍历链表
Node* p = g_pHead;
while (p != NULL)
{
fwrite(&p->teach, sizeof(Teacher), 1, fp);
p = p->pNext;
}
//关闭文件
fclose(fp);
printf("\n数据保存成功!\n");
system("pause");
system("cls");
break;
}
case 2:system("pause");
system("cls");
break;
}
}