📄 宾馆客户登记系统.cpp
字号:
#include <fstream>
#include<iostream>
#include<iomanip>
#include<cmath>
#include <stdlib.h>
#include <string.h>
using namespace std;
struct Date
{
int year;
int month;
int day;
};
struct SLink
{
int Pnum;
int Pid;
char name[20];
char sex;
Date petime;
char Ptype[50];
double Fmon;
char Rinf[50];
Date batime;
bool baroom;
double pay;
SLink *next;
};
SLink * Add(SLink*head);
SLink * Updata(SLink*head);
SLink*Delete(SLink*head);
SLink*Query(SLink*head);
void Print(SLink*head);
int main()
{
SLink*p,*head;
head=new SLink;
ofstream table;
ifstream table1;
cout<<"********************************************************************************"<<endl;
cout<<" "<<" ";
cout<<"宾馆客房信息"<<endl;
cout<<endl;
cout<<" "<<" ";
cout<<"在下面一个列表中选择一个选项"<<endl;
cout<<endl;
while(1)
{
cout<<"(1)添加客房信息 *"<<endl;
cout<<"(2)修改客房信息"<<endl;
cout<<"(3)删除客房信息"<<endl;
cout<<"(4)查询客房信息"<<endl;
cout<<"(5)退出"<<endl;
cout<<"********************************************************************************"<<endl;
cout<<"选择<1-5>"<<endl;
int k;
cin>>k;
switch(k)
{
case 1:
{
table1.open("personinformation111.txt");
if(!table1)
{
cout<<"Cannot open input file!\n";
}
SLink *pp;
head=NULL;
while(!table1.eof()) {
if(pp = new SLink()) {
table1>> pp->Pnum>>pp->name>>pp->sex>>pp->Pid>>pp->petime.year>>pp->petime.month>>pp->petime.day>>pp->Fmon
>>pp->Ptype;
pp->next = head;
head = pp;
}
}
table1.close();
table.open("personinformation111.txt");
head=Add(head);
for(pp=head->next;pp;pp=pp->next)
{
table<<setw(3)<<pp->Pnum<<" ";
table<<setw(14)<<pp->name<<" ";
table<<setw(5)<<pp->sex<<" "<<" ";
table<<setw(12)<<pp->Pid<<" ";
table<<setw(3)<<pp->petime.year<<" ";
table<<pp->petime.month<<" ";
table<<pp->petime.day<<" ";
table<<setw(5)<<pp->Fmon<<" ";
table<<setw(15)<<pp->Ptype<<" ";
table<<endl;
}
table.close();
break;
}
case 2:
{
table1.open("personinformation111.txt");
if(!table1)
{
cout<<"Cannot open input file!\n";
}
SLink *pp;
head=NULL;
while(!table1.eof()) {
if(pp = new SLink()) {
table1>> pp->Pnum>>pp->name>>pp->sex>>pp->Pid>>pp->petime.year>>pp->petime.month>>pp->petime.day>>pp->Fmon
>>pp->Ptype;
pp->next = head;
head = pp;
}
}
table1.close();
SLink *ppp;pp=Updata(head);
if(pp)
{
cout<<"请输入客户的房号"<<endl;
cin>>pp->Pnum;
cout<<"请输入客户姓名"<<endl;
cin>>pp->name;
cout<<"请输入客户性别"<<endl;
cin>>pp->sex;
cout<<"请输入客户身份证号"<<endl;
cin>>pp->Pid;
cout<<"请输入入住时间"<<endl;
cin>>pp->petime.year>>pp->petime.month>>pp->petime.day;
cout<<"请输入预交金"<<endl;
cin>>pp->Fmon;
cout<<"请输入住房类型"<<endl;
cin>>pp->Ptype;
}
else{cout<<"此房号不存在"<<endl;break;}
// cout<<pp->Pnum<<endl;
for(ppp=head;ppp;ppp=ppp->next)
{
if(ppp->Pnum==pp->Pnum)
{
ppp->Pid=pp->Pid;
//ppp->name=pp->name;
strcpy(ppp->name,pp->name);
ppp->sex=pp->sex;
ppp->Pid=pp->Pid;
ppp->petime.year=pp->petime.year;
ppp->petime.month=pp->petime.month;
ppp->petime.day=pp->petime.day;
ppp->Fmon=ppp->Fmon;
strcpy(ppp->Ptype,pp->Ptype);
break;
}
}
table.open("personinformation111.txt");
SLink *yf;
for(yf=head->next;yf;yf=yf->next)
{
table<<setw(3)<<yf->Pnum<<" ";
table<<setw(14)<<yf->name<<" ";
table<<setw(5)<<yf->sex<<" "<<" ";
table<<setw(12)<<yf->Pid<<" ";
table<<setw(3)<<yf->petime.year<<" ";
table<<yf->petime.month<<" ";
table<<yf->petime.day<<" ";
table<<setw(5)<<yf->Fmon<<" ";
table<<setw(15)<<yf->Ptype<<" ";
table<<endl;
}
table.close();
break;
}
case 3:{
table1.open("personinformation111.txt");
if(!table1)
{
cout<<"Cannot open input file!\n";
}
SLink *pp;
head=NULL;
while(!table1.eof()) {
if(pp = new SLink()) {
table1>> pp->Pnum>>pp->name>>pp->sex>>pp->Pid>>pp->petime.year>>pp->petime.month>>pp->petime.day>>pp->Fmon
>>pp->Ptype;
pp->next = head;
head = pp;
}
}
table1.close();
SLink *ppp;pp=Delete(head);
if(pp)
{
for(ppp=head;ppp->next;ppp=ppp->next)
{ if(head&&head->Pnum==pp->Pnum)
head=head->next;
else if(ppp->next->Pnum==pp->Pnum)
{
ppp->next=pp->next; break;
}
}
}
cout<<"此房间已经成为空房"<<endl;
table.open("personinformation111.txt");
SLink *yf;
for(yf=head->next;yf;yf=yf->next)
{
table<<setw(3)<<yf->Pnum<<" ";
table<<setw(14)<<yf->name<<" ";
table<<setw(5)<<yf->sex<<" "<<" ";
table<<setw(12)<<yf->Pid<<" ";
table<<setw(3)<<yf->petime.year<<" ";
table<<yf->petime.month<<" ";
table<<yf->petime.day<<" ";
table<<setw(5)<<yf->Fmon<<" ";
table<<setw(15)<<yf->Ptype<<" ";
table<<endl;
}
table.close();
break;
}
case 4:{
table1.open("personinformation111.txt");
if(!table1)
{
cout<<"Cannot open input file!\n";
}
SLink *pp;
head=NULL;
while(!table1.eof()) {
if(pp = new SLink()) {
table1>> pp->Pnum>>pp->name>>pp->sex>>pp->Pid>>pp->petime.year>>pp->petime.month>>pp->petime.day>>pp->Fmon
>>pp->Ptype;
pp->next = head;
head = pp;
}
}
table1.close();
head=Query(head); break;}
case 5:exit(0);
default: {cout<<"输入信息错误!\n请输入上面序号数字\n"<<endl;break; }
}
}
return 0;
}
SLink * Add(SLink*head)
{
SLink *p;
SLink *pp;
pp=head;
p=new SLink;
cout<<"请输入客户入住房号"<<endl;
cin>>p->Pnum;
while(pp->next)
{
pp=pp->next;
if(pp->Pnum==p->Pnum)
{
cout<<"此房间已经被使用!"<<endl;
return head;
}
}
cout<<"请输入客户的身份证号"<<endl;
cin>>p->Pid;
cout<<"请输入客户姓名"<<endl;
cin>>p->name;
cout<<"请输入客户性别"<<endl;
cin>>p->sex;
cout<<"请输入客户入住时间"<<endl;
cin>>p->petime.year>>p->petime.month>>p->petime.day;
cout<<"请输入客户的预交金"<<endl;
cin>>p->Fmon;
cout<<"请输入客户入住类型:"<<endl;
cin>>p->Ptype;
while(pp->next)
pp=pp->next;
pp->next=p;
p->next=NULL;
return head;
}
SLink * Updata(SLink*head)
{
SLink *p,*p1;
int sign=0;//作为是否找到此信息的标记
p1=head;
p=new SLink;
cout<<"请输入要更新的客户住房号:"<<endl;
cin>>p->Pnum;
while(p1)
{
if(p1->Pnum==p->Pnum)
{
return p1;
sign=1;
}
else p1=p1->next;
}
if(sign==0)
cout<<"此客房为空房"<<endl;
return NULL;
}
SLink*Delete(SLink*head)
{
SLink *p,*p1;
int sign=0;//作为是否找到此信息的标记
p1=head->next;
p=new SLink;
cout<<"请输入要删除的客户住房号:"<<endl;
cin>>p->Pnum;
while(p1)
{
if(p1->Pnum==p->Pnum)
{
return p1;
sign=1;
}
else p1=p1->next;
}
if(sign==0)
cout<<"此客房为空房"<<endl;
return head;
}
SLink*Query(SLink*head)
{ SLink *p1,*p2;
int sign;//作为查找是否成功的标志
p2=new SLink;
cout<<"********************************"<<endl;
cout<<"Choose a Query from a flowing list"<<endl;
cout<<endl;
cout<<"(1)Query by numble"<<endl;
cout<<"(2)Query by name"<<endl;
cout<<"(3)Query by sex"<<endl;
int k2;
cin>>k2;
switch(k2)
{
case 1:
cout<<"Please input the numble you want to query"<<endl;
cin>>p2->Pnum;
for(p1=head->next;p1;p1=p1->next)
{
if(p1->Pnum==p2->Pnum)
{
cout<<"你要查找的信息为:"<<endl;
cout<<"入住房号:"<<p1->Pnum<<endl;
cout<<"房主身份证号:"<<p1->Pid<<endl;
cout<<"房主姓名:"<<p1->name<<endl;
cout<<"客户性别:"<<p1->sex<<endl;
cout<<"客户入住时间:"<<p1->petime.year<<p1->petime.month<<p1->petime.day<<endl;
cout<<"客户预付款:"<<p1->Fmon;
cout<<"客户住房类型:"<<p1->Ptype;
sign=1;break;
}
}
if(sign==0) cout<<"查找失败!"<<endl;
break;
case 2:
cout<<"Please input the name you want to query"<<endl;
cin>>p2->name;
for(p1=head->next;p1;p1=p1->next)
{
if(strcmp(p1->name,p2->name)==0)
{
cout<<"你要查找的信息为:"<<endl;
cout<<"你要查找的信息为:"<<endl;
cout<<"入住房号:"<<p1->Pnum<<endl;
cout<<"房主身份证号:"<<p1->Pid<<endl;
cout<<"房主姓名:"<<p1->name<<endl;
cout<<"客户性别:"<<p1->sex<<endl;
cout<<"客户入住时间:"<<p1->petime.year<<p1->petime.month<<p1->petime.day<<endl;
cout<<"客户预付款:"<<p1->Fmon;
cout<<"客户住房类型:"<<p1->Ptype;
sign=1;break;
}
}
if(sign==0) cout<<"查找失败!"<<endl;
break;
case 3:
cout<<"Please input the sex you want to query"<<endl;
cin>>p2->sex;
for(p1=head->next;p1;p1=p1->next)
{
if(p1->sex==p2->sex)
{
cout<<"你要查找的信息为:"<<endl;
cout<<"入住房号:"<<p1->Pnum<<endl;
cout<<"房主身份证号:"<<p1->Pid<<endl;
cout<<"房主姓名:"<<p1->name<<endl;
cout<<"客户性别:"<<p1->sex<<endl;
cout<<"客户入住时间:"<<p1->petime.year<<p1->petime.month<<p1->petime.day<<endl;
cout<<"客户预付款:"<<p1->Fmon;
cout<<"客户住房类型:"<<p1->Ptype;
sign=1;
}
}
if(sign==0) cout<<"查找失败!"<<endl;
break;
default :cout<<"请按要求输入";break;
}
return head;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -