问题描述:
//=================================
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
//=================================
using namespace std;
//=================================
//用于对汽车信息的记录
typedef struct{
string license_plate;
char state; //汽车当前状态,字符s表示停放在停车位上,
}CAR;
CAR *Car=new CAR;
//用于停车位
#define MAX_STOP 5
typedef struct{
CAR STOP[MAX_STOP]; //各汽车信息的存储空间
int top; //用来指示栈顶位置的静态指针
}STOPPING;
STOPPING *stopping=new STOPPING;
//====================================================================
//用于辅助栈
typedef struct
{
CAR _BUFFER[MAX_STOP];
int top;
}BUFFER;
BUFFER *buffer=new BUFFER;
//=====================================================================
void come()
{
int i=-1;
if(stopping->top!=MAX_STOP-1)
{
stopping->top++;
i++;
cout<<"输入车牌号"<<endl;
cin>>stopping->STOP[i].license_plate;
cout<<"车牌号为 "<<stopping->STOP[i].license_plate<<"进入"<<endl;
}
else
cout<<"满了"<<endl;
}
//=====================================================================
void leave(){
if(stopping->top!=-1)
{
cout<<"输入车牌号"<<endl;
cin>>Car->license_plate;
for(int i=stopping->top;i>=0;i--)
{
if(stopping->STOP[i].license_plate=Car->license_plate)
break;
}
int m=i;
//=======================移入辅助栈=======================================================
int j=-1;
for( int k=stopping->top;(buffer->top!=MAX_STOP-1)&&(k>=m);k--)
{
buffer->top++;
j++;
buffer->_BUFFER[j].license_plate=stopping->STOP[i].license_plate;
stopping->top--;
i--;
}
j=j-1;
//======================移入栈===========================================================
for(int n=stopping->top;buffer->top!=MAX_STOP-1;n++)
{
stopping->top++;
i++;
stopping->STOP[i].license_plate=buffer->_BUFFER[j].license_plate;
buffer->top--;
j--;
}
cout<<"车牌号为 "<<stopping->STOP[i].license_plate<<"出去"<<endl;
}
else
cout<<"空了"<<endl;
}
int main(int argc, char* argv[]){
cout<<setw(45)<<"欢迎使用本程序"<<endl;
cout<<"本程序为停车场的模拟管理程序,有车到来时请按[c]键。"<<endl;
cout<<"然后根据屏幕提示进行相关操作,有车要走时请按[l]键。"<<endl;
cout<<"然后根据屏幕提示进行相关操作,查看停车状态按[p]键。"<<endl;
cout<<"然后根据屏幕提示进行相关操作,要退出程序请按[q]键。"<<endl;
stopping->top=-1;
buffer->top=-1;
for(;;){
cout<<"请选择您要做的操作!"<<endl;
char k;
k=getchar(); //接收功能字符
if(k=='q')break; //q退出程序
switch(k)
{
case 'c':come();break;
case 'l':leave();break;
default:cout<<"输入错误!"<<endl;
break;
}
getchar();
}
return 0;
}
最好改一下 ,让我运行啊!!!
问题解答:
都改成char name[255]好了
cstring最好少用
string 都改为CString