?? account.cpp.bak
字號:
/*
* File: account.cpp
* --------------
* This file implements the account.h interface.
*/
#include "account.h"
/* Implements */
//for Account..
Account::Account( int id, int exp, int pre, int rooms, int roomnums, bool noteno )
{
curExpences=exp;
preExpences=pre;
numOfRooms=rooms;
numOfRoomNums=roomnums;
notEnoughExpences=noteno;
ID=1000;
score=0;
VIPLevel=1;
notEnoughExpences=false;
pType=CASH;
cCardType=IDENTITYCARD;
roomList=new (struct AccRoomList);
if (roomList == NULL) {Error("");return;}
roomList->curRoom=NULL;
roomList->next=NULL;
roomNumList=new (struct AccRoomNumList);
if (roomNumList == NULL) Error("");
roomNumList->roomNum=0;
roomNumList->next=NULL;
}
void Account::SetInfo() //add
{
}
void Account::SetID( int num )
{
ID=num;
}
void Account::SetScore( int num )
{
score=num;
}
void Account::SetName( string temp )
{
name=temp;
}
void Account::SetSex( Sex temp )
{
sex=temp;
}
void Account::SetCCardType( CreditCardType type )
{
cCardType=type;
}
void Account::SetCCardNum( string num )
{
cCardNum=num;
}
void Account::SetAddress( string addr )
{
address=addr;
}
void Account::SetPhoneNum( int num )
{
phoneNum=num;
}
void Account::SetCurExpences( int num ) //add
{
curExpences=num;
}
void Account::SetPreExpences( int exp )
{
preExpences=exp;
}
int Account::CheckExpences( Room *room )
{
struct AccRoomList *pr;
pr=roomList->next;
int tempExp=0;
int temp=0;
int ret=0;
while (pr != NULL){
temp=pr->curRoom->GetCurExpences();
tempExp+=temp;
if (pr->curRoom == room) ret=temp;
pr=pr->next;
}
curExpences=tempExp;
if (curExpences > preExpences) notEnoughExpences=true;
else notEnoughExpences=false;
return ret;
}
bool Account::GetNotEnoughExpences()
{
return notEnoughExpences;
}
void Account::SetRemarks( string temp )
{
remarks=temp;
}
int Account::GetNumOfRooms()
{
return numOfRooms;
}
string Account::GetName()
{
return name;
}
string Account::GetCCardNum()
{
return cCardNum;
}
int Account::GetPhoneNum()
{
return phoneNum;
}
int Account::GetID()
{
return ID;
}
int Account::GetScore()
{
return score;
}
int Account::GetCurExpences()
{
return curExpences;
}
int Account::GetPreExpences()
{
return preExpences;
}
struct AccRoomNumList *Account::GetAccRoomNumList()
{
return roomNumList;
}
void Account::AddRoom( Room *room )
{
struct AccRoomList *p,*temp;
temp=new (struct AccRoomList);
if (temp == NULL) {Error("");return;}
temp->curRoom=room;
temp->next=NULL;
p=roomList;
while (p->next != NULL) p=p->next;
p->next=temp;
numOfRooms++;
}
void Account::DeleteRoom( Room *room )
{
struct AccRoomList *p,*temp;
p=roomList;
while (p->curRoom != room && p->next != NULL) {temp=p;p=p->next;}
if (p->curRoom == room) temp->next=p->next;
delete p;
numOfRooms--;
}
void Account::AddRoomNum( int num )
{
struct AccRoomNumList *p,*temp;
temp=new (struct AccRoomNumList);
if (temp == NULL) {Error("");return;}
temp->roomNum=num;
temp->next=NULL;
p=roomNumList;
while (p->next != NULL) p=p->next;
p->next=temp;
numOfRoomNums++;
}
void Account::DeleteRoomNum( int num )
{
struct AccRoomNumList *p,*temp;
p=roomNumList;
while (p->roomNum != num && p->next != NULL) {temp=p;p=p->next;}
if (p->roomNum == num) temp->next=p->next;
delete p;
numOfRoomNums--;
}
void Account::SetPayType( PayType type )
{
pType=type;
}
void Account::PrintInfoBrief()
{
cout<<setw(4)<<ID<<setw(15)<<name<<setw(14)<<phoneNum<<endl;
}
void Account::PrintInfo()
{
cout<<"Account Info:"<<endl;
cout<<"ID:"<<ID<<endl;
cout<<"Name:"<<name<<endl;
cout<<"Sex:";
switch(sex)
{
case MALE:cout<<"Male"<<endl;break;
case FEMALE:cout<<"Female"<<endl;break;
default:break;
}
cout<<"CreditCardType:";
switch(cCardType)
{
case STUDENTSCARD:cout<<"StudentsCard"<<endl;break;
case IDENTITYCARD:cout<<"IdentityCard"<<endl;break;
case OTHERS:cout<<"Others"<<endl;break;
default:break;
}
cout<<"CardNumber:"<<cCardNum<<endl;
cout<<"PhoneNumber:"<<phoneNum<<endl;
cout<<"Address:"<<address<<endl;
cout<<"PayType:";
switch (pType)
{
case PRE:cout<<"Pre"<<endl;break;
case CASH:cout<<"Cash"<<endl;break;
case CHECK:cout<<"Check"<<endl;break;
default:break;
}
cout<<"Remaining sum:"<<preExpences<<endl;
if (CheckExpences(NULL));
cout<<"CurrentExpences:"<<curExpences<<endl;
cout<<"Score:"<<score<<endl;
cout<<"Remarks:"<<remarks<<endl;
cout<<"RoomState:"<<endl;
if (numOfRooms == 0) cout<<"None"<<endl;
else{
AccRoomList *p;
p=roomList->next;
for (int i=1;i<=numOfRooms;i++) {
cout<<"Room "<<i<<" : "<< p->curRoom->GetRoomNum() <<endl;
p=p->next;
}
}
cout<<"-EOF-"<<endl;
}
void Account::WriteToFile(ofstream *fout)///
{
*fout << "<ACCOUNT>" << endl << ID << ' ' << VIPLevel << endl << name << endl << sex << ' '
<< cCardType << endl << cCardNum << endl << address << endl << phoneNum << ' '
<< curExpences << ' ' << preExpences << ' ' << notEnoughExpences << endl
<< remarks << endl << pType << ' ' << numOfRooms << endl;
struct AccRoomList *tempList = roomList->next;
while (tempList != NULL)
{
*fout<< tempList->curRoom->GetRoomNum() << endl;
tempList = tempList->next;
}
}
void Account::ReadFromFile(ifstream *fin)///
{
string temp_s;
int numOfrooms;
int iSex, iCardType, iPayType;
*fin >> temp_s;
*fin >> ID >> VIPLevel ;
(*fin).ignore(max_c,'\n');
getline(*fin,name,'\n');
*fin >> iSex >> iCardType >> cCardNum ;
(*fin).ignore(max_c,'\n');
getline(*fin,address,'\n');
*fin >> phoneNum >> curExpences >> preExpences >> notEnoughExpences ;
(*fin).ignore(max_c,'\n');
getline(*fin,remarks,'\n');
*fin >> iPayType >> numOfrooms;
sex = Sex(iSex);
cCardType = CreditCardType(iCardType);
pType = PayType(iPayType);
int num;
for (int i = 0; i < numOfrooms; i++)
{
*fin >> num;
AddRoomNum(num);
}
}
Account::~Account()
{
struct AccRoomList *p;
p=roomList;
while (roomList->next != NULL ){
roomList=roomList->next;
delete p;
p=roomList;
}
delete p;
struct AccRoomNumList *t;
t=roomNumList;
while (roomNumList->next != NULL){
roomNumList=roomNumList->next;
delete t;
t=roomNumList;
}
delete t;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -