📄 accountmanage.cpp.bak
字号:
/*
* File: accountmanage.cpp
* --------------
* This file implements the accountmanage.h interface.
*/
#include "accountmanage.h"
/* Implementation */
AccountManage::AccountManage()
{
numOfAccounts=0;
allAccountList=new (struct AllAccountList);
if (allAccountList == NULL ) Error("");
else {
allAccountList->curAccount=NULL;
allAccountList->next=NULL;
}
}
int AccountManage::GetNumOfAccounts()
{
return numOfAccounts;
}
void AccountManage::AddAccount( Account *newAccount)
{
struct AllAccountList *p,*newp;
p=allAccountList;
newp=new (struct AllAccountList);
if (newp == NULL )Error("");
newp->curAccount=newAccount;
newp->next=NULL;
while (p->next != NULL) p=p->next;
p->next=newp;
numOfAccounts++;
}
bool AccountManage::DeleteAccount( Account *acc )
{
struct AllAccountList *p,*temp;
p=allAccountList->next;
temp=allAccountList;
while (p != NULL && p->curAccount != acc) {temp=p;p=p->next;}
if (p == NULL) {Error("Not Found this Account~");return false;}
temp->next=p->next;
delete p;
numOfAccounts--;
return true;
}
//bool ModifyAccount( Account * );
Account *AccountManage::GetAccount( int id, string nam, string card, int phone ) //add
{
struct AllAccountList *p;
p=allAccountList->next;
while (p != NULL) {
if (id ==-1 || p->curAccount->GetID() == id)
if (nam == "" || p->curAccount->GetName() == nam)
if (card == "" || p->curAccount->GetCCardNum() == card)
if (phone == 0 || p->curAccount->GetPhoneNum() == phone){
return p->curAccount;
}
p=p->next;
}
return NULL;
}
struct AllAccountList *AccountManage::GetAllAccountList()
{
return allAccountList;
}
void AccountManage::PrintAccountList( int type )
{
cout<<"TotalAccount: "<<numOfAccounts<<endl;
cout<<" ID"<<setw(15)<<"Name"<<setw(14)<<"PhoneNume"<<endl;
struct AllAccountList *p=allAccountList->next;
while (p != NULL){
if (p->curAccount->GetNumOfRooms()-type >= 0) p->curAccount->PrintInfoBrief();
p=p->next;
}
}
void AccountManage::PrintAccountInfo( Account *p )
{
/*
struct AllAccountList *p=allAccountList->next;
while (p != NULL && p->curAccount->GetID() != id) p=p->next;
if (p == NULL) Error("Not Found this ID!");
p->curAccount->PrintInfo();
*/
p->PrintInfo();
}
void AccountManage::WriteToFile(ofstream *fout)///
{
*fout << "<ACCOUNTMANAGE>" << endl << numOfAccounts << endl;
struct AllAccountList *tempList = allAccountList->next;
while (tempList != NULL)
{
tempList->curAccount->WriteToFile(fout);
tempList = tempList->next;
}
}
void AccountManage::ReadFromFile(ifstream *fin)///
{
string temp_s;
int num;
*fin >> temp_s;
*fin >> num;
//allAccountList = NULL;
for (int i = 0; i < num; i++)
{
Account *q = new Account;
if (q == NULL) {Error("");return;}
q->ReadFromFile(fin);
AddAccount(q);
}
}
void AccountManage::CleanAllAccount()
{
struct AllAccountList *p,*temp;
p=allAccountList->next;
temp=allAccountList;
while (p != NULL){
temp=p->next;
DeleteAccount(p->curAccount);
p=temp;
}
numOfAccounts=0;
}
AccountManage::~AccountManage()
{
CleanAllAccount();
struct AllAccountList *p=allAccountList;
while (allAccountList->next != NULL){
allAccountList=allAccountList->next;
delete p;
p=allAccountList;
}
delete p;
}
/* Function: NewAccount()
* Usage: *Account=*NewAccount(ID);
* ---------------------------
* This function allow the user to create a new account
* by entering all the account info,
* and the account's ID will be set in default,
* and returns the pointer of the new account.
*/
Account *NewAccount(int num)
{
string t;
int tt;
Account *tAcc;
tAcc=new Account;
if (tAcc == NULL) return NULL;
while (1){
tAcc->SetID(num+1001);
cout<<"Please input the Name:";
tAcc->SetName(GetString());
cout<<"Please input the Sex(1-Male 2-Female):";
tt=GetInt();
while (tt < 1 || tt > 2) {cout<<"Input must be '1' or '2' :";tt=GetInt();}
tAcc->SetSex(Sex(tt-1));
cout<<"Please input the Pay Type(1-Cash 2-Check):";
tt=GetInt();
while (tt < 1 || tt > 2) {cout<<"Input must be '1' or '2' :";tt=GetInt();}
tAcc->SetPayType(PayType(tt));
cout<<"Please input CreditCard Type(1-students 2-identity 3-others):";
tt=GetInt();
while (tt < 1 || tt > 3) {cout<<"Input must be '1' or '2' or '3' :";tt=GetInt();}
tAcc->SetCCardType(CreditCardType(tt-1));
cout<<"Please input the CreditCard Number:";
tAcc->SetCCardNum(GetString());
cout<<"Please input the Address:";
tAcc->SetAddress(GetString());
cout<<"Please input the Phone Num:";
tt=GetInt();
//while (tt < 1 || tt > 2) {cout<<"Input must be '1' or '2' :";tt=GetInt();}
tAcc->SetPhoneNum(tt);
cout<<"Please input the remark:";
tAcc->SetRemarks(GetString());
cout<<"=======The New Account Info====="<<endl;
tAcc->PrintInfo();
cout<<"Is it Correct?(y/n):";
char com=GetYesNo();
if (com == 'y') {
cout<<"Add Account Success~"<<endl;
cout<<"ID:"<<tAcc->GetID()<<endl<<"Name:"<<tAcc->GetName()<<endl;
return tAcc;
}
cout<<"Please Input the Account Info Again..:"<<endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -