第一次的博客,就献给这个管理系统吧
一个礼拜跌跌撞撞终于写出来了这个简单又美观的管理系统!!接下来会为大家分块介绍这个管理系统,相信大家也可以在短时间内写出让自己满意的管理系统,也希望这篇文章对大家有所帮助。
/*定义存放学生信息的结构体*/
typedef struct Information
{
char Name[20]; //姓名
char Class[8]; //班级号
char ID[9]; //学号
char Dor[9]; //宿舍号
char Bed[2]; //床位号
struct Information *next;
} Information;
Part2.1:定义文件:
/*定义文件*/
FILE* fp;
char *filename = "C:/Users/lenovo/Desktop/selfsystem.txt"; //文件路径需自定义哦!!!
Part2.2:读出文件信息:
/*读出文件信息*/
Information* Fscanf()
{
Information *head = (Information *)malloc(sizeof(Information));
head->next = NULL;
FILE *fp = fopen(filename, "rt"); //以读写方式打开文件
if (fp == NULL)
{
puts("Fail to open file!");
exit(1); //程序异常退出
}
if(fscanf(fp,"%s %s %s %s %s", head->Name, head->Class, head->ID, head->Dor, head->Bed)!=EOF)
{
while(fgetc(fp)!=EOF) //判断是否已经到文件尾部了
{
Information *cur= (Information *)malloc(sizeof(Information));
fscanf(fp,"%s %s %s %s %s", cur->Name, cur->Class, cur->ID, cur->Dor, cur->Bed);
cur->next = head;
head = cur;
} //利用头插法将文件读入链表中
}
else
return NULL;
fclose(fp);
return head->next;
}
Part2.3:将信息存入文件:
/*存入文件*/
void Fprintf(Information *head)
{
if ((fp = fopen(filename, "w")) == NULL) //以只写方式打开文件
{
printf("\n\nThe file cannot be opened!\n");
exit(1);
}
Information *cur = head;
while(cur)
{
fprintf(fp,"%s %s %s %s %s\n", cur->Name, cur->Class, cur->ID, cur->Dor, cur->Bed);
cur = cur->next;
}
fclose(fp);
}
Part3:隐藏光标、设置光标位置、设置字体颜色:
其实大家也可以跳过这一步,但是为了界面好看使用舒适嘛。。。。
大家可以把这些控制台的函数自己存好,以后可以就反复使用啦~
/*隐藏光标*/
void hidden(){
CONSOLE_CURSOR_INFO cursor_info = {
1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
/*设置光标位置*/
static void toxy(int x, int y)
{
COORD pos = {
x , y };
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
/*设置字体颜色*/
void color(short x)
{
if(x>=0 && x<=15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
}
------好啦,定义完这些,我们就要撸起袖子搞真正的主体啦!话不多说,我们进入主体。----
Part4:目录:
目录的目的是避免让后面调用的函数因顺序而出现不可调用问题,也可以方便阅读者阅读
Information *Addition(Information *head);
Information *Query(Information *head);
Information *Modify(Information *head);
Information *Delect(Information *head);
Information *Sort(Information *head);
void Print(Information *head);
void Over();
void Menu();
Part5:添加学生信息:
这里我运用的头插法 ^ _ ^
/*添加学生信息*/
Information* Addition(Information*head)
{
int n, count=0;
printf("\nPlease input the number of student:"); //请输入要添加的学生数量
scanf("%d", &n);
system("cls"); //清屏操作
while(n--)
{
Information *cur = (Information*)malloc(sizeof(Information));
printf("*-------------Please Input The Student's Information------------*");
printf("\n");
printf(" %d.", ++count);
printf("Full Name: ");
scanf("%s", cur->Name);
fflush(stdin); //每一次输入完后清空缓存区
printf("\n");
printf(" Class: ");
scanf("%s", cur->Class);
fflush(stdin);
printf("\n");
printf(" Student ID: ");
scanf("%s", cur->ID);
fflush(stdin);
printf("\n");
printf(" Dormitory Number: ");
scanf("%s", cur->Dor);
fflush(stdin);
printf("\n");
printf(" Bed Number: ");
scanf("%s", cur->Bed);
fflush(stdin);
system("cls"); //清屏
cur->next = head->next;
head->next = cur;
}
return head;
}
Part6:查询学生信息:
这里我使用了按姓名查询和按学号查询
首先全部遍历一遍链表,若没有找到信息则显示“No information was found for the student!”,若查询到则打印这条信息。
/*查询学生信息*/
Information* Query(Information*head)
{
system("cls");
hidden(); //隐藏光标
char choice;
toxy(50,5);
printf("*********************************\n");
toxy(48,8);
printf("**--------1.Search by name------**\n"); //通过名字查询
toxy(48,10);
printf("**--------2.Search by ID--------**\n"); //通过学号查询
toxy(48,12);
printf("**--------3.Exit menu-----------**\n"); //返回菜单
toxy(48,14);
printf("**********************************\n");
choice = getch();
fflush(stdin); //清空缓存区
system("cls");
switch(choice) //以两种方式查询
{
case '1':
{
printf("\nPlease enter the name of the student:"); //请输入学生姓名
char name[20];
gets(name);
fflush(stdin);
system("cls");
Information *cur = head->next;
while(cur&&strcmp(cur->Name,name)!=0) cur = cur->next; //一定要用字符串比较函数!
if(cur==NULL)
{
printf("\nNo information was found for the student!"); //未找到该学生信息
}
else //打印找出的信息
{
printf("\n\t\t --Student's Information-- \n\n");
printf("\t------------------------------------------------------------------------------------------\n");
printf("\t\tFull Name--------Class--------Student ID--------Dormitory Number--------Bed Number--------\n");
printf("\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n", cur->Name, cur->Class, cur->ID, cur->Dor, cur->Bed);
cur = cur->next;
}
printf("\n\t\tPress Any Key To Return."); //按任意键返回
getch();
break;
}
case '2':
{
printf("\nPlease enter the ID of the student:"); //请输入学生学号
char id[9];
gets(id);
fflush(stdin);
Information *pcur = head->next;
while(pcur&&strcmp(pcur->ID, id)!=0) pcur = pcur->next;
if(pcur==NULL) printf("No information was found for the student!"); //未找到该学生信息
else //打印找出的信息
{
printf("\n\t\t --Student's Information-- \n\n");
printf("\t------------------------------------------------------------------------------------------\n");
printf("\t\tFull Name--------Class--------Student ID--------Dormitory Number--------Bed Number--------\n");
printf("\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n", pcur->Name, pcur->Class, pcur->ID, pcur->Dor, pcur->Bed);
pcur = pcur->next;
}
printf("\t\tPress Any Key To Return."); //按任意键返回
getch();
break;
}
case '3':
{
Menu(); //返回主菜单
break;
}
default:
{
printf("Wrong Entry!"); //输入错误
break;
}
}
return head;
}
Part7:修改学生信息:
这一块我只按照姓名查找到信息来修改┭┮﹏┭┮觉得可以再多一些功能的朋友可以继续添加~
遍历的思想和查询一致,在修改完后打印修改后信息。
/*修改学生信息*/
Information* Modify(Information*head)
{
system("cls");
printf("\nPlease enter the name of the student:"); //请输入学生姓名
char name[20];
gets(name);
fflush(stdin);
Information *cur = head;
while(cur&&strcmp(cur->Name,name)!=0) cur = cur->next;
if(!cur)
{
printf("\nNo information was found for the student!"); //未找到该学生信息
printf("\n\n\t\tPress Any Key To Return."); //按任意键返回
getch();
}
else //输入修改后信息
{
system("cls");
printf("*-------------Please Input The Modified Information------------*");
printf("\n");
printf(" Full Name: ");
scanf("%s", cur->Name);
fflush(stdin);
printf("\n");
printf(" Class: ");
scanf("%s", cur->Class);
fflush(stdin);
printf("\n");
printf(" Student ID: ");
scanf("%s", cur->ID);
fflush(stdin);
printf("\n");
printf(" Dormitory Number: ");
scanf("%s", cur->Dor);
fflush(stdin);
printf("\n");
printf(" Bed Number: ");
scanf("%s", cur->Bed);
fflush(stdin);
printf("\n");
system("cls");
//修改完后打印这条信息
printf("\n\t\t --Student's Information-- \n\n");
printf("\t------------------------------------------------------------------------------------------\n");
printf("\t\tFull Name--------Class--------Student ID--------Dormitory Number--------Bed Number--------\n");
printf("\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n", cur->Name, cur->Class, cur->ID, cur->Dor, cur->Bed);
printf("\n\n\t\tPress Any Key To Return.");
getch();
}
system("cls");
return head;
}
Part8:删除学生信息:
同样的遍历链表,在删除成功后显示“Delect successfully!"
/*删除学生信息*/
Information* Delect(Information*head)
{
system("cls");
printf("\nPlease enter the name of the student:"); //输入要删除的学生姓名
char name[20];
gets(name);
Information *pre = head;
while(pre->next&&strcmp(pre->next->Name,name)!=0) pre = pre->next;
if(!pre->next)
{
printf("\nNo information was found for the student!");
printf("\n\n\t\tPress Any Key To Return.");
getch();
}
else
{
system("cls");
Information *cur = pre->next;
pre->next = pre->next->next;
free(cur);
printf("\n\t\tDelect successfully!"); //已删除成功
printf("\n");
printf("\n\t\tPress Any Key To Return.");
getch();
}
return head;
}
Part9:排序:
此处我设置了按姓名和按学号两种排序嘿嘿
运用的思想是字典排序。
/*字典排序*/
Information *Sort(Information *head)
{
system("cls");
hidden();
char choice;
toxy(50,5);
printf("*********************************\n");
toxy(48,8);
printf("**--------1.Sort by name-------**\n"); //按姓名排序
toxy(48,10);
printf("**--------2.Sort by ID---------**\n"); //按学号排序
toxy(48,12);
printf("**--------3.Exit menu----------**\n"); //退回菜单
toxy(48,14);
printf("*********************************\n");
choice = getch();
fflush(stdin);
system("cls");
switch(choice)
{
case '1':
{
Information *p, *q, *r;
r = NULL;
while (r!=head->next)
{
p = head;
q = p->next;
while (q->next != r)
{
if (strcmp(p->next->Name,q->next->Name)==1)
{
p->next = q->next;
q->next = q->next->next;
p->next->next = q;
}
p = p->next;
q = p->next;
}
r = q;
}
system("cls");
Print(head);
system("cls");
return head;
}
case '2':
{
Information *p, *q, *r;
r = NULL;
while (r!=head->next)
{
p = head;
q = p->next;
while (q->next != r)
{
if (strcmp(p->next->ID,q->next->ID)==1)
{
p->next = q->next;
q->next = q->next->next;
p->next->next = q;
}
p = p->next;
q = p->next;
}
r = q;
}
system("cls");
Print(head);
system("cls");
return head;
}
case '3':
{
Menu();
break;
}
default:
{
printf("Wrong Entry!");
break;
}
}
return head;
}
Part10:打印信息:
/*打印信息*/
void Print(Information*head)
{
system("cls");
Information *cur = head->next;
printf("\n\t\t --Student's Information-- \n\n");
printf("\t------------------------------------------------------------------------------------------\n");
printf("\t\tFull Name--------Class--------Student ID--------Dormitory Number--------Bed Number--------\n");
while(cur)
{
printf("\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n", cur->Name, cur->Class, cur->ID, cur->Dor, cur->Bed);
cur = cur->next;
}
printf("\n\t\tPress Any Key To Return.");
getch();
}
Part11:退出程序:
作为一个精致的老娘么儿,退出系统也要漂漂亮亮的!!
/*退出系统*/
void Over(Information *head)
{
char t;
toxy(48,11);
printf("-----------------------------------");
toxy(48,12);
printf("| Are You Sure You Want To Exit? |");
toxy(48,14);
printf("| 1.Yes 2.No |");
toxy(48,15);
printf("-----------------------------------");
while(1)
{
t=getch(); //输入t并且不回显
switch(t)
{
case '1':
{
Fprintf(head->next);
system("cls");
color(6);
toxy(48,10);
printf("Exiting....");
Sleep(1000); //暂停1秒
system("cls");
color(1);
toxy(48,10);
printf("Software exited");
toxy(48,12);
printf("Thank you for using!");
toxy(48,14);
printf("by-by^_^");
exit(0); break; //终止程序
}
case '2':
{
Menu(); //调用函数,进入菜单
break;
}
default :break;
}
}
}
Part12:主菜单:
主菜单也要精致美丽!
/*主菜单*/
void Menu()
{
Information *head= (Information*)malloc(sizeof(Information));
head->next=Fscanf();
do
{
system("cls");
hidden(); //隐藏光标
color(3); //设置一个喜欢的颜色
char t;
toxy(50,5); //将光标移动到(50,5)坐标处
printf("Welcome to dormitory management system");
toxy(48,8);
printf(" | 1.Information Addition |");
toxy(48,10);
printf(" | 2.Information Service |");
toxy(48,12);
printf(" | 3.Information Modification |");
toxy(48,14);
printf(" | 4.Information Deletion |");
toxy(48,16);
printf(" | 5.Sorting Of Information |");
toxy(48,18);
printf(" | 6.Information Printing |");
toxy(48,20);
printf(" | 7.Exit Software |");
t=getch(); //不回显函数
system("cls");
switch(t)
{
case '1':head=Addition(head);break;
case '2':head=Query(head);break;
case '3':head=Modify(head);break;
case '4':head=Delect(head);break;
case '5':head=Sort(head);break;
case '6':Print(head);break;
case '7':Over(head);break;
default :
printf("Wrong input,please input again");break;
}
} while (1);
}
Part13:主函数:
int main(void)
{
Information *createlist = (Information*)malloc(sizeof(Information));
Menu();
return 0;
}
#include
#include
#include
#include
#include
#include
#include
/*定义存放学生信息的结构体*/
typedef struct Information
{
char Name[20]; //姓名
char Class[8]; //班级号
char ID[9]; //学号
char Dor[9]; //宿舍号
char Bed[2]; //床位号
struct Information *next;
} Information;
/*定义文件*/
FILE* fp;
char *filename = "C:/Users/lenovo/Desktop/selfsystem.txt"; //文件路径需自定义哦!!!
/*读出文件信息*/
Information* Fscanf()
{
Information *head = (Information *)malloc(sizeof(Information));
head->next = NULL;
FILE *fp = fopen(filename, "rt");
if (fp == NULL)
{
puts("Fail to open file!");
exit(1); //程序异常退出
}
if(fscanf(fp,"%s %s %s %s %s", head->Name, head->Class, head->ID, head->Dor, head->Bed)!=EOF)
{
while(fgetc(fp)!=EOF) //判断是否已经到文件尾部了
{
Information *cur= (Information *)malloc(sizeof(Information));
fscanf(fp,"%s %s %s %s %s", cur->Name, cur->Class, cur->ID, cur->Dor, cur->Bed);
cur->next = head;
head = cur;
} //利用头插法将文件读入链表中
}
else
return NULL;
fclose(fp);
return head->next;
}
/*存入文件*/
void Fprintf(Information *head)
{
if ((fp = fopen(filename, "w")) == NULL)
{
printf("\n\nThe file cannot be opened!\n");
exit(1);
}
Information *cur = head;
while(cur)
{
fprintf(fp,"%s %s %s %s %s\n", cur->Name, cur->Class, cur->ID, cur->Dor, cur->Bed);
cur = cur->next;
}
fclose(fp);
}
/*目录*/
Information *Addition(Information *head);
Information *Query(Information *head);
Information *Modify(Information *head);
Information *Delect(Information *head);
Information *Sort(Information *head);
void Print(Information *head);
void Over();
void Menu();
/*隐藏光标*/
void hidden(){
CONSOLE_CURSOR_INFO cursor_info = {
1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
/*设置光标位置*/
static void toxy(int x, int y)
{
COORD pos = {
x , y };
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
/*设置字体颜色*/
void color(short x)
{
if(x>=0 && x<=15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
}
/*添加学生信息*/
Information* Addition(Information*head)
{
int n, count=0;
printf("\nPlease input the number of student:"); //请输入要添加的学生数量
scanf("%d", &n);
system("cls"); //清屏操作
while(n--)
{
Information *cur = (Information*)malloc(sizeof(Information));
printf("*-------------Please Input The Student's Information------------*");
printf("\n");
printf(" %d.", ++count);
printf("Full Name: ");
scanf("%s", cur->Name);
fflush(stdin); //每一次输入完后清空缓存区
printf("\n");
printf(" Class: ");
scanf("%s", cur->Class);
fflush(stdin);
printf("\n");
printf(" Student ID: ");
scanf("%s", cur->ID);
fflush(stdin);
printf("\n");
printf(" Dormitory Number: ");
scanf("%s", cur->Dor);
fflush(stdin);
printf("\n");
printf(" Bed Number: ");
scanf("%s", cur->Bed);
fflush(stdin);
system("cls"); //清屏
cur->next = head->next;
head->next = cur;
}
return head;
}
/*查询学生信息*/
Information* Query(Information*head)
{
system("cls");
hidden(); //隐藏光标
char choice;
toxy(50,5);
printf("*********************************\n");
toxy(48,8);
printf("**--------1.Search by name------**\n"); //通过名字查询
toxy(48,10);
printf("**--------2.Search by ID--------**\n"); //通过学号查询
toxy(48,12);
printf("**--------3.Exit menu-----------**\n"); //返回菜单
toxy(48,14);
printf("**********************************\n");
choice = getch();
fflush(stdin); //清空缓存区
system("cls");
switch(choice) //以两种方式查询
{
case '1':
{
printf("\nPlease enter the name of the student:"); //请输入学生姓名
char name[20];
gets(name);
fflush(stdin);
system("cls");
Information *cur = head->next;
while(cur&&strcmp(cur->Name,name)!=0) cur = cur->next;//一定要用字符串比较函数!
if(cur==NULL)
{
printf("\nNo information was found for the student!"); //未找到该学生信息
}
else //打印找出的信息
{
printf("\n\t\t --Student's Information-- \n\n");
printf("\t------------------------------------------------------------------------------------------\n");
printf("\t\tFull Name--------Class--------Student ID--------Dormitory Number--------Bed Number--------\n");
printf("\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n", cur->Name, cur->Class, cur->ID, cur->Dor, cur->Bed);
cur = cur->next;
}
printf("\n\t\tPress Any Key To Return."); //按任意键返回
getch();
break;
}
case '2':
{
printf("\nPlease enter the ID of the student:"); //请输入学生学号
char id[9];
gets(id);
fflush(stdin);
Information *pcur = head->next;
while(pcur&&strcmp(pcur->ID, id)!=0) pcur = pcur->next;
if(pcur==NULL) printf("No information was found for the student!"); //未找到该学生信息
else //打印找出的信息
{
printf("\n\t\t --Student's Information-- \n\n");
printf("\t------------------------------------------------------------------------------------------\n");
printf("\t\tFull Name--------Class--------Student ID--------Dormitory Number--------Bed Number--------\n");
printf("\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n", pcur->Name, pcur->Class, pcur->ID, pcur->Dor, pcur->Bed);
pcur = pcur->next;
}
printf("\t\tPress Any Key To Return."); //按任意键返回
getch();
break;
}
case '3':
{
Menu(); //返回主菜单
break;
}
default:
{
printf("Wrong Entry!"); //输入错误
break;
}
}
return head;
}
/*修改学生信息*/
Information* Modify(Information*head)
{
system("cls");
printf("\nPlease enter the name of the student:"); //请输入学生姓名
char name[20];
gets(name);
fflush(stdin);
Information *cur = head;
while(cur&&strcmp(cur->Name,name)!=0) cur = cur->next;
if(!cur)
{
printf("\nNo information was found for the student!"); //未找到该学生信息
printf("\n\n\t\tPress Any Key To Return."); //按任意键返回
getch();
}
else //输入修改后信息
{
system("cls");
printf("*-------------Please Input The Modified Information------------*");
printf("\n");
printf(" Full Name: ");
scanf("%s", cur->Name);
fflush(stdin);
printf("\n");
printf(" Class: ");
scanf("%s", cur->Class);
fflush(stdin);
printf("\n");
printf(" Student ID: ");
scanf("%s", cur->ID);
fflush(stdin);
printf("\n");
printf(" Dormitory Number: ");
scanf("%s", cur->Dor);
fflush(stdin);
printf("\n");
printf(" Bed Number: ");
scanf("%s", cur->Bed);
fflush(stdin);
printf("\n");
system("cls");
//修改完后打印这条信息
printf("\n\t\t --Student's Information-- \n\n");
printf("\t------------------------------------------------------------------------------------------\n");
printf("\t\tFull Name--------Class--------Student ID--------Dormitory Number--------Bed Number--------\n");
printf("\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n", cur->Name, cur->Class, cur->ID, cur->Dor, cur->Bed);
printf("\n\n\t\tPress Any Key To Return.");
getch();
}
system("cls");
return head;
}
/*删除学生信息*/
Information* Delect(Information*head)
{
system("cls");
printf("\nPlease enter the name of the student:"); //输入要删除的学生姓名
char name[20];
gets(name);
Information *pre = head;
while(pre->next&&strcmp(pre->next->Name,name)!=0) pre = pre->next;
if(!pre->next)
{
printf("\nNo information was found for the student!");
printf("\n\n\t\tPress Any Key To Return.");
getch();
}
else
{
system("cls");
Information *cur = pre->next;
pre->next = pre->next->next;
free(cur);
printf("\n\t\tDelect successfully!"); //已删除成功
printf("\n");
printf("\n\t\tPress Any Key To Return.");
getch();
}
return head;
}
/*打印信息*/
void Print(Information*head)
{
system("cls");
Information *cur = head->next;
printf("\n\t\t --Student's Information-- \n\n");
printf("\t------------------------------------------------------------------------------------------\n");
printf("\t\tFull Name--------Class--------Student ID--------Dormitory Number--------Bed Number--------\n");
while(cur)
{
printf("\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n", cur->Name, cur->Class, cur->ID, cur->Dor, cur->Bed);
cur = cur->next;
}
printf("\n\t\tPress Any Key To Return.");
getch();
}
/*字典排序*/
Information *Sort(Information *head)
{
system("cls");
hidden();
char choice;
toxy(50,5);
printf("*********************************\n");
toxy(48,8);
printf("**--------1.Sort by name-------**\n"); //按姓名排序
toxy(48,10);
printf("**--------2.Sort by ID---------**\n"); //按学号排序
toxy(48,12);
printf("**--------3.Exit menu----------**\n"); //退回菜单
toxy(48,14);
printf("*********************************\n");
choice = getch();
fflush(stdin);
system("cls");
switch(choice)
{
case '1':
{
Information *p, *q, *r;
r = NULL;
while (r!=head->next)
{
p = head;
q = p->next;
while (q->next != r)
{
if (strcmp(p->next->Name,q->next->Name)==1)
{
p->next = q->next;
q->next = q->next->next;
p->next->next = q;
}
p = p->next;
q = p->next;
}
r = q;
}
system("cls");
Print(head);
system("cls");
return head;
}
case '2':
{
Information *p, *q, *r;
r = NULL;
while (r!=head->next)
{
p = head;
q = p->next;
while (q->next != r)
{
if (strcmp(p->next->ID,q->next->ID)==1)
{
p->next = q->next;
q->next = q->next->next;
p->next->next = q;
}
p = p->next;
q = p->next;
}
r = q;
}
system("cls");
Print(head);
system("cls");
return head;
}
case '3':
{
Menu();
break;
}
default:
{
printf("Wrong Entry!");
break;
}
}
return head;
}
/*退出系统*/
void Over(Information *head)
{
char t;
toxy(48,11);
printf("-----------------------------------");
toxy(48,12);
printf("| Are You Sure You Want To Exit? |");
toxy(48,14);
printf("| 1.Yes 2.No |");
toxy(48,15);
printf("-----------------------------------");
while(1)
{
t=getch(); //输入t并且不回显
switch(t)
{
case '1':
{
Fprintf(head->next);
system("cls");
color(6);
toxy(48,10);
printf("Exiting....");
Sleep(1000); //暂停1秒
system("cls");
color(1);
toxy(48,10);
printf("Software exited");
toxy(48,12);
printf("Thank you for using!");
toxy(48,14);
printf("by-by^_^");
exit(0); break; //终止程序
}
case '2':
{
Menu(); //调用函数,进入菜单
break;
}
default :break;
}
}
}
/*主菜单*/
void Menu()
{
Information *head= (Information*)malloc(sizeof(Information));
head->next=Fscanf();
do
{
system("cls");
hidden(); //隐藏光标
color(3); //设置一个喜欢的颜色
char t;
toxy(50,5); //将光标移动到(50,5)坐标处
printf("Welcome to dormitory management system");
toxy(48,8);
printf(" | 1.Information Addition |");
toxy(48,10);
printf(" | 2.Information Service |");
toxy(48,12);
printf(" | 3.Information Modification |");
toxy(48,14);
printf(" | 4.Information Deletion |");
toxy(48,16);
printf(" | 5.Sorting Of Information |");
toxy(48,18);
printf(" | 6.Information Printing |");
toxy(48,20);
printf(" | 7.Exit Software |");
t=getch(); //不回显函数
system("cls");
switch(t)
{
case '1':head=Addition(head);break;
case '2':head=Query(head);break;
case '3':head=Modify(head);break;
case '4':head=Delect(head);break;
case '5':head=Sort(head);break;
case '6':Print(head);break;
case '7':Over(head);break;
default :
printf("Wrong input,please input again");break;
}
} while (1);
}
int main(void)
{
Information *createlist = (Information*)malloc(sizeof(Information));
Menu();
return 0;
}
查询界面:
修改信息成功后的打印:
退出:
删除成功:
未查询到信息:
信息打印: