運(yùn)行界面:
部分程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define N 10
//客戶信息結(jié)構(gòu)體
typedef struct{
char userName[9];??? //客戶姓名
char idNum[19];????? //身份證號(hào)
int inTime;????????? //入住時(shí)間
int outTime;???????? //離開(kāi)時(shí)間
int roomNo;????????? //房間號(hào)????? 1到10
}userInformation;
userInformation user[N];
//userInformation user1[N];
int roomState[10] = {0};??? //房間狀態(tài)
int nowRoom = 0;??????? //已住房間數(shù)
scannerRead()????? //鍵盤(pán)輸入函數(shù),從鍵盤(pán)錄入信息至結(jié)構(gòu)體
{
int i=0,flag=1;
while(flag)
{
//通過(guò)循環(huán)找到空信息行的位置,在進(jìn)行添加
if(strlen(user[i].idNum) == 0)
{
printf("請(qǐng)輸入客戶姓名、身份證號(hào)(空格隔開(kāi)):");
scanf("%s %s",user[i].userName,user[i].idNum);
printf("請(qǐng)輸入入住時(shí)間、離開(kāi)時(shí)間、房間號(hào)(空格隔開(kāi)):");
scanf("%d %d %d",&user[i].inTime,&user[i].outTime,&user[i].roomNo);
printf("%st%st",user[i].userName,user[i].idNum);
printf("%dt%dt%d",user[i].inTime,user[i].outTime,user[i].roomNo);
flag=0;
nowRoom++;
}
roomState[user[i].roomNo-1] = 1;
i++;
}
//Sleep(1000);
//system("cls");
}
txtLoad()??????????????? //文件輸入函數(shù)、從文件中導(dǎo)入信息至結(jié)構(gòu)體
{
int n = 0;
int i = 0,j = 0;
char PATHNAME[20];
FILE *fr = fopen("file1.txt","rt");
if(fr == NULL) {
printf("打開(kāi)文件出錯(cuò)。n");
return 1;
}
//通過(guò)
close(ret);
}
int i,m;
printf("輸入查詢條件:房號(hào)n");
scanf("%d",&fangNUM);
//循環(huán)找出所需刪除的位置后,重新排序
for(i=0;i<N;i++)
{
if(fangNUM==user[i].roomNo)
{
printf("需要?jiǎng)h除的入住信息如下:n");
printf("姓名:%s,身份證號(hào):%sn入住時(shí)間%d,退房時(shí)間:%d,房號(hào):%dn",user[i].userName,user[i].idNum,user[i].inTime,user[i].outTime,user[i].roomNo);
memset(user[i].userName,0,1);
memset(user[i].idNum,0,1);
memset(&user[i].inTime,0,4);
memset(&user[i].outTime,0,4);
memset(&user[i].roomNo,0,4);
m=i;
break;
}
}
for(i=0;i<N-m;i++)
{
strcpy(user[m+i].userName,user[m+i+1].userName);
strcpy(user[m+i].idNum,user[m+i+1].idNum);
user[m+i].inTime=user[m+i+1].inTime;
user[m+i].outTime=user[m+i+1].outTime;
user[m+i].roomNo=user[m+i+1].roomNo;
}
for(i=0;i<N;i++)
{
printf("%st%st%dt%dt%dn",user[i].userName,user[i].idNum,user[i].inTime,user[i].outTime,user[i].roomNo);
}
memset(user[9].userName,0,1);
memset(user[9].idNum,0,1);
memset(&user[9].inTime,0,4);
memset(&user[9].outTime,0,4);
memset(&user[9].roomNo,0,4);
}
show(){
printf(" *************************************************************************n");
printf(" ************************歡迎使用客房登記系統(tǒng)*****************************n");
printf("| t???????????????? 1.--客戶信息輸入??????????????????????????????? |n");
printf("| t???????????????? 2.--客戶及房間信息查詢????????????????????????? |n");
printf("| t????????????? ???3.--客戶信息修改??????????????????????????????? |n");
printf("| t???????????????? 4.--客戶信息刪除??????????????????????????????? |n");
printf("| t???????????????? 5.--客戶信息保存??????????????????????????????? |n");
printf("| t???????????????? 6.--退出系統(tǒng)??????? ????????????????????????????|n");
printf("|************************************************************************|n");
printf("|************************************************************************|nn");
}
show_1(){
printf(" *************************************************************************n");
printf(" ************************歡迎使用客房登記系統(tǒng)*****************************n");
printf("| t???????????????? 1.--文件輸入信息??????????????????????????????? |n");
printf("| t???????????????? 2.--鍵盤(pán)輸入信息??????????????????????????????? |n");
printf("|************************************************************************|n");
printf("|************************************************************************|nn");
}
show_2(){
printf(" *************************************************************************n");
printf(" ************************歡迎使用客房登記系統(tǒng)*****************************n");
printf("| t???????????????? 1.--房間號(hào)查詢住宿信息????????????????????????? |n");
printf("| t???????????????? 2.--身份證號(hào)查詢住宿信息??????????????????????? |n");
printf("| t???????????????? 3.--根據(jù)日期能夠查詢到空房間信息??????????????? |n");
printf("|************************************************************************|n");
printf("|************************************************************************|nn");
}
show_4(){
printf(" *************************************************************************n");
printf(" ************************歡迎使用客房登記系統(tǒng)*****************************n");
printf("| t???????????????? 1.--根據(jù)身份證號(hào)刪除入住信息??????????????????? |n");
printf("| t???????????????? 2.--根據(jù)房間號(hào)刪除入住信息?????????????????????? |n");
printf("|************************************************************************|n");
printf("|************************************************************************|nn");
}
main()
{
int k = 1;
int n = 0;
int m = 0;
while(k)
{
scanf("%d",&m);
switch(m)
{
case 1:outRoom1();
break;
case 2:outRoom2();
break;
}
break;
case 5:
save();
//loadm();
break;
case 6:
k = 0;
break;
default:
printf("輸入有誤,重新輸入n");
break;
}
}
}