数据结构-----停车场管理系统(C++实现)

本实验有5个类:

Time             ---停车场时间类

Stack            ---停车场栈类

Queue          ---停车场便道队列类

SystemLog   ---停车场系统日志类

CarSystem   ---停车场系统类

---------------------------------------

分别有11个文件:

Time           ----Time.h        Time.cpp

Stack          ----Stack.h      Stack.cpp

Queue        ----Queue.h    Queue.cpp

SystemLog -----SystemLog.h      SystemLog.cpp

CarSystem  -----CarSystem.h     CarSystem.cpp

分别为对应的声明(头文件)和实现

下面的这些文件的包含关系:

int main()

#include "CarSystem.h"

   #include "SystemLog.h"

     #include "Queue.h"

        #include "Stack.h"

          #include "Time.h"

文件的包含很不合理,有待日后改进~!

----------------------------------------------------------------

下面是源代码:

------------------------------------------------------------------------------------------

 //------Time.h--------

#include <iostream>
using namespace std;

class Time
{
private:
 int _hour;
 int _minute;
public:
 Time();
 Time(int hour,int minute);
 Time(const Time& time);
 bool SetTime(int hour,int minute);
 bool Check_Time()const;
 bool ReSet_timeArr();
 bool operator==(const Time& time)const;
 bool operator>(const Time& time)const;
 bool operator<(const Time& time)const;
 bool operator>=(const Time& time)const;
 bool operator<=(const Time& time)const;
 bool operator!=(const Time& time)const;
 const Time operator+(int minute);
 const Time operator+(const Time& time);
 const int  operator-(const Time& time);
 const Time operator-(int minute);
 const Time operator+=(const Time& time);
 const Time operator-=(const Time& time);
 const Time operator=(const Time& time);
 const Time operator++(int a);
 const Time operator--(int a);
 friend const Time operator++(Time& time);
 friend const Time operator--(Time& time);
 friend ostream& operator<<(ostream& out,const Time& time);
 friend istream& operator>>(istream& ins,Time& time);
};

--------------------------------------------------------------------------------

//----------Time.cpp----------

#include "Time.h"
using namespace std;

 

Time::Time()
{
 _hour=0;
 _minute=0;
}

Time::Time(int hour, int minute)
{
 _hour=hour;
 _minute=minute;
}


Time::Time(const Time &time)
{
 _hour=time._hour;
 _minute=time._minute;
}


bool Time::SetTime(int hour, int minute)
{
 _hour=hour;
 _minute=minute;
 return true;
}


bool Time::Check_Time()const
{
 if (_hour<0||_hour>=24||_minute<0||_minute>=60)
  return false;
 return true;
}


bool Time::ReSet_timeArr()
{
 if (Check_Time())
  return true;
 if (_minute<0)
 {
  _hour--;
  _minute+=60;
 }
 else if (_minute>=60)
 {
  _hour++;
  _minute-=60;
 }
 if (_hour<0)
 {
  _hour+=24;
 }
 else if (_hour>=24)
 {
  _hour-=24;
 }
 return true;
}


bool Time::operator ==(const Time &time)const
{
 return ((this->_hour==time._hour)&&(this->_minute==time._minute));
}

bool Time::operator !=(const Time &time)const
{
 return !(*this==time);
}

bool Time::operator >(const Time &time)const
{
 if (_hour>time._hour)
 {
  return true;
 }
 else if (_hour==time._hour&&_minute>time._minute)
 {
  return true;
 }
 else
  return false;
}

bool Time::operator >=(const Time &time)const
{
 if (_hour>time._hour)
 {
  return true;
 }
 else if (_hour==time._minute&&_minute>=time._minute)
 {
  return true;
 }
 else
  return false;
}

bool Time::operator <(const Time &time)const
{
 if (_hour<time._hour)
 {
  return true;
 }
 else if (_hour==time._hour&&_minute<time._minute)
 {
  return true;
 }
 else
  return false;
}


bool Time::operator <=(const Time &time)const
{
 if (_hour<time._hour)
 {
  return true;
 }
 else if (_hour==time._hour&&_minute<=time._minute)
 {
  return true;
 }
 else
  return false;
}


const Time Time::operator +(int minute)
{
 Time temp(*this);
 temp._minute+=minute;
 temp.ReSet_timeArr();
 return temp;
}

const Time Time::operator +(const Time &time)
{
 Time temp;
 temp._hour=_hour+time._hour;
 temp._minute=_minute+time._minute;
 temp.ReSet_timeArr();
 return temp;
}


const Time Time::operator +=(const Time &time)
{
 _hour+=time._hour;
 _minute+=time._minute;
 ReSet_timeArr();
 return *this;
}


const int Time::operator -(const Time& time)
{
 int minute;
 minute=(_hour-time._hour)*60+_minute-time._minute;
 return minute;
}


const Time Time::operator -(int minute)
{
 Time temp(*this);
 temp._minute-=minute;
 temp.ReSet_timeArr();
 return temp;
}


const Time Time::operator -=(const Time& time)
{
 _hour-=time._hour;
 _minute-=time._minute;
 ReSet_timeArr();
 return *this;
}


const Time Time::operator =(const Time& time)
{
 if (!time.Check_Time())
  return Time(-1,-1);
 _hour=time._hour;
 _minute=time._minute;
 return *this;
}


const Time Time::operator++(int a)
{
 Time temp=*this;
 _minute++;
 ReSet_timeArr();
 return temp;
}

const Time Time::operator--(int a)
{
 Time temp=*this;
 _minute--;
 ReSet_timeArr();
 return temp;
}

const Time operator++(Time& time)
{
 time++;
 return time;
}


const Time operator--(Time& time)
{
 time--;
 return time;
}


ostream& operator<<(ostream& out,const Time& time)
{
 if (!time.Check_Time())
 {
  out<<"Error Time!"<<endl;
  return out;
 }
 if (time._hour<10)
 {
  out<<"0"<<time._hour;
 }
 else
 {
  out<<time._hour;
 }
 out<<":";
 if (time._minute<10)
 {
  out<<"0"<<time._minute;
 }
 else
 {
  out<<time._minute;
 }
 return out;
}


istream& operator>>(istream& ins,Time& time)
{
 int hour,minute;
 ins>>hour;
 ins.ignore(1);
 ins>>minute;
 time.SetTime(hour,minute);
 return ins;
}

------------------------------------------------------------------

//--------Stack.h------------

#include "Time.h"
#include <string>
#define STACK_INIT_SIZE 100 //栈初始容量
#define STACK_INCR_SIZE 50  //栈增量

 

typedef struct CarNode
{//汽车信息结构体
 string _carNum;
 int _carType;//汽车类型数字代表占位置的大小
 Time _timeArr;//到达时间
 Time _timeBgn;//入车场时间,若一来到就进入车场,则与_timeArr相等,否则为进入车场的当前系统时间
}CarNode,*CarNodePtr;


class Stack
{//顺序栈,初始100,50递增
private:
 CarNodePtr _base,_top;//头尾指针
 int _stack_capacity;//栈大小
 int _stack_size;//栈使用大小
 int _stack_sum;//车辆总数
public:
 Stack();
 Stack(Stack& oldStack);//此操作部销毁oldStack
 ~Stack();
 bool IncSize(int size=STACK_INCR_SIZE);//栈扩容。此操作创建一个增容的新栈,并复制当前栈中内容,然后删除旧的栈。
 bool ReSetStack(int capacity);//删除重设新栈
 bool Empty()const;//栈中没有元素返回true,否则false
 bool Full()const;
 bool Clear();//清空。重置_top指针,元素的值不理会
 int  StackCapacity()const;//返回栈容量
 int  StackSize()const;//返回栈使用大小
 int  StackSum()const;//返回汽车数量
 bool Find(const CarNode& target)const;//找车辆位置
 CarNodePtr GetBase()const;//返回栈底指针
 CarNodePtr GetTop()const;//返回栈顶元素指针(栈顶指针的前一项)
 bool Push(const CarNode& car);//car压入栈顶
 CarNode Pop();//栈顶元素弹出
 friend ostream& operator<<(ostream& out,const Stack& carStack);
 friend ostream& operator<<(ostream& out,const CarNode carNode);
 friend istream& operator>>(istream& ins,CarNode& carNode);
};

---------------------------------------------------------------------------------------------------------------------------------------------

//--------------Stack.cpp-------------------

#include "Stack.h"


Stack::Stack()
{
 _base=new CarNode[STACK_INIT_SIZE];
 for (int i=0;i<STACK_INIT_SIZE;++i)
 {
  _base[i]._carType=0;
 }//for
 _top=_base;
 _stack_capacity=STACK_INIT_SIZE;
 _stack_size=0;
 _stack_sum=0;
}//Stack

Stack::Stack(Stack& oldStack)
{
 CarNodePtr pOldStack=oldStack._base;
 int oldsum=oldStack._stack_sum;
 _base=new CarNode[oldStack._stack_capacity];
 _top=_base;
 for (int i=0;i<oldsum;++i)
 {
  _top->_carNum=pOldStack->_carNum;
  _top->_carType=pOldStack->_carType;
  _top->_timeArr=pOldStack->_timeArr;
  _top->_timeBgn=pOldStack->_timeBgn;
  _top++;
  pOldStack++;
 }//for
 _stack_sum=oldStack._stack_sum;
 _stack_size=oldStack._stack_size;
 _stack_capacity=oldStack._stack_capacity;
}


Stack::~Stack()
{
 delete [] _base;
 _base=_top=NULL;
}


bool Stack::IncSize(int size)
{
 CarNodePtr pCarNode,pOldStack=_base;
 pCarNode=new CarNode[_stack_capacity+size];
 _top=pCarNode;//暂存
 for (int i=0;i<_stack_sum;++i)
 {
  pCarNode->_carNum=pOldStack->_carNum;
  pCarNode->_carType=pOldStack->_carType;
  pCarNode->_timeArr=pOldStack->_timeArr;
  pCarNode->_timeBgn=pOldStack->_timeBgn;
  pCarNode++;
  pOldStack++;
 }//for
 delete [] _base;
 _base=_top;//交换
 _top=pCarNode;
 _stack_capacity+=size;
 return true;
}

bool Stack::ReSetStack(int capacity)
{
 delete [] _base;
 _base=new CarNode[capacity];
 _top=_base;
 _stack_capacity=capacity;
 _stack_size=0;
 _stack_sum=0;
 return true;
}

bool Stack::Empty()const
{
 return _stack_sum==0;//or_stack_size<=0;
}


bool Stack::Full()const
{
 return _stack_size>=_stack_capacity;
}


bool Stack::Clear()
{
 _top=_base;
 _stack_sum=0;
 _stack_size=0;
 return true;
}

 

int Stack::StackCapacity()const
{
 return _stack_capacity;
}

int Stack::StackSize()const
{
 return _stack_size;
}

int Stack::StackSum()const
{
 return _stack_sum;
}


bool Stack::Find(const CarNode& target)const
{
// int pos=0;
 CarNodePtr pTemp=_base;
 while (pTemp!=_top)
 {
//  pos++;
  if (pTemp->_carNum==target._carNum)
  {//找到
//   break;
   return true;
  }//if
  pTemp++;
 }//while
// return pos;
 return false;
}


CarNodePtr Stack::GetTop()const
{
 return _top-1;
}

CarNodePtr Stack::GetBase()const
{
 return _base;
}


bool Stack::Push(const CarNode& car)
{//去掉了栈满判断,以及自动增容功能
 _top->_carNum=car._carNum;
 _top->_carType=car._carType;
 _top->_timeArr=car._timeArr;
 _top->_timeBgn=car._timeBgn;
 _top++;
 _stack_size+=car._carType;//位置
 _stack_sum++;
 return true;
}


CarNode Stack::Pop()
{//去掉了栈空判断
 _top--;
 _stack_size-=_top->_carType;
 _stack_sum--;
 return *_top;
}


ostream& operator<<(ostream& out,const Stack& carStack)
{
 int count=0;
 CarNodePtr pLink_base=carStack._base,pLink_top=carStack._top;
 out<<"Index/tCarNumber/tCarType/t/tArrTime/t/tBgnTime"<<endl;
 while (pLink_base!=pLink_top)
 {
  out<<++count<<"/t"<<pLink_base->_carNum<<"/t/t"<<pLink_base->_carType<<"/t/t"<<pLink_base->_timeArr<<"/t/t"<<pLink_base->_timeBgn<<endl;
  pLink_base++;
 }//while
 cout<<"Stack Capacity:"<<carStack._stack_capacity<<"/tStack Size:"<<carStack._stack_size<<"/tStack Sum:"<<carStack._stack_sum<<endl;
 return out;
}

 

ostream& operator<<(ostream& out,const CarNode carNode)
{
 out<<carNode._carNum<<"/t/t"<<carNode._carType<<"/t"<<carNode._timeArr<<"/t"<<carNode._timeBgn;
 return out;
}


istream& operator>>(istream& ins,CarNode& carNode)
{
 getline(ins,carNode._carNum,',');//受到终止符号的限制,输入命令时必须小心。
 ins>>carNode._carType;
 ins.ignore();
 ins>>carNode._timeArr;
 return ins;
}

-----------------------------------------------------------------------------------------------------------------------------------------------

//----------------Queue.h-------------------------

#include "Stack.h"
#define QUEUE_INIT_SIZE 100 //队列初始容量
#define QUEUE_INCR_SIZE 50  //队列增量


class Queue
{//顺序队列,初始100,增量50
private:
 CarNodePtr _base;//顺序队列头指针
 int _front,_reer;//游标(下标控制)
 int _queue_capacity;//队列大小
 int _queue_size;//队列使用大小
 int _queue_sum;//汽车数量
public:
 Queue();
 Queue(Queue& carQueue);
 ~Queue();
 bool IncSize(int size=QUEUE_INCR_SIZE);//队列扩容。增容后复制旧队列的信息,并删除旧队列。
 bool ReSetQueue(int capacity);//删除并重设新队列
 bool Empty()const;
 bool Full()const;
 bool Clear();
 int  QueueSize()const;
 int  QueueCapacity()const;
 int  QueueSum()const;
 bool Find(const CarNode& target)const;
 CarNodePtr GetBase()const;
 CarNode GetFront()const;
 CarNode GetReer()const;
 bool EnQueue(CarNode& carNode);
 CarNode DeQueue();
 friend ostream& operator<<(ostream& out,const Queue& carQueue);
};

------------------------------------------------------------------------------------------------------------------------------

//---------------Queue.cpp------------------

#include "Queue.h"


Queue::Queue()
{
 _base=new CarNode[QUEUE_INIT_SIZE];
 _front=_reer=0;
 _queue_capacity=QUEUE_INIT_SIZE;
 _queue_size=0;
 _queue_sum=0;
}


Queue::Queue(Queue &carQueue)
{
 int oldSize=carQueue._queue_capacity;
 int oldSum=carQueue._queue_sum;//不用多次调用
 _base=new CarNode[oldSize];
 _queue_capacity=oldSize;
 _front=0;
 for (_queue_sum=0;_queue_sum<oldSum;++_queue_sum)
 {
  _base[_queue_sum]._carNum=carQueue._base[_queue_sum]._carNum;
  _base[_queue_sum]._carType=carQueue._base[_queue_sum]._carType;
  _base[_queue_sum]._timeArr=carQueue._base[_queue_sum]._timeArr;
  _base[_queue_sum]._timeBgn=carQueue._base[_queue_sum]._timeBgn;
 }//for
 _reer=_queue_sum;
 _queue_size=carQueue._queue_size;
}

Queue::~Queue()
{
 delete [] _base;
 _base=NULL;
}

bool Queue::IncSize(int size)
{
 CarNodePtr pCarNode=new CarNode[_queue_capacity+size];
 for (int i=0;i<_queue_sum;++i)
 {
  pCarNode[i]._carNum=_base[_front]._carNum;
  pCarNode[i]._carType=_base[_front]._carType;
  pCarNode[i]._timeArr=_base[_front]._timeArr;
  pCarNode[i]._timeBgn=_base[_front]._timeBgn;
  _front=(_front+1)%_queue_capacity;
 }
 delete [] _base;
 _base=pCarNode;
 _front=0;
 _reer=_queue_sum;
 _queue_capacity+=size;
 return true;
}


bool Queue::ReSetQueue(int capacity)
{
 delete [] _base;
 _base=new CarNode[capacity];
 _front=_reer=0;
 _queue_capacity=capacity;
 _queue_size=0;
 _queue_sum=0;
 return true;
}


bool Queue::Empty()const
{
 return _queue_sum==0;//or_queue_size<=0;
}

bool Queue::Full()const
{
 return _queue_size>=_queue_capacity;
}


bool Queue::Clear()
{
 _front=_reer=0;
 _queue_size=0;
 _queue_sum=0;
 return true;
}


int Queue::QueueSize()const
{
 return _queue_size;
}


int Queue::QueueCapacity()const
{
 return _queue_capacity;
}

int Queue::QueueSum()const
{
 return _queue_sum;
}


CarNode Queue::GetFront()const
{
 return _base[_front];
}


CarNode Queue::GetReer()const
{
 return _base[(_reer-1+_queue_capacity)%_queue_capacity];
}

CarNodePtr Queue::GetBase()const
{
 return _base;
}


bool Queue::Find(const CarNode& target)const
{
 int pos=_front;
 for (int i=0;i<_queue_sum;++i)
 {
//  pos++;
  if (_base[pos]._carNum==target._carNum)
  {
//   break;
   return true;
  }//if
  pos=(pos+1)%_queue_capacity;
 }//for
// return pos;
 return false;
}


bool Queue::EnQueue(CarNode &carNode)
{//去掉了队列满检测,自动增容
 _base[_reer]._carNum=carNode._carNum;
 _base[_reer]._carType=carNode._carType;
 _base[_reer]._timeArr=carNode._timeArr;
 _base[_reer]._timeBgn=carNode._timeBgn;
 _reer=(_reer+1)%_queue_capacity;
 _queue_size+=carNode._carType;
 _queue_sum++;
 return true;
}


CarNode Queue::DeQueue()
{
 int i=_front;
 _front=(_front+1)%_queue_capacity;
 _queue_size-=_base[i]._carType;
 _queue_sum--;
 return _base[i];
}

ostream& operator<<(ostream& out,const Queue& carQueue)
{
 out<<"Index/tCarNumber/tCarType/t/tArrTime/t/tBgnTime"<<endl;
 int front=carQueue._front,count=carQueue.QueueSum(),capacity=carQueue._queue_capacity;
 for (int i=0;i<count;++i)
 {
  out<<i+1<<"/t"<<carQueue._base[front]._carNum<<"/t/t"<<carQueue._base[front]._carType<<"/t/t"<<carQueue._base[front]._timeArr<<"/t/t"<<carQueue._base[front]._timeBgn<<endl;//输入错误(错误的换行符),修改~
  front=(front+1)%capacity;
 }
 cout<<"Queue Capacity:"<<carQueue._queue_capacity<<"/tQueue Size:"<<carQueue._queue_size<<"/tQueue Sum:"<<carQueue._queue_sum<<endl;
 return out;
}
--------------------------------------------------------------------------------------------------------------------------------------

//-------------SystemLog.h------------------

#include "Queue.h"

typedef struct LogNode
{
 string _carNum;
 int _carType;
 Time _arrTime;
 Time _bgnTime;
 Time _lveTime;
 int _minute;
 int _fee;
 struct LogNode *_next;
}LogNode,*LogNodePtr;

 

class SystemLog
{
private:
 LogNodePtr _front;
 LogNodePtr _reer;
 int _recordSum;
public:
 SystemLog();
 ~SystemLog();
 bool Clear();
 bool Empty();
 bool SetPakLotFee();
 bool SetSideWayFee();
 LogNodePtr GetFront()const;//此处需修改,不能把头指针给出去
 LogNodePtr GetReer()const;//同上
 bool AddRecord(const CarNode& target,const Time& sysTime,int fee);
 friend ostream& operator<<(ostream& out,const SystemLog& log);
};

-----------------------------------------------------------------------------------------------------------

//----------------SystemLog.cpp---------------------

#include "SystemLog.h"
#include <iomanip>


SystemLog::SystemLog()
{
 _front=new LogNode;//头结点
 _reer=_front;
 _reer->_next=0;
 _recordSum=0;
}


SystemLog::~SystemLog()
{
 LogNodePtr pLog=_front;
 while(pLog!=NULL)
 {
  _front=_front->_next;
  delete pLog;
  pLog=_front;
 }
 _front=_reer=NULL;
 _recordSum=0;
}


bool SystemLog::Clear()
{
 LogNodePtr pDel=_front->_next,pLink=pDel;
 _front->_next=NULL;
 while (pLink!=NULL)
 {
  pLink=pLink->_next;
  delete pDel;
  pDel=pLink;
 }
 _reer=_front;
 _recordSum=0;
 return true;
}


bool SystemLog::Empty()
{
 return _recordSum==0;
}

LogNodePtr SystemLog::GetFront()const
{
 return _front->_next;//第一个元素(跳过头结点)
}

LogNodePtr SystemLog::GetReer()const
{
 return _reer;
}

 

bool SystemLog::AddRecord(const CarNode& target,const Time& sysTime,int fee)
{
 _reer->_next=new LogNode;
 _reer=_reer->_next;
 _reer->_carNum=target._carNum;
 _reer->_carType=target._carType;
 _reer->_arrTime=target._timeArr;
 _reer->_bgnTime=target._timeBgn;
 _reer->_lveTime=sysTime;
 _reer->_minute=_reer->_lveTime-_reer->_arrTime;
 _reer->_fee=fee;
 _reer->_next=NULL;
 return true;
}


ostream& operator<<(ostream& out,const SystemLog& log)
{
 out<<"  ----------------------------------------------------------------------------" <<endl;
 out<<" |                          · 系· 统 · 日 · 志 ·                         |"<<endl;
 out<<" | 序号      车牌号        到达时间       离开时间       计费时间       费用  |"<<endl;
 out<<"  ----------------------------------------------------------------------------"<<endl;
 LogNodePtr pLink=log._front->_next;
 int count=0;
 while (pLink!=NULL)
 {
  out<<" | "<<setw(3)<<++count<<"       "<<pLink->_carNum<<"         "<<pLink->_arrTime<<"           "<<pLink->_lveTime<<"           "<<setw(4)<<pLink->_minute<<"        "<<setw(4)<<pLink->_fee<<"  |"<<endl;
  pLink=pLink->_next;
 }
 out<<" |                                                       ◎共 "<<setw(3)<<count<<" 条日志记录  |"<<endl;
 out<<"  ----------------------------------------------------------------------------"<<endl;
 return out;
}

---------------------------------------------------------------------------------------------------------------------------------------

//--------------------CarSystem.h------------------------

#include "SystemLog.h"
#include <fstream>
#define DEFAULT_PLOT_FEE 8
#define DEFAULT_SWAY_FEE 5
typedef struct Message
{
 char _orderType;
 CarNode car;
}Msg,*MsgPtr;

typedef struct MsgNode
{
 Msg _msg;
 struct MsgNode *_next;
}MsgNode,*MsgNodePtr;

 

class CarSystem
{
private:
 Stack _pakLot;                     //停车场
 Stack _tempLot;                    //临时车场
 Queue _sideWay;                    //便道
 MsgNodePtr _msgData;               //消息数据区
 Msg _msg;                          //消息
 SystemLog _carLog;                 //系统数据库
 Time _sysTime;                     //系统时间
 int _pakLotFee;                    //车场收费标准
 int _sideWayFee;                   //便道收费标准
 string _readMsgFile;               //消息命令库文件
 string _saveLogFile;               //日志保存文件
 bool SetPakLotFee(int feerate);
 bool SetSideWayFee(int feerate);
 bool SetParametor();
 bool HelpFile();
 bool UseSystemHelp();
 bool ParaHelp();
 bool PutPakLotInfo()const;
 bool PutSideWayInfo()const;
public:
 CarSystem();
 ~CarSystem();
 bool GetMsg();
 bool LoadMsg();
 bool ProcessMsgData();
 bool MsgDataEmpty()const;
// int  MsgDataSum()const;
 bool PeekMsg();
 bool CheckMsg();
 bool SetCar();//从msg读取消息
 bool GetCar(CarNode& carMove);
 bool ProcessMsg();
 bool CheckPakLot();
 bool AutoDriveEvent();
 bool DriveEvent();
 bool PakLotTest()const;
 bool SaveLogs();
 friend ostream& operator<<(ostream& out,Msg& msg);
 friend ostream& operator<<(ostream& out,MsgNodePtr msgData);
 bool StartSystem();
};

------------------------------------------------------------------------------------------------------------------------

//---------------CarSystem.cpp---------------------

#include "CarSystem.h"
#include <conio.h>
#include <iomanip>

CarSystem::CarSystem()
{
 _msgData=new MsgNode;
 _msgData->_next=NULL;
 _msg._orderType='E';
 _sysTime.SetTime(0,0);                 //设置停车场系统工作时间
 _pakLotFee=DEFAULT_PLOT_FEE;           //默认车场收费标准
 _sideWayFee=DEFAULT_SWAY_FEE;          //默认便道收费标准
 _readMsgFile="msg.txt";
 _saveLogFile="SystemLog.txt";
}


CarSystem::~CarSystem()
{
 delete _msgData;
 _msgData=NULL;
 _msg._orderType='E';
 _sysTime.SetTime(0,0);
 _pakLotFee=0;
 _sideWayFee=0;
}


bool CarSystem::SetPakLotFee(int feerate)
{
 if (feerate<0)
  return false;
 _pakLotFee=feerate;
 return true;
}


bool CarSystem::SetSideWayFee(int feerate)
{
 if (feerate<0)
  return false;
 _sideWayFee=feerate;
 return true;
}


bool CarSystem::PakLotTest()const
{
// system("cls");
 cout<<"=================================================="<<endl;
 cout<<_pakLot<<endl<<endl<<_tempLot<<endl<<endl<<_sideWay<<endl<<endl;
 system("pause");
 return true;
}


bool CarSystem::GetMsg()
{
 while (1)
 {
  cin>>_msg._orderType;
  if (_msg._orderType=='E'||_msg._orderType=='e')
  {
   getline(cin,string());
   return true;
  }//if
  else if (_msg._orderType=='A'||_msg._orderType=='D')
  {
   getchar();
   cin>>_msg.car;
   return true;
  }//else if
  else
  {
   cout<<"Wrong Message,Please input again!"<<endl;
   continue;
  }//else
 }//while
 return true;
}//GetMsg


bool CarSystem::LoadMsg()
{
 ifstream fin(_readMsgFile.c_str());
 if (fin.fail())
 {
  cout<<"Open File "<<_readMsgFile<<" Error!"<<endl;
  exit(1);
 }//if
 Msg msg;
 MsgNodePtr pLink=_msgData;
 int errors=0;//错误信息计数器
 int count=0;//消息计数器
 while (!fin.eof())
 {
  fin>>msg._orderType;
  //此处加入注释过滤功能
  if (msg._orderType=='A'||msg._orderType=='D')
  {
   pLink->_next=new MsgNode;
   pLink=pLink->_next;
   pLink->_msg._orderType=msg._orderType;
   fin.ignore();
   fin>>pLink->_msg.car;
   pLink->_next=NULL;
  }//if
  else if (msg._orderType=='E')
  {
   pLink->_next=new MsgNode;
   pLink=pLink->_next;
   pLink->_msg._orderType=msg._orderType;
   fin.ignore(1);
   fin>>pLink->_msg.car;
   pLink->_msg.car._timeArr--;
   pLink->_next=NULL;
  }//else if
  else
  {
   cout<<++errors<<" Error MessageDatas!"<<endl;
   getline(fin,string());//忽略一行
  }//else
  count++;//计数器+1
 }//while
 fin.close();
 cout<<_msgData;
 system("pause");
 if (errors)
 {
  cout<<"共读取"<<setw(3)<<count<<" 条消息。"<<"无效消息共"<<setw(3)<<errors<<"条!"<<endl;
  cout<<"此数据源可能导致程序异常终止,建议检查数据正确性再测试。是否继续(Y/N)?"<<endl;
  char ans;
  cin>>ans;
  if (ans=='N'||ans=='n')
  {
   exit(1);
  }//if
 }//if
 return true;
}//LoadMsg


bool CarSystem::ProcessMsgData()
{
 MsgNodePtr pFront=_msgData,pSet=pFront->_next,pLink=pSet->_next;
 while (pFront->_next->_next!=NULL)
 {
  while (pLink!=NULL)
  {
   if (pLink->_msg.car._timeArr<pFront->_next->_msg.car._timeArr)
   {
    pSet->_next=pLink->_next;
    pLink->_next=pFront->_next;
    pFront->_next=pLink;
    pLink=pSet->_next;
   }//if
   else
   {
    pSet=pLink;
    pLink=pLink->_next;
   }//else
  }//while
  pFront=pFront->_next;
  pSet=pFront->_next;
  pLink=pSet->_next;
 }//while
 return true;
}//ProcessMsgData

bool CarSystem::MsgDataEmpty() const
{
 return _msgData->_next==NULL;
}

 

