各位大哥大姐帮我看看这个程序问题在哪好不好??
呃 还没写 完 已经漏洞百出了 我郁闷啊 #include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <ctime>
#include <cstdlib>
void choose(char);
void menu();
int montoday(int,int);
int days(int,int,int);
bool choose_a(char *);
const int LENname=6;
const int LENIDc=18;
const int LENnat=6;
const int MAXroom=500;
const int LENphone=11;
class GuestDate{
char name[LENname];
char sex[2];
char IDc[LENIDc];
char nat[LENnat];
char phone[LENphone];
int roomID;
int delTag;
public:
GuestDate() {delTag=0;}
int year;
int mon;
int day;
char *getname() {return name;}
char *getsex() {return sex;}
char *getIDc() {return IDc;}
char *getnat() {return nat;}
char *getphone() {return phone;}
int getdelTag() {return delTag;}
int getroomID() {return roomID;}
void setname(char na[]) {strcpy(name,na);}
void setsex(char na[]) {strcpy(sex,na);}
void setIDc(char na[]) {strcpy(IDc,na);}
void setnat(char na[]) {strcpy(nat,na);}
void setphone(char na[]) {strcpy(phone,na);}
void setroomID(int na) {roomID=na;}
void del() {delTag=0;}
void unDel() {delTag=1;}
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class GuestWay{
public:
GuestDate guest[MAXroom];
void showdate(int);
void showdate();
void save();
void open();
void newfile();
void del(int roomID)
{
guest[roomID].del();
}
int roomIDscan(int roomID){
if(1==guest[roomID].getdelTag()) return 1;
return 0;
}
void IDcscan(char []);
};
void GuestWay::showdate(int i)
{
cout.flags(ios::left);
cout<<setw(8)<<guest[i].getname()
<<setw(4)<<guest[i].getsex()
<<setw(20)<<guest[i].getIDc()
<<setw(8)<<guest[i].getnat()
<<setw(9)<<guest[i].getphone()
<<setw(6)<<guest[i].getroomID()
<<endl;
}
void GuestWay::showdate()
{
cout.flags(ios::left);
cout<<setw(8)<<"姓名"
<<setw(6)<<"性别"
<<setw(20)<<"身份证"
<<setw(8)<<"籍贯"
<<setw(14)<<"手机号"
<<setw(6)<<"房间"
<<endl;
for(int i=1;i<MAXroom;i++)
if(guest[i].getdelTag()==1)
showdate(i);
}
void GuestWay::save()
{
fstream f("GusetDate.date",ios::in|ios::binary);
for(int i=1;i<MAXroom;i++)
f.write((char*)&guest[i],sizeof(guest[i]));
f.close();
}
void GuestWay::open()
{
fstream f("GusetDate.date",ios::in|ios::binary);
int roomID=0;
for(;;)
{
if(!f)
break;
roomID++;
f.seekg(roomID*sizeof(guest[roomID]));
f.read((char*)&guest[roomID],sizeof(guest[roomID]));
}
f.close();
}
void GuestWay::IDcscan(char IDc[])
{
for(int i=1;i<=MAXroom;i++)
{
if (0==strcmp(guest[i].getIDc(),IDc)) GuestWay::showdate(i);
else cout<<"没有入住该旅客"<<endl;
}
}
void GuestWay::newfile()
{
int roomID;
char name[LENname];
char sex[2];
char IDc[LENIDc];
char nat[LENnat];
char phone[LENphone];
for(;;){
cout<<"输入房间"<<endl;
cin>>roomID;
if(0==GuestWay::roomIDscan(roomID) && roomID<MAXroom)
guest[roomID].setroomID(roomID);
else {
cout<<"该房间已有人"<<endl;
break;
}
cout<<"输入姓名"<<endl;
cin>>name; guest[roomID].setname(name);
cout<<"输入性别"<<endl;
cin>>sex;
guest[roomID].setsex(sex);
cout<<"输入身份证"<<endl;
cin>>IDc;
guest[roomID].setIDc(IDc);
cout<<"输入籍贯"<<endl;
cin>>nat;
guest[roomID].setnat(nat);
cout<<"输入手机号"<<endl;
cin>>phone;
guest[roomID].setphone(phone);
guest[roomID].year=0;
guest[roomID].mon=0;
guest[roomID].day=0;
guest[roomID].unDel();
break;
}
for(int i=1;i<roomID;i++){
if(1==guest[i].getdelTag() && guest[roomID].getroomID() < guest[i].getroomID()){
GuestDate temp;
temp=guest[i];
guest[i]=guest[roomID];
guest[roomID]=temp;
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void menu()
{
cout<<"按1入住"<<" "
<<"按2退房"<<" "
<<"按3显示住房信息"<<" "
<<"按4房间查询"<<" "
<<"按5身份证查询"<<" "
<<"按q退出"<<" "<<endl;
}
void choose(char key){
GuestWay guest;
guest.open();
switch(key){
case 49 :
//guest.open();
guest.newfile();
//guest.save();
break;
case 50 :
//guest.open();
cout<<"输入房间"<<endl;
int roomID;
cin>>roomID;
if(0==guest.roomIDscan(roomID)) {
cout<<"该房间没有人"<<endl;
break;
}
else
{
guest.del(roomID);
//guest.save();
}
break;
case 51 :
//guest.open();
guest.showdate();
break;
case 52 :
//guest.open();
cout<<"输入房间"<<endl;
cin>>roomID;
if(0==guest.roomIDscan(roomID)) {
cout<<"该房间没有人"<<endl;
break;
}
else guest.showdate(roomID);
break;
case 53 :
char IDc[18];
cin>>IDc;
guest.IDcscan(IDc);
break;
case 113: exit(0);
default : cout<<"输入错误,重新输入"<<endl;
}
guest.save();
}
int montoday(int year,int mon){
int day;
switch(mon){
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12:
day=31;break;
case 4 :
case 6 :
case 9 :
case 11:
day=30;break;
case 2 :
if( year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
day=29;
else
day=28;
}
return day;
}
int days(int year,int mon,int day){
return montoday(year,mon)+day;
}
bool choose_a(char *p){
int k=0;
while(*p) {p++;k++;}
if (k==1) return true;
else return false;
}
void main()
{
menu();
while(1)
{
char key[10];
cin>>key;
if (choose_a(key))
{
choose(key[0]);
menu();
}
else {cout<<"输入错误"<<endl;menu();}
}
}