最近做了课程设计,实验室设备管理系统.系统本身并不难做,可是需要考虑到美观性,准确性,因此,我在中间加了大量的判断,并且,用了菜单式的功能,让其变得更加美观,也加了一些动画效果.功能也是十分的完备.可以添加设备信息,删除设备信息,修改设备信息,查看设备信息,设置密码功能,保存设备信息功能,统计设备数量功能,为设备信息排序的功能,密码功能,保存信息,能有的基本都有了。可以说是我心目中比较完美的一种程序,尽管还不完美.
头文件:
#ifndef _STUDENT_H_
#define _STUDENT_H_
#include
#include
#include
#include
#include
#include
#include
#include
#pragma comment(lib,"winmm.lib")
//设备信息
struct shebei
{
char snumber[20];
char sname[20];
int sprice;
int year;
int month;
int day;
shebei *next;
};
//改变输出位置
void gotoxy(int x,int y)
{
COORD coord;
coord.X = y;
coord.Y = x;
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(handle,coord);
}
//改变文本颜色
void set_color(int x)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle,x);
}
//隐藏光标
void cursor_hidden(int x,int y)
{
CONSOLE_CURSOR_INFO info = {x,y};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&info);
}
#endif _STUDENT_H_.
源文件:
#include "head_file.h"
void start();//欢迎界面
shebei *password_input(shebei *head);//输入密码界面
void position_select(shebei *head);//功能选择界面
void position_tuichu(shebei *head);//退出系统功能
void position_add_out();//添加设备功能界面
shebei *position_add_add(shebei *head);//添加设备信息功能实现
void position_print(shebei *head);//输出设备信息
void position_keep(shebei *head);//保存设备信息
shebei *position_sort(shebei *head);//为设备信息排序功能
void position_find(shebei *head);//查询设备信息功能界面
void position_find_find(shebei *head,int select);//查询设备信息
void position_set_password();//设置密码功能
void position_count(shebei *head);//统计设备信息
void position_change(shebei *head);//设备信息更改功能菜单
shebei *position_change_change(shebei *head);//设备信息更改功能
void position_delete(shebei *head);//设备信息删除菜单
shebei* position_delete_delete(shebei *head,int select);
shebei *head = NULL;//链表头部
int main()
{
cursor_hidden(1,0);
start();
return 0;
}
//欢迎界面
void start()
{
int i = 18;
int s = 1;
int k;
int select = 14;
int n = 0,l = 1;
int n2 = 73;
int solo = 0;
if(access("music/title.wav",0)==0)
PlaySound("music/title.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
while(1)
{
k = 0;
system("cls");
set_color(i);
gotoxy(k++,15);printf("*******************************************\n");
gotoxy(k++,15);printf("| ## ## ##### ## ## ###### |\n");
gotoxy(k++,15);printf("| ## ## # ## ## # # |\n");
gotoxy(k++,15);printf("| ###### ##### ## ## # # |\n");
gotoxy(k++,15);printf("| ## ## # ## ## # # |\n");
gotoxy(k++,15);printf("| ## ## ##### ##### ##### ###### |\n");
gotoxy(k++,15);printf("*******************************************\n");
gotoxy(9,n);set_color(0xa);printf("welcome");
gotoxy(10,n2);printf("you");
gotoxy(14,33);printf("进入系统\n");
gotoxy(15,33);printf("退出系统\n");
gotoxy(18,30);printf("w - 上 s - 下\n");
gotoxy(19,30);printf("enter - 确定\n");
gotoxy(22,30);printf("制作:第六组\n");
set_color(13);gotoxy(select,30);printf("->");
solo++;
if(solo==5)
{
if(l==1)
{
n++;
n2--;
}
if(n==73)
{
l=0;
}
if(l==0)
{
n--;
n2++;
}
if(n==0)
{
l=1;
}
solo = 0;
}
if(GetKeyState('W')<0)
{
if(select==14)
select = 15;
else
select--;
getch();
Sleep(100);
}
if(GetKeyState('S')<0)
{
if(select==15)
select = 14;
else
select++;
getch();
Sleep(100);
}
s++;
if(s==50)
{
i++;
s = 1;
}
if(i==30)
i = 18;
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
switch(select)
{
case 14:
{
head = password_input(head);
position_select(head);
}
break;
case 15:
{
position_tuichu(head);
break;
}
}
Sleep(200);
}
}
}
//输入密码界面
shebei *password_input(shebei *head)
{
system("cls");
FILE *fp,*fp1;
shebei *p,*q;
auto char m[20],k[20];
if(access("dat/password1.dat",1)==0)
{
if((fp1=fopen("dat/password1.dat","rb"))==0)
{
cout<<"打开文件错误"<
}
if(ftell(fp1)!=0)
rewind(fp1);
fread(m,sizeof(m),1,fp1);
while(1)
{
gotoxy(10,22);printf("请输入密码\n");
gotoxy(11,22);
int i = 0;
while(1)
{
k[i]=getch();
if(k[i]=='\r')
break;
putchar('*');
i++;
}
k[i] = 0;
if(strcmp(m,k)==0)
break;
system("cls");
gotoxy(10,22);printf("输入密码错误\n");
Sleep(1000);
system("cls");
}
fclose(fp1);
Sleep(200);
}
if(access("dat/data1.txt",1)==0)
{
if((fp=fopen("dat/data1.txt","r"))==NULL)
{
cout<<"打开文件错误";
exit(0);
}
if(ftell(fp)!=0)
rewind(fp);
while(!feof(fp))
{
p = (shebei *)malloc(sizeof(shebei));
fscanf(fp,"%s %s %d %d %d %d\n",p->snumber,p->sname,&p->sprice,&p->year,&p->month,&p->day);
p -> next = NULL;
if(head==NULL)
{
head = p;
}
else
{
q = head;
while(q->next!=NULL)
q = q -> next;
q -> next= p;
}
}
fclose(fp);
}
return head;
}
//功能选择界面
void position_select(shebei *head)
{
int k;
int select = 7;
while(1)
{
k = 6;
system("cls");
system("color 0a");
gotoxy(k++,15);printf("************************************************\n");
gotoxy(k++,15);printf("* 1.添加设备信息 *\n");
gotoxy(k++,15);printf("* 2.更改设备信息 *\n");
gotoxy(k++,15);printf("* 3.删除设备信息 *\n");
gotoxy(k++,15);printf("* 4.查询设备信息 *\n");
gotoxy(k++,15);printf("* 5.显示设备信息 *\n");
gotoxy(k++,15);printf("* 6.统计设备信息 *\n");
gotoxy(k++,15);printf("* 7.为设备信息排序 *\n");
gotoxy(k++,15);printf("* 8.设置密码 *\n");
gotoxy(k++,15);printf("* 9.退出程序 *\n");
gotoxy(k++,15);printf("************************************************\n");
if(GetKeyState('W')<0)
{
if(select==7)
select = 15;
else
select--;
getch();
Sleep(100);
}
if(GetKeyState('S')<0)
{
if(select==15)
select = 7;
else
select++;
getch();
Sleep(100);
}
gotoxy(select,17);set_color(12);printf("->");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
switch(select)
{
case 7:
position_add_out();
break;
case 8:
{
position_change(head);
}
break;
case 9:
{
position_delete(head);
}
break;
case 10:
{
position_find(head);
}
break;
case 11:
{
position_print(head);
}
break;
case 12:
{
position_count(head);
}
break;
case 13:
{
head = position_sort(head);
}
break;
case 14:
{
position_set_password();
}
break;
case 15:
{
position_tuichu(head);
}
break;
}
}
}
}
//退出功能
void position_tuichu(shebei *head)
{
int result = MessageBox(NULL,"真的要离开吗"," ",MB_YESNO);
switch(result)
{
case IDYES:
{
shebei *p,*q;
p = head;
while(p!=NULL)
{
q = p;
p = p -> next;
free(q);
}
p = NULL;
q = NULL;
head = NULL;
exit(0);
}
break;
case IDNO:
{
if(access("music/title.wav",0)==0)
PlaySound("music/title.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
return ;
}
}
return ;
}
//添加设备信息
void position_add_out()
{
system("cls");
int select = 7;
while(1)
{
int k = 6;
system("cls");
set_color(7);
gotoxy(k++,15);printf("*****************************************\n");
gotoxy(k++,15);printf("* 1.添加信息 *\n");
gotoxy(k++,15);printf("* 2.保存信息 *\n");
gotoxy(k++,15);printf("* 3.查看信息 *\n");
gotoxy(k++,15);printf("* 4.返回上一级 *\n");
gotoxy(k++,15);printf("*****************************************\n");
if(GetKeyState('W')<0)
{
if(select==7)
select = 10;
else
select--;
getch();
Sleep(100);
}
if(GetKeyState('S')<0)
{
if(select==10)
select = 7;
else
select++;
getch();
Sleep(100);
}
gotoxy(select,17);set_color(12);printf("->");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
switch(select)
{
case 7:
head = position_add_add(head);
break;
case 8:
position_keep(head);
break;
case 9:
{
position_print(head);
}
break;
case 10:
return ;
}
}
}
}
//添加设备信息功能实现
shebei *position_add_add(shebei *head)
{
int stick = 1;
cursor_hidden(1,1);
shebei *p,*q,*h;
p = head;
set_color(0xd);
while(stick)
{
p = (shebei*)malloc(sizeof(shebei));
while(1)
{
while(1)
{
int i;
system("cls");
gotoxy(10,22);printf("请输入学生编号:");
gotoxy(11,22);scanf("%s",p->snumber);
for(i=0;(p->snumber[i])!=0;i++)
{
if(!((p->snumber[i])>='0'&&(p->snumber[i])<='9'))
{
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
break;
}
}
if(p->snumber[i]==0)
break;
}
h = head;
while(h!=NULL)
{
if(strcmp(h->snumber,p->snumber)==0)
break;
h = h -> next;
}
if(h==NULL)
break;
system("cls");gotoxy(10,22);printf("输入编号重复,请重新输入");Sleep(1000);system("cls");
}
system("cls");
gotoxy(10,22);printf("请输入设备名称:");
gotoxy(11,22);scanf("%s",p->sname);
while(1)
{
system("cls");
gotoxy(10,22);printf("请输入设备价格:");
gotoxy(11,22);if(scanf("%d",&p->sprice)==1&&(p->sprice)>0)
break;
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
}
int i = 0;
int s[2][12] = {{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
while(1)
{
system("cls");gotoxy(10,22);printf("请输入购买年份");
gotoxy(11,22);if(scanf("%d",&p->year)==1&&p->year>0)
break;
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
}
if((p->year)%4==0&&(p->year)%100!=0||p->year%400==0)
i = 1;
while(1)
{
system("cls");gotoxy(10,22);printf("请输入购买月份");
gotoxy(11,22);if(scanf("%d",&p->month)==1&&p->month>=1&&p->month<=12)
break;
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
}
while(1)
{
system("cls");gotoxy(10,22);printf("请输入购买日");
gotoxy(11,22);if(scanf("%d",&p->day)==1&&p->day>=1&&p->day<=s[i][p->month-1])
break;
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
}
p->next = NULL;
if(head==NULL)
{
head = p;
}
else
{
q = head;
while(q->next!=NULL)
q = q -> next;
q -> next= p;
}
Sleep(200);
system("cls");
while(1)
{
system("cls");
gotoxy(10,22);printf("是否要继续输入");
gotoxy(11,22);printf("1.是");
gotoxy(12,22);printf("0.否");
gotoxy(13,22);
if(scanf("%d",&stick)==1&&stick==0||stick==1)
break;
fflush(stdin);
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);
}
}
cursor_hidden(1,0);
Sleep(200);
return head;
}
//显示设备信息
void position_print(shebei *head)
{
system("cls");
shebei *p;
int select;system("color 1a");
while(1)
{
select = 0;
p = head;
gotoxy(select++,0);printf("************************************************************************\n");
gotoxy(select++,0);printf("学生编号 设备名称 价格 年—月—日\n");
while(p!=NULL)
{
gotoxy(select++,0);
printf("%-20s%-20s%-10d%-4d-%-2d-%-2d\n",p->snumber,p->sname,p->sprice,p->year,p->month,p->day);
p = p -> next;
}
gotoxy(select++,0);printf("************************************************************************\n");
gotoxy(select++,28);printf("按enter返回上一级\n");
if(GetKeyState(VK_RETURN)<0)
{
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
getch();
Sleep(200);
return ;
}
}
}
//保存设备信息
void position_keep(shebei *head)
{
FILE *fp1;
shebei *p;
fp1 = fopen("dat/data1.txt","w");
if(fp1==NULL)
{
cout<<"文件打开失败"<
}
p = head;
while(p!=NULL)
{
fprintf(fp1,"%s %s %d %d %d %d\n",p->snumber,p->sname,p->sprice,p->year,p->month,p->day);
p = p -> next;
}
fclose(fp1);
MessageBox(NULL,"数据已保存"," ",NULL);
return ;
}
//为设备排序功能菜单
shebei *position_sort(shebei *head)
{
system("cls");
int select = 7;
while(1)
{
int k = 6;
system("cls");
set_color(0x0d);
gotoxy(k++,15);printf("*****************************************\n");
gotoxy(k++,15);printf("* 1.按学生编号排序 *\n");
gotoxy(k++,15);printf("* 2.按设备名称排序 *\n");
gotoxy(k++,15);printf("* 3.按价格排序 *\n");
gotoxy(k++,15);printf("* 4.返回上一级 *\n");
gotoxy(k++,15);printf("*****************************************\n");
if(GetKeyState('W')<0)
{
if(select==7)
select = 10;
else
select--;
getch();
Sleep(100);
}
if(GetKeyState('S')<0)
{
if(select==10)
select = 7;
else
select++;
getch();
Sleep(100);
}
gotoxy(select,17);set_color(12);printf("->");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
switch(select)
{
case 7:
{
shebei *temp,*q,*p;
for(q=head;q->next!=NULL;q=q->next)
for(p=q->next;p->next!=NULL;p=p->next)
{
if(strcmp(p->next->snumber,q->next->snumber)<0)
{
if(q->next==p)
{
temp=p->next;
p->next=p->next->next;
temp->next=p;
q->next=temp;
p=temp;
}
else
{
temp=p->next;
p->next=q->next;
q->next=temp;
temp=p->next->next;
p->next->next=q->next->next;
q->next->next=temp;
}
}
}
}
MessageBox(NULL,"排序已完成"," ",NULL);
break;
case 8:
{
shebei *temp,*q,*p;
for(q=head;q->next!=NULL;q=q->next)
for(p=q->next;p->next!=NULL;p=p->next)
{
if(strcmp(p->next->sname,q->next->sname)<0)
{
if(q->next==p)
{
temp=p->next;
p->next=p->next->next;
temp->next=p;
q->next=temp;
p=temp;
}
else
{
temp=p->next;
p->next=q->next;
q->next=temp;
temp=p->next->next;
p->next->next=q->next->next;
q->next->next=temp;
}
}
}
}
MessageBox(NULL,"排序已完成","",NULL);
break;
case 9:
{
shebei *temp,*q,*p;
for(q=head;q->next!=NULL;q=q->next)
for(p=q->next;p->next!=NULL;p=p->next)
{
if(p->next->sprice
{
if(q->next==p)
{
temp=p->next;
p->next=p->next->next;
temp->next=p;
q->next=temp;
p=temp;
}
else
{
temp=p->next;
p->next=q->next;
q->next=temp;
temp=p->next->next;
p->next->next=q->next->next;
q->next->next=temp;
}
}
}
}
MessageBox(NULL,"排序已完成","",NULL);
break;
case 10:
return head;
}
}
}
}
//查询设备信息功能菜单
void position_find(shebei *head)
{
system("cls");
int select = 7;
while(1)
{
int k = 6;
system("cls");set_color(11);
gotoxy(k++,15);printf("*****************************************\n");
gotoxy(k++,15);printf("* 1.按学生编号查找 *\n");
gotoxy(k++,15);printf("* 2.按设备名称查找 *\n");
gotoxy(k++,15);printf("* 3.按价格查找 *\n");
gotoxy(k++,15);printf("* 4.按年份查找 *\n");
gotoxy(k++,15);printf("* 5.返回上一级 *\n");
gotoxy(k++,15);printf("*****************************************\n");
if(GetKeyState('W')<0)
{
if(select==7)
select = 11;
else
select--;
getch();
Sleep(100);
}
if(GetKeyState('S')<0)
{
if(select==11)
select = 7;
else
select++;
getch();
Sleep(100);
}
gotoxy(select,17);set_color(12);printf("->");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
switch(select)
{
case 7:
case 8:
case 9:
case 10:
position_find_find(head,select);
break;
case 11:
return ;
}
}
}
}
//查询设备信息
void position_find_find(shebei *head,int select)
{
shebei *p;
int select2;
p = head;
switch(select)
{
case 7:
{
auto char number[20];
system("cls");
set_color(7);
cursor_hidden(1,1);
while(1)
{
int i;
system("cls");
gotoxy(10,22);printf("请输入学生编号:");
gotoxy(11,22);scanf("%s",number);
for(i=0;(number[i])!=0;i++)
{
if(!(number[i]>='0'&&number[i]<='9'))
{
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
break;
}
}
if(number[i]==0)
break;
}
cursor_hidden(1,0);
Sleep(200);
while(p!=NULL)
{
if(strcmp(number,p->snumber)==0)
{
system("cls");
while(1)
{
select2 = 0;
gotoxy(select2++,0);printf("************************************************************************\n");
gotoxy(select2++,0);printf("学生编号 设备名称 价格 年—月—日\n");
gotoxy(select2++,0);printf("%-20s%-20s%-10d%-4d-%-2d-%-2d\n",p->snumber,p->sname,p->sprice,p->year,p->month,p->day);
gotoxy(select2++,0);printf("************************************************************************\n");
gotoxy(select2++,28);printf("按enter返回上一级\n");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
Sleep(200);
return ;
}
}
}
p = p -> next;
}
MessageBox(NULL,"没有找到","",NULL);
return ;
}
case 8:
{
auto char name[20];
system("cls");
set_color(0xb);
gotoxy(8,20);cout<<"请输入要查找的设备名称"<
gotoxy(9,20);scanf("%s",name);
cursor_hidden(1,0);
Sleep(200);
system("cls");
while(1)
{
p = head;
select2 = 0;
gotoxy(select2++,0);printf("************************************************************************\n");
gotoxy(select2++,0);printf("学生编号 设备名称 价格 年—月—日\n");
while(p!=NULL)
{
if(strcmp(name,p->sname)==0)
{
gotoxy(select2++,0);printf("%-20s%-20s%-10d%-4d-%-2d-%-2d\n",p->snumber,p->sname,p->sprice,p->year,p->month,p->day);
}
p = p -> next;
}
gotoxy(select2++,0);printf("************************************************************************\n");
gotoxy(select2++,28);printf("按enter返回上一级\n");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
Sleep(200);
return ;
}
}
}
case 9:
{
int price;
system("cls");
set_color(0xb);
cursor_hidden(1,1);
while(1)
{
system("cls");gotoxy(10,22);cout<<"请输入要查询的价格"<
break;
fflush(stdin);
system("cls");gotoxy(10,22);cout<<"输入数据错误,请重新输入";Sleep(1000);system("cls");
}
cursor_hidden(1,0);
Sleep(200);
system("cls");
while(1)
{
p = head;
select2 = 0;
gotoxy(select2++,0);printf("************************************************************************\n");
gotoxy(select2++,0);printf("学生编号 设备名称 价格 年—月—日\n");
while(p!=NULL)
{
if(price==p->sprice)
{
gotoxy(select2++,0);printf("%-20s%-20s%-10d%-4d-%-2d-%-2d\n",p->snumber,p->sname,p->sprice,p->year,p->month,p->day);
}
p = p -> next;
}
gotoxy(select2++,0);printf("************************************************************************\n");
gotoxy(select2++,28);printf("按enter返回上一级\n");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
Sleep(200);
return ;
}
}
}
case 10:
{
int year;
set_color(8);
cursor_hidden(1,1);
while(1)
{
system("cls");gotoxy(10,22);cout<<"请输入要查询的年份"<
break;
fflush(stdin);
system("cls");gotoxy(10,22);cout<<"输入数据错误,请重新输入";Sleep(1000);system("cls");
}
cursor_hidden(1,0);
Sleep(200);
system("cls");
while(1)
{
p = head;
select2 = 0;
gotoxy(select2++,0);printf("************************************************************************\n");
gotoxy(select2++,0);printf("学生编号 设备名称 价格 年—月—日\n");
while(p!=NULL)
{
if(year==p->year)
{
gotoxy(select2++,0);printf("%-20s%-20s%-10d%-4d-%-2d-%-2d\n",p->snumber,p->sname,p->sprice,p->year,p->month,p->day);
}
p = p -> next;
}
gotoxy(select2++,0);printf("************************************************************************\n");
gotoxy(select2++,28);printf("按enter返回上一级\n");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
Sleep(200);
return ;
}
}
}
}
}
//设置密码功能
void position_set_password()
{
system("cls");
auto char s[20];
FILE *fp1;
set_color(15);
gotoxy(10,22);printf("请输入一个新的密码:\n");
gotoxy(11,22);scanf("%s",s);
fp1 = fopen("dat/password1.dat","w");
if(fp1==NULL)
{
cout<<"文件未被打开"<
}
fwrite(&s,sizeof(s),1,fp1);
fclose(fp1);
Sleep(200);
return ;
}
//设备信息统计
void position_count(shebei *head)
{
set_color(0xb);
int select2;
shebei *p;
p = head;
int count = 0;
int i;
int s;
while(p!=NULL)
{
p = p -> next;
count++;
}
p = head;
char *h;
int *q;
h = (char *)calloc(count,20*sizeof(char *));
q = (int *)calloc(count,sizeof(int));
s = 0;
while(p!=NULL)
{
if(s==0)
{
strcpy(h,p->sname);
s++;
(*q)++;
}
else
{
for(i=0;i {
if(strcmp(h+i*20*sizeof(char),p->sname)==0)
{
(*(q+i))++;
break;
}
}
if(i==s)
{
strcpy(h+i*20*sizeof(char),p->sname);
(*(q+s))++;
s++;
}
}
p = p -> next;
}
while(1)
{
system("cls");
select2 = 0;
gotoxy(select2++,20);printf("********************************\n");
gotoxy(select2++,20);printf("|设备名称 设备数量 |\n");
for(i=0;i {
gotoxy(select2++,20);printf("|%-20s%-10d|\n",h+i*20*sizeof(char),*(q+i));
}
gotoxy(select2++,20);printf("********************************\n");
gotoxy(select2++,28);printf("按enter返回上一级\n");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
Sleep(200);
return ;
}
}
}
//更改设备信息功能
void position_change(shebei *head)
{
system("cls");
int select = 7;
while(1)
{
int k = 6;
system("cls");
set_color(15);
gotoxy(k++,15);printf("*****************************************\n");
gotoxy(k++,15);printf("* 1.按学生编号更改 *\n");
gotoxy(k++,15);printf("* 2.查看所有信息 *\n");
gotoxy(k++,15);printf("* 3.保存所有信息 *\n");
gotoxy(k++,15);printf("* 4.返回上一级 *\n");
gotoxy(k++,15);printf("*****************************************\n");
if(GetKeyState('W')<0)
{
if(select==7)
select = 10;
else
select--;
getch();
Sleep(100);
}
if(GetKeyState('S')<0)
{
if(select==10)
select = 7;
else
select++;
getch();
Sleep(100);
}
gotoxy(select,17);set_color(12);printf("->");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
switch(select)
{
case 7:
head = position_change_change(head);
break;
case 8:
position_print(head);
break;
case 9:
position_keep(head);
break;
case 10:
return ;
}
}
}
}
//更改设备信息
shebei *position_change_change(shebei *head)
{
auto char number[20];
shebei *p;
int k;
int select = 7;
int select2;
system("cls");cursor_hidden(1,1);
set_color(0xa);
while(1)
{
int i;
system("cls");
gotoxy(10,22);printf("请输入学生编号:");
gotoxy(11,22);scanf("%s",number);
for(i=0;(number[i])!=0;i++)
{
if(!((number[i])>='0'&&(number[i])<='9'))
{
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
break;
}
}
if(number[i]==0)
break;
}
cursor_hidden(1,0);
Sleep(200);
p = head;
while(p!=NULL&&strcmp(p->snumber,number)!=0)
{
p = p -> next;
}
if(p==NULL)
{
MessageBox(NULL,"没有找到信息"," ",NULL);
return head;
}
else
{
while(1)
{
system("cls");k = 6;
set_color(15);
gotoxy(k++,15);printf("*****************************************\n");
gotoxy(k++,15);printf("* 1.查看信息 *\n");
gotoxy(k++,15);printf("* 2.修改设备名称 *\n");
gotoxy(k++,15);printf("* 3.修改设备价格 *\n");
gotoxy(k++,15);printf("* 4.修改设备生产日期 *\n");
gotoxy(k++,15);printf("* 5.返回上一级 *\n");
gotoxy(k++,15);printf("*****************************************\n");
if(GetKeyState('W')<0)
{
if(select==7)
select = 11;
else
select--;
getch();
Sleep(100);
}
if(GetKeyState('S')<0)
{
if(select==11)
select = 7;
else
select++;
getch();
Sleep(100);
}
gotoxy(select,17);set_color(12);printf("->");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
switch(select)
{
case 7:
{
while(1)
{
system("color f");
select2 = 0;system("cls");
gotoxy(select2++,20);printf("*******************************\n");
gotoxy(select2++,20);printf("*学生编号%20s *\n",p->snumber);
gotoxy(select2++,20);printf("*设备名称%20s *\n",p->sname);
gotoxy(select2++,20);printf("*设备价格%20d *\n",p->sprice);
gotoxy(select2++,20);printf("*年 %20d *\n",p->year);
gotoxy(select2++,20);printf("*月 %20d *\n",p->month);
gotoxy(select2++,20);printf("*日 %20d *\n",p->day);
gotoxy(select2++,20);printf("*******************************\n");
gotoxy(select2++,28);printf("按enter返回上一级\n");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
Sleep(200);
break;
}
}
break;
}
case 8:
{
cursor_hidden(1,1);
system("cls");
gotoxy(10,22);printf("请输入设备名称:\n");
gotoxy(11,22);scanf("%s",p->sname);
cursor_hidden(1,0);
Sleep(200);
}
break;
case 9:
{
cursor_hidden(1,1);
while(1)
{
system("cls");
gotoxy(10,22);printf("请输入设备价格:\n");
gotoxy(11,22);if(scanf("%d",&p->sprice)==1&&(p->sprice)>0)
break;
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
}
Sleep(200);
cursor_hidden(1,0);
}
break;
case 10:
{
cursor_hidden(1,1);
int i = 0;
int s[2][12] = {{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
while(1)
{
system("cls");gotoxy(10,22);printf("请输入购买年份\n");
gotoxy(11,22);if(scanf("%d",&p->year)==1&&p->year>0)
break;
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
}
if((p->year)%4==0&&(p->year)%100!=0||p->year%400==0)
i = 1;
while(1)
{
system("cls");gotoxy(10,22);printf("请输入购买月份\n");
gotoxy(11,22);if(scanf("%d",&p->month)==1&&p->month>=1&&p->month<=12)
break;
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
}
while(1)
{
system("cls");gotoxy(10,22);printf("请输入购买日");
gotoxy(11,22);if(scanf("%d",&p->day)==1&&p->day>=1&&p->day<=s[i][p->month-1])
break;
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
}
cursor_hidden(1,0);
Sleep(200);
}
break;
case 11:
return head;
}
}
}
}
}
//设备信息删除功能菜单
void position_delete(shebei *head)
{
system("cls");
int select = 7;
while(1)
{
int k = 6;
system("cls");
set_color(0x0d);
gotoxy(k++,15);printf("*****************************************\n");
gotoxy(k++,15);printf("* 1.按学生编号删除 *\n");
gotoxy(k++,15);printf("* 2.查看信息 *\n");
gotoxy(k++,15);printf("* 3.保存所有信息 *\n");
gotoxy(k++,15);printf("* 4.返回上一级 *\n");
gotoxy(k++,15);printf("*****************************************\n");
if(GetKeyState('W')<0)
{
if(select==7)
select = 10;
else
select--;
getch();
Sleep(100);
}
if(GetKeyState('S')<0)
{
if(select==10)
select = 7;
else
select++;
getch();
Sleep(100);
}
gotoxy(select,17);set_color(12);printf("->");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
switch(select)
{
case 7:
head = position_delete_delete(head,select);
break;
case 8:
position_print(head);
break;
case 9:
position_keep(head);
break;
case 10:
return ;
}
Sleep(200);
}
}
}
//设备信息删除功能
shebei *position_delete_delete(shebei *head,int select)
{
shebei *p,*q;
char snumber[20],name[20];
int select2;
set_color(0x0d);
if(head==NULL)
{
MessageBox(NULL,"无信息可以删除","",NULL);
return head;
}
else
{
while(1)
{
int i;
system("cls");
gotoxy(10,22);printf("请输入学生编号:\n");
gotoxy(11,22);scanf("%s",snumber);
for(i=0;(snumber[i])!=0;i++)
{
if(!((snumber[i])>='0'&&(snumber[i])<='9'))
{
system("cls");gotoxy(10,22);printf("输入数据错误,请重新输入");Sleep(1000);system("cls");
fflush(stdin);
break;
}
}
if(snumber[i]==0)
break;
}
Sleep(200);
p = head;
while(p!=NULL&&strcmp(p->snumber,snumber)!=0)
{
q = p;
p = p -> next;
}
if(p!=NULL)
{
while(1)
{
select2 = 0;system("cls");
gotoxy(select2++,20);printf("该名学生的信息是:");
gotoxy(select2++,20);printf("*******************************\n");
gotoxy(select2++,20);printf("*学生编号%20s *\n",p->snumber);
gotoxy(select2++,20);printf("*设备名称%20s *\n",p->sname);
gotoxy(select2++,20);printf("*设备价格%20d *\n",p->sprice);
gotoxy(select2++,20);printf("*年 %20d *\n",p->year);
gotoxy(select2++,20);printf("*月 %20d *\n",p->month);
gotoxy(select2++,20);printf("*日 %20d *\n",p->day);
gotoxy(select2++,20);printf("*******************************\n");
gotoxy(select2++,28);printf("按enter删除信息\n");
gotoxy(select2++,28);printf("按o键取消");
if(GetKeyState(VK_RETURN)<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
if(p==head)
head = p -> next;
else
q -> next = p -> next;
free(p);
Sleep(200);
return head;
}
else if(GetKeyState('O')<0)
{
getch();
if(access("music/enter.wav",0)==0)
PlaySound("music/enter.wav",NULL,NULL);
Sleep(200);
return head;
}
}
}
else
{
MessageBox(NULL,"未找到该生信息"," ",NULL);
return head;
}
}
}