bool CarSystem::PeekMsg()
{
 if (MsgDataEmpty())
  return false;
 MsgNodePtr pLink=_msgData->_next;
 _msg._orderType=pLink->_msg._orderType;
 _msg.car=pLink->_msg.car;
 _msgData->_next=pLink->_next;
 delete pLink;
 pLink=NULL;
 return true;
}


bool CarSystem::CheckMsg()
{
 if (_msg._orderType=='A'||_msg._orderType=='D'||_msg._orderType=='E')
 {//命令正确
  if (!_msg.car._carNum.empty()&&_msg.car._carType>=0)
  {//车牌号,车型正确,到达时间有效
   return true;
  }//if
 }//if
 return false;
}//CheckMsg


bool CarSystem::SetCar()
{
 if (!_pakLot.Full())
 {//车场没满
  _msg.car._timeBgn=_sysTime;
  _pakLot.Push(_msg.car); 
 }//if
 else if (!_sideWay.Full())
 {
  _sideWay.EnQueue(_msg.car);
 }//else if
 else
 {
  cout<<"没有更多的停车空间!"<<endl;
  system("pause");//此处加入系统暂停设置~
  return false;
 }//else
 return true;
}


bool CarSystem::GetCar(CarNode &carMove)
{
 if (_pakLot.Find(_msg.car))
 {//在车场
  CarNode carMove=_pakLot.Pop();
  while (carMove._carNum!=_msg.car._carNum)//优化此处,繁琐的string对象比较
  {//开始找车
   _tempLot.Push(carMove);
   carMove=_pakLot.Pop();
  }//for
  //carMove是应出库车辆
  int fee=(carMove._timeBgn-carMove._timeArr)*_sideWayFee+(_sysTime-carMove._timeBgn)*_pakLotFee;//入库汽车应缴停车费用
  fee*=carMove._carType;//汽车类型的倍数
  _carLog.AddRecord(carMove,_sysTime,fee);
  while (!_tempLot.Empty())
  {                                 //数据测试
   carMove=_tempLot.Pop();
   _pakLot.Push(carMove);
  }//while                                 //数据测试
  CheckPakLot();                             //检测车场                                //数据测试
 }//if
 else if (_sideWay.Find(_msg.car))
 {//在便道                                                                             此处仍存在问题
  CarNode carMove=_sideWay.DeQueue(),setBack=_sideWay.GetReer();//setBack-->便道的车出来后,其他的车还原
  while (carMove._carNum!=_msg.car._carNum)   //修改此处判断
  {//开始找车
   _sideWay.EnQueue(carMove);
   carMove=_sideWay.DeQueue();
  }//while
  //carMove是应出库车辆
  int fee=(_sysTime-carMove._timeArr)*_sideWayFee;//便道汽车应缴停车费用
  fee*=carMove._carType;//汽车类型的倍数
  _carLog.AddRecord(carMove,_sysTime,fee);//加入日志文件
  carMove=_sideWay.DeQueue();
  //第一辆就是要找的车 这里更改
  while (carMove._carNum!=setBack._carNum)
  {
   _sideWay.EnQueue(carMove);
   carMove=_sideWay.DeQueue();
  }//while
  _sideWay.EnQueue(carMove);//找到尾部车辆,入队列
 }//else if
 else
 {
  cout<<"找不到车辆 "<<_msg.car._carNum<<"!   请检查输入信息!"<<endl;
  PakLotTest();            //用户侦错功能
  cout<<_msg;
  system("pause");
  return false;
 }//else
 return true;
}//GetCar

 

bool CarSystem::ProcessMsg()
{
 if (!CheckMsg())
  return false;
 switch (_msg._orderType)
 {
 case 'A':
  {
   //此处加入系统暂停设置
   SetCar();//汽车入库
   break;
  }//case 'A'
 case 'D':
  {
   CarNode carMove;
   GetCar(carMove);//_msg暂存用,之后会读入
   break;
  }
 case'E':
  {
   int fee;//存储每辆车应缴的费用
   while (!_pakLot.Empty())
   {//先入库的先记录
    _msg.car=_pakLot.Pop();
    _tempLot.Push(_msg.car);
   }//while
   while (!_tempLot.Empty())
   {
    _msg.car=_tempLot.Pop();
    fee=(_msg.car._timeBgn-_msg.car._timeArr)*_sideWayFee+(_sysTime-_msg.car._timeBgn)*_pakLotFee;//入库汽车应缴停车费用
    fee*=_msg.car._carType;//汽车类型的倍数
    _carLog.AddRecord(_msg.car,_sysTime,fee);//车场的车清空,收费
   }//while
   while (!_sideWay.Empty())
   {
    _msg.car=_sideWay.DeQueue();
    fee=(_sysTime-_msg.car._timeArr)*_sideWayFee;//便道汽车应缴停车费用
    fee*=_msg.car._carType;//汽车类型的倍数
    _carLog.AddRecord(_msg.car,_sysTime,fee);//加入日志文件
   }//while
   break;
  }//case 'E'
 }//switch
 return true;
}//ProcessMsg


bool CarSystem::CheckPakLot()
{
 while (!_pakLot.Full()&&!_sideWay.Empty())
 {
  CarNode carMove=_sideWay.DeQueue();
  carMove._timeBgn=_sysTime;//入库时间
  _pakLot.Push(carMove);
 }//while
 return true;
}//CheckPakLot


bool CarSystem::AutoDriveEvent()
{
 bool finished=false;
 if (LoadMsg())
 {
  ProcessMsgData();      //处理消息区,按时间顺序排序
  if (!PeekMsg())
   return false;
  while (!finished)
  {
   _sysTime++;//系统总时间
   if (_msg.car._timeArr<=_sysTime||_msg._orderType=='E')
   {
    ProcessMsg();
    if (!PeekMsg())
     finished=true;
   }//if
   //删除了车场情况检测
   system("cls");
   cout<<"  ---------------------------------------------------------------------------- "<<endl;
   cout<<" |                · 停 · 车 · 场 · 管 · 理 · 系 · 统 ·                |"<<endl;
   cout<<"  ---------------------------------------------------------------------------- "<<endl;
   cout<<"                                           · 系 统 时 间 ·  "<<_sysTime<<"   "<<endl;
   cout<<_carLog;                           //自启动输出系统日志
  }//while
  SaveLogs();
  cout<<"     ◎◎"<<"车场容量:"<<setw(3)<<_pakLot.StackCapacity()<<"       剩余容量:"<<setw(3)
   <<_pakLot.StackCapacity()-_pakLot.StackSize()<<"       车辆数量:"<<setw(3)<<_pakLot.StackSum()<<endl
   <<"     ◎◎便道容量:"<<setw(3)<<_sideWay.QueueCapacity()<<"       剩余容量:"<<setw(3)
   <<_sideWay.QueueCapacity()-_sideWay.QueueSize()<<"       车辆数量:"<<setw(3)<<_sideWay.QueueSum()<<endl;
  //关闭系统;
  _sysTime.SetTime(0,0);
  _pakLot.Clear();
  _tempLot.Clear();
  _sideWay.Clear();
  _carLog.Clear();
  cout<<"     ◎◎"<<"系统已关闭!"
   <<"                       ◎";
  system("pause");
  return true;
 }
 cout<<"System Error!"<<endl;
 return false;
}

bool CarSystem::SaveLogs()
{//修改输出格式
 ofstream fout(_saveLogFile.c_str());
 if (fout.fail())
 {
  cout<<"Open File "<<_saveLogFile<<" Failed!"<<endl;
  exit(1);
 }
 fout<<endl<<"                                    -----停车场系统日志-----                 "<<endl<<endl;
 fout<<"  序号/t/t  车牌号/t/t/t       到达时间/t/t/t      离开时间/t/t    计费时间/t/t     费用 "<<endl;
 fout<<"-----------------------------------------------------------------------------------------"<<endl;
 LogNodePtr pLink=_carLog.GetFront()->_next;
 int count=0;
 while (pLink!=NULL)
 {
  fout<<"/t"<<setw(3)<<++count<<"/t      "<<setw(6)<<pLink->_carNum<<"/t        "<<setw(5)<<pLink->_arrTime
   <<"/t             "<<pLink->_lveTime<<"/t          "<<setw(4)<<pLink->_minute<<"/t         "<<setw(4)<<pLink->_fee<<endl;
  pLink=pLink->_next;
 }
 fout<<"-----------------------------------------------------------------------------------------"<<endl;
 fout<<endl<<"总运行时间:/t/t"<<_sysTime<<endl;
 fout.close();
 return true;
}

 

ostream& operator<<(ostream& out,Msg& msg)
{
 out<<msg._orderType<<"/t"<<msg.car;
 return out;
}


ostream& operator<<(ostream& out,MsgNodePtr msgData)
{
 int count=0;
 MsgNodePtr pLink=msgData->_next;
 while (pLink!=NULL)
 {
  ++count;
  out<<pLink->_msg<<endl;
  pLink=pLink->_next;
 }
 cout<<"Totally "<<count<<" Message!"<<endl;
 return out;
}

 


//
//界面显示部分
//


bool CarSystem::PutPakLotInfo()const
{
 system("cls");
 cout<<"         -------------------------------------------------------------- "<<endl;
 cout<<"        |          · 停 · 车 · 场 · 管 · 理 · 系 · 统 ·        |"<<endl;
 cout<<"         -------------------------------------------------------------- "<<endl;
 cout<<"                                       · 系 统 时 间 ·  "<<_sysTime<<"   "<<endl;
 cout<<"         -------------------------------------------------------------- "<<endl;
 cout<<"        |                   · 车 · 库 · 详 · 情 ·                 |"<<endl;
 cout<<"        | 序号      车牌号        到达时间       已停时间        费用  |"<<endl;
 cout<<"         -------------------------------------------------------------- "<<endl;
 cout<<"        |                                                              |"<<endl;
 int count=0;
 CarNodePtr pBase=_pakLot.GetBase();
 int sum=_pakLot.StackSum();
 int minute=0;
 while (sum!=0)
 {
  minute=-(pBase->_timeArr-_sysTime);
  cout<<"        | "<<setw(3)<<++count<<"       "<<setw(6)<<pBase->_carNum<<"      "<<setw(5)<<pBase->_timeArr
   <<"           "<<setw(4)<<minute<<"          "<<setw(4)<<minute*_pakLotFee<<" |"<<endl;
  pBase++;
  sum--;
 }
 cout<<"        |                                                              |"<<endl;
 cout<<"         -------------------------------------------------------------- "<<endl;
 cout<<endl;
 cout<<"          ◎共停车辆:"<<setw(3)<<count<<"            ◎车场容量:"<<setw(3)<<_pakLot.StackCapacity()<<endl<<endl;
 cout<<"        ◎◎";
 system("pause");
 return true;
}


bool CarSystem::PutSideWayInfo() const
{
 system("cls");
 cout<<"         -------------------------------------------------------------- "<<endl;
 cout<<"        |          · 停 · 车 · 场 · 管 · 理 · 系 · 统 ·        |"<<endl;
 cout<<"         -------------------------------------------------------------- "<<endl;
 cout<<"                                       · 系 统 时 间 ·  "<<_sysTime<<"   "<<endl;
 cout<<"         -------------------------------------------------------------- "<<endl;
 cout<<"        |                   · 便 · 道 · 详 · 情 ·                 |"<<endl;
 cout<<"        | 序号      车牌号        到达时间       已停时间        费用  |"<<endl;
 cout<<"         -------------------------------------------------------------- "<<endl;
 cout<<"        |                                                              |"<<endl;
 int count=0;
 CarNodePtr pBase=_sideWay.GetBase();
 int sum=_sideWay.QueueSum();
 int minute=0;
 while (sum!=0)
 {
  minute=-(pBase->_timeArr-_sysTime);           //掉转两个时间出现错误
  cout<<"        | "<<setw(3)<<++count<<"       "<<setw(6)<<pBase->_carNum<<"       "<<setw(5)<<pBase->_timeArr
   <<"           "<<setw(4)<<minute<<"         "<<setw(4)<<minute*_pakLotFee<<"  |"<<endl;
  pBase++;
  sum--;
 }
 cout<<"        |                                                              |"<<endl;
 cout<<"         -------------------------------------------------------------- "<<endl;
 cout<<endl;
 cout<<"          ◎共停车辆:"<<setw(3)<<count<<"            ◎便道容量:"<<setw(3)<<_sideWay.QueueCapacity()<<endl<<endl;
 cout<<"        ◎◎";
 system("pause");
 return true;
}

 


bool CarSystem::StartSystem()
{
 int _exit=false;
 int number;
 while (!_exit)
 {
  system("cls");
  cout<<"      --------------------------------------------------------------------" <<endl;
  cout<<"     |             · 停 · 车 · 场 · 管 · 理 · 系 · 统 ·           |"<<endl;
  cout<<"      --------------------------------------------------------------------" <<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |                       · 欢 · 迎 · 使 · 用 ·                   |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |            1.人 工 启 动                    2.自 动 测 试          |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |            3.参 数 设 置                    4.查 看 帮 助          |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |                            0. 退 出 系 统                          |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |                       · 暨 · 南 · 大 · 学 ·                   |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"      -------------------------------------------------------------------- "<<endl;
  cout<<endl;
  cout<<"          ◎请输入菜单选项-->";
  cin>>number;
  switch (number)
  {
  case 1:
   {
    DriveEvent();
    break;
   }
  case 2:
   {
    AutoDriveEvent();
    break;
   }
  case 3:
   {
    SetParametor();
    break;
   }
  case 4:
   {
    HelpFile();
    break;
   }
  case 0:
   {
    _exit=true;
    cout<<endl<<endl<<"        ◎◎感谢使用!";
    break;
   }
  default:
   {
    cout<<"输入有误,请重新输入!"<<endl;
    cin.ignore(100);
    system("pause");
    break;
   }
  }
 }
 return true;
}

 

bool CarSystem::DriveEvent()
{
 bool _exit=false,_useful=false;
 char order;
 while (!_exit)
 {
  system("cls");
  cout<<"      -------------------------------------------------------------------- "<<endl;
  cout<<"     |              · 停 · 车 · 场 · 管 · 理 · 系 · 统 ·          |"<<endl;
  cout<<"      -------------------------------------------------------------------- "<<endl;
  cout<<"                                         · 系 统 时 间 ·  "<<_sysTime<<endl;
  cout<<"      -------------------------------------------------------------------- "<<endl;
  cout<<"     |                       · 人 · 工 · 启 · 动 ·                   |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |            1.使 用 说 明                    2.查 看 车 库          |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |            3.查 看 便 道                    4.查 看 日 志          |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |            5.输 入 命 令                    6.关 闭 系 统          |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |                              0.退 出 系 统                         |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |                       · 暨 · 南 · 大 · 学 ·                   |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"      -------------------------------------------------------------------- "<<endl;
  cout<<endl;
  cout<<"          ◎请输入菜单选项-->";
  cin>>order;
  switch (order)
  {
  case '1':
   {//使用说明
    _useful=UseSystemHelp();
    break;
   }//case 1
  case '2':
   {//查看车场
    if (!_useful)
    {
     cout<<endl<<"        ◎◎"<<"请先阅读使用说明!"<<endl;
     system("pause");
     break;
    }//if
    PutPakLotInfo();
    break;
   }//case 2
  case '3':
   {//查看便道
    if (!_useful)
    {
     cout<<"请先阅读使用说明!"<<endl;
     system("pause");
     break;
    }//if
    PutSideWayInfo();
    break;
   }//case 3
  case '4':
   {//查看日志
    if (!_useful)
    {
     cout<<"请先阅读使用说明!"<<endl;
     system("pause");
     break;
    }//if
    system("cls");
    cout<<_carLog;
    system("pause");
    break;
   }//case 4
  case '5':
   {//输入命令
    cout<<endl<<"       ◎请输入控制命令:";
    GetMsg();
    while (_sysTime<_msg.car._timeArr)
    {
     CheckPakLot();
     _sysTime++;
    }//while
    ProcessMsg();
    break;
   }//case 5
  case '6':
   {//关闭系统   此处修改
    return true;
    break;
   }//case 6
  case '0':
   {//退出系统
    cout<<endl<<endl<<"        ◎◎感谢使用!";
    exit(1);
    break;
   }//case 0
  default:
   {//错误输入
    cout<<"       ◎输入有误,请重新输入!"<<endl;
    system("pause");
    break;
   }//default
  }//switch
 }//while
 return true;
}//DriveEvent


bool CarSystem::ParaHelp()
{
 system("cls");
 cout<<"      --------------------------------------------------------------------- "<<endl;
 cout<<"     |               · 停 · 车 · 场 · 管 · 理 · 系 · 统 ·          |"<<endl;
 cout<<"      --------------------------------------------------------------------- "<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"     |                       · 参 · 数 · 说 · 明 ·                    |"<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"     |      1. <系统初始时间>即系统启动时间,默认00:00启动。              |"<<endl;
 cout<<"     |      2. <收费标准>分为车场收费标准与便道收费标准,即停便道收费      |"<<endl;
 cout<<"     |         标准与车场不同,停在不同地方的总收费由两部分费用相加。      |"<<endl;
 cout<<"     |      3. <车场容量>即车场占地面积,与所能容纳车辆多少相关。          |"<<endl;
 cout<<"     |      4. <便道容量>即便道占地面积,车场停满之后会停在便道。          |"<<endl;
 cout<<"     |      5. <消息预存文档>自动启动系统时,需要先预读所有控制命令,      |"<<endl;
 cout<<"     |         这个是控制命令的存放位置,默认与程序路径相同,文件名为      |"<<endl;
 cout<<"     |         “msg.txt”(不包含引号)。命令存放一行一条,文件结尾以       |"<<endl;
 cout<<"     |         <E,000000,0,00:00>结束。                                    |"<<endl;
 cout<<"     |      6. <日志保存文档>程序运行的所有数据将以系统日志方式保存,      |"<<endl;
 cout<<"     |         默认保存在与程序路径相同,文件名为”SystemLogs.txt“的      |"<<endl;
 cout<<"     |         文档中。(不包含引号)。                                      |"<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"     |                         · 按 任 意 键 返 回 ·                     |"<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"     |                       · 暨 · 南 · 大 · 学 ·                    |"<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"      --------------------------------------------------------------------- "<<endl;
 cout<<"/t◎";
 system("pause");
 return true;

}


bool CarSystem::SetParametor()
{
 bool _back=false;
 int number;
 while (!_back)
 {
  //系统时间,车场容量,便道容量,日志文档,消息数据区文档,收费标准
  system("cls");
  cout<<"      -------------------------------------------------------------------- "<<endl;
  cout<<"     |             · 停 · 车 · 场 · 管 · 理 · 系 · 统 ·           |"<<endl;
  cout<<"      -------------------------------------------------------------------- "<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |                       · 参 · 数 · 设 · 置 ·                   |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |                             1.参 数 说 明                          |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |        2.系 统 初 始 时 间                3.收 费 标 准            |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |        4.车 场 容 量                      5.便 道 容 量            |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |        6.消 息 预 存 文 档                7.日 志 保 存 文 档      |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |                             0.返 回 上 层                          |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"     |                       · 暨 · 南 · 大 · 学 ·                   |"<<endl;
  cout<<"     |                                                                    |"<<endl;
  cout<<"      -------------------------------------------------------------------- "<<endl;
  cout<<endl;
  cout<<"          ◎请输入菜单选项-->";
  cin>>number;
  cout<<endl;
  switch (number)
  {
  case 1:
   {//参数设置说明
    ParaHelp();
    break;
   }//case 1
  case 2:
   {//系统初始时间设置
    cout<<"        ◎◎请输入新系统时间-->";
    cin>>_sysTime;
    cout<<"        ◎◎新系统时间设置成功:"<<_sysTime<<endl<<"/t◎";
    system("pause");
    break;
   }//case 2
  case 3:
   {//收费标准设置
    int pakLotFee=0,sideWayFee=0;
    cout<<"        ◎◎请输入新 停车场 收费标准-->";
    cin>>pakLotFee;
    cout<<"        ◎◎请输入新 便  道 收费标准-->";
    cin>>sideWayFee;
    if (SetPakLotFee(pakLotFee)&&SetSideWayFee(sideWayFee))
    {
     cout<<"        ◎◎新收费标准设置成功!停车场收费标准:"<<setw(2)
      <<_pakLotFee<<"/t便道收费标准:"<<setw(2)<<_sideWayFee<<endl<<"/t◎";
     system("pause");
    }//if
    else
    {
     cout<<"        ¤¤新收费标准设置失败!请重新设置。"<<endl<<"/t◎";
     system("pause");
     break;
    }//else
   }//case 3
  case 4:
   {//车场容量设置
    int capacity=0;
    cout<<"        ◎◎请输入新车场容量-->";
    cin>>capacity;
    if (capacity==0)
    {//车场容量不能设置为0
     cout<<"停车场容量不能设置为0!请重新设置!"<<endl;
     break;
    }//if
    if (_pakLot.ReSetStack(capacity)&&_tempLot.ReSetStack(capacity))
    {
     cout<<"        ◎◎新车场容量设置成功:"<<capacity<<endl<<"/t◎";
     system("pause");
     break;
    }//if
    else
    {
     cout<<"        ¤¤新车场容量设置失败!请重新设置。"<<endl<<"/t◎";
     system("pause");
     break;
    }//else
   }//
  case 5:
   {//便道容量设置
    int capacity=0;
    cout<<"        ◎◎请输入新便道容量-->";
    cin>>capacity;
    if (_sideWay.ReSetQueue(capacity))
    {
     cout<<"        ◎◎新便道容量设置成功:"<<capacity<<endl<<"/t◎";
     system("pause");
     break;
    }//if
    else
    {
     cout<<"        ¤¤新便道容量设置失败!请重新设置。"<<endl<<"/t◎";
     system("pause");
     break;
    }//else
   }// case 5
  case 6:
   {//消息命令文档路径设置
    cout<<"        ◎◎请输入新消息命令文档路径-->";
    cin>>_readMsgFile;
    if (_readMsgFile.empty())
    {
     cout<<"        ◎◎新消息命令文档路径设置成功:"<<_readMsgFile<<endl<<"/t◎";
     system("pause");
     break;
    }//if
    else
    {
     cout<<"        ◎◎新消息命令文档路径设置失败!请重新设置。"<<endl<<"/t◎";
     system("pause");
     break;
    }//if
   }//case 6
  case 7:
   {//日志保存文档路径设置
    cout<<"        ◎◎请输入新消息命令文档路径-->";
    cin>>_saveLogFile;
    if (_saveLogFile.empty())
    {
     cout<<"        ◎◎新消息命令文档路径设置成功:"<<_saveLogFile<<endl<<"/t◎";
     system("pause");
     break;
    }//if
    else
    {
     cout<<"        ◎◎新消息命令文档路径设置失败!请重新设置。"<<endl<<"/t◎";
     system("pause");
     break;
    }//else
   }//case 7
  case 0:
   {//返回上层
    _back=true;
    break;
   }//case 0
  default:
   {//输入错误
    cout<<"       ◎输入有误,请重新输入!";
    system("pause");
    break;
   }//default
  }//switch
 }//while
 return true;
}//SetParametor

 

bool CarSystem::UseSystemHelp()
{
 system("cls");
 cout<<"      --------------------------------------------------------------------- "<<endl;
 cout<<"     |              · 停 · 车 · 场 · 管 · 理 · 系 · 统 ·           |"<<endl;
 cout<<"      --------------------------------------------------------------------- "<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"     |                        · 使 · 用 · 说 · 明 ·                   |"<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"     |                  系统启动后,请按照如下格式输入系统命令             |"<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"     |      1. 命令类型,汽车车牌号,当前时间  例如:A,C07418,1,08:00      |"<<endl;
 cout<<"     |      2. 命令类型分三种-->   A-汽车到达,D-汽车离开,E-关闭系统      |"<<endl;
 cout<<"     |      3. 汽车车牌号应该是6位-->C07418,CT1259,80C57Z等均可。但是      |"<<endl;
 cout<<"     |         汽车离开的命令会检查是否存在汽车,若车牌号错误会导致系      |"<<endl;
 cout<<"     |         统中断,甚至出错(由于时间关系,未优化此处)。因此,键入      |"<<endl;
 cout<<"     |         命令时请慎重。                                              |"<<endl;
 cout<<"     |      4. 介于车牌与时间中的数字表示车辆类型,也相当于即车辆占地      |"<<endl;
 cout<<"     |         面积大小,1表示占一个车位大小,2表示两个车位大小,这与      |"<<endl;
 cout<<"     |         车场容量大小直接相关。                                      |"<<endl;
 cout<<"     |      5. 小时分钟均为两位中间以冒号相隔,且不能小于当前系统时间      |"<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"     |                          · 按 任 意 键 返 回 ·                    |"<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"     |                        · 暨 · 南 · 大 · 学 ·                   |"<<endl;
 cout<<"     |                                                                     |"<<endl;
 cout<<"      --------------------------------------------------------------------- "<<endl;
 cout<<"/t◎";
 system("pause");
 return true;
}


bool CarSystem::HelpFile()
{
 system("cls");
 cout<<"      -------------------------------------------------------------------- "<<endl;
 cout<<"     |             · 停 · 车 · 场 · 管 · 理 · 系 · 统 ·           |"<<endl;
 cout<<"      -------------------------------------------------------------------- "<<endl;
 cout<<"     |                                                                    |"<<endl;
 cout<<"     |                       · 说 · 明 · 文 · 档 ·                   |"<<endl;
 cout<<"     |                                                                    |"<<endl;
 cout<<"     |        本程序以两个栈结构(顺序栈)与一个队列(顺序队列)结构实现了停  |"<<endl;
 cout<<"     |    车场的管理问题,实现不够完美,有待改进。下是具体使用方法:      |"<<endl;
 cout<<"     |                                                                    |"<<endl;
 cout<<"     |   1. 人工启动-->用于人工输入命令控制停车场系统,详情见使用说明     |"<<endl;
 cout<<"     |   2. 自动启动-->用于处理预先保存的命令集文档,自动处理完成,并保存 |"<<endl;
 cout<<"     |      相应的日志文档,以供检测。                                    |"<<endl;
 cout<<"     |   3. 参数设置-->包含诸多程序参数的修改,详情见参数设置             |"<<endl;
 cout<<"     |   4. 程序使用C++,包含5个类[Time,Stack,Queue,SystemLog,CarSystem]  |"<<endl;
 cout<<"     |      均为简单类,实现单一。不包含虚函数,继承,多态。              |"<<endl;
 cout<<"     |                                                                    |"<<endl;
 cout<<"     |                         · 按 任 意 键 返 回 ·                    |"<<endl;
 cout<<"     |                                                                    |"<<endl;
 cout<<"     |                       · 暨 · 南 · 大 · 学 ·                   |"<<endl;
 cout<<"     |                                                                    |"<<endl;
 cout<<"      -------------------------------------------------------------------- "<<endl;
 cout<<"/t◎";
 system("pause");
 return true;
}

---------------------------------------------------------------------------------------------------------------------------------------

 

 

 

//经过测试,发现许多问题的存在,具体如下:

-------------------------------------------------------

停车场管理系统BUG问题以及优化问题总结:

>>人工启动中对错误命令的处理
>>日志文件输出格式优化
>>系统关闭之后的数据清除问题
>>车库栈与临时栈共享内存空间
>>收费由按分钟收费改为按小时收费,不足1小时的按一小时计算(变量类型要改)
>>车场便道都满了的情况,则先处理D类消息。优化ProcessMsg()函数
>>三个时间的处理。到达时间,入库时间,离开时间    OK
>>便道上的车离开后,其他的车要不要还原
>>返回的结构体或者对象类型改成引用参数返回
>>自动读入之后不要自动关闭系统,让用户选择是否关闭系统
>>添加功能:文档中允许加入注释
>>优化CarSystem.cpp 235行的比较     OK
>>输出停留时间出错         OK
>>在便道找到车辆之后的车辆归位优化(考虑设计成输出受阻双端队列)
>>数据读入的正确性检测优化(到达的车辆一定比没到达的车辆多)
>>参数设置中,新参数的正确性问题

 

 

-----------------------------------------------------------------------------------------------

由于设置了格式化,以及对程序总体把握和知识水平有限的原因,造成代码冗余,存在许多无用代码。有待日后进一步修改.......

如有朋友愿意指点一二,请留言,有不明白的我能指出是什么意思,有错误请大虾指正.......

 

 

下面附上测试数据:

//------------msg.txt-------------

A,D02658,1,00:39
A,C3483T,2,00:56
A,A00000,1,01:00
D,D02658,1,01:01
A,A05326,2,01:30
A,D88888,2,02:00
D,A00000,1,02:20
A,C80369,1,03:45
D,A05326,2,04:00
A,F05236,1,04:04
D,D88888,2,04:12
A,KT1205,3,04:55
A,JM125B,3,05:00
D,C80369,1,05:23
D,C3483T,2,06:00
A,JK8888,3,06:00
D,KT1205,1,07:00
E,000000,0,00:00

 

 

 

-----------------------------------------

下面截图是测试结果。

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值