C++ C++;使用STL:堆栈和队列

C++ C++;使用STL:堆栈和队列,c++,stl,stack,queue,C++,Stl,Stack,Queue,我的作业是: 一天的数据集在头等舱的lot.txt文件中提供 到达/离开代码:字符(A或D)许可证字符串(例如BOSS) 表示军事时间的时间整数值 早起的鸟630工人700首席执行官730职员730经理800 副总裁900 D职员930 A购物者1000 D首席执行官1000 D EARLYBIRD 1030 D 工人1100 A门卫1100 D经理1130 应将车辆记录为包含许可证和 到达时间。为了简单起见,时间将是一个整数 代表军事时间。包含C++字符串类。 结构车辆{string lice

我的作业是:

一天的数据集在头等舱的lot.txt文件中提供

到达/离开代码:字符(A或D)许可证字符串(例如BOSS) 表示军事时间的时间整数值

早起的鸟630工人700首席执行官730职员730经理800 副总裁900 D职员930 A购物者1000 D首席执行官1000 D EARLYBIRD 1030 D 工人1100 A门卫1100 D经理1130

应将车辆记录为包含许可证和 到达时间。为了简单起见,时间将是一个整数 代表军事时间。包含C++字符串类。 结构车辆{string license;//许可证值int 到达;//在军事时间到达(0-2359)}

读入数据文件的行并重新创建汽车的运动 进出停车场。车辆每小时收费8美元 在他们逗留期间。部分时间是四舍五入的。你 我们可以假设,只有停车场中的车主离开时才到达 要求在当天结束时报告停车场中的任何车辆以及 费用总额。使用讨论过的模板堆栈和队列类 在演讲中

对于每次处理的到达,您应报告:有xxxxxx许可证的车辆 停在xxxx或有xxxxxx许可证的车辆在xxxx被拒绝- 满了

对于处理的每次离境,您应报告:有驾照的汽车 xxxxxx于XXXXX离开,支付$xx.xx

当一辆汽车开走时,我在这方面遇到了麻烦。我不太熟悉堆栈和队列,但据我所知,堆栈是后进先出,队列是先进先出

以下是我所拥有的:

    struct Vehicle
    {
        char ad; // Arrival departure char
        string license; // license value
        int arrival; // arrival in military time
    };

    int main()
    {
        ifstream  fin;          // declare input file stream object 
        fin.open ("lot.txt");  //open data text
        stack<string> stack; // STL Stack object
        queue<string> q; // STL Queue object

        Vehicle v; // Object of struct Vehicle

        while(!fin.fail()){
            fin >> v.ad >> v.license >> v.arrival;
            if (v.ad == 'A' && stack.size() < 5){
                stack.push(v.license);
                cout << endl << "Car with license " << v.license << " parked at " << v.arrival;
            }else if(v.ad == 'A' && stack.size() >= 5){
                cout << endl << "Car with license " << v.license << " turned away at " << v.arrival << " - LOT FULL";
            }else if(v.ad == 'D'){
                string departingcar = v.license;

                for(int i=0; i<stack.size(); i++)
//am I on the right track with a for loop?
                    q.push(v.license);
                    stack.pop();
                    q.pop();
                    if(departingcar != v.license){
                        stack.push(v.license);
                    }
                }

            }
        }
        return 0;
    }
struct车辆
{
char ad;//到达/离开字符
字符串许可证;//许可证值
int到达;//军事时间到达
};
int main()
{
ifstream fin;//声明输入文件流对象
fin.open(“lot.txt”);//打开数据文本
堆栈;//STL堆栈对象
队列q;//STL队列对象
车辆v;//结构车辆的对象
而(!fin.fail()){
fin>>v.ad>>v.license>>v.arrival;
if(v.ad='A'&&stack.size()<5){
stack.push(v.license);

cout当前,for循环没有真正意义,因为在向队列添加内容之后,您也会弹出前面的元素,因为您从未将其保存到其他任何地方,所以它将永远丢失

我假设您要做的是找到插入堆栈中的汽车并将其移除。如果是,请执行以下操作:

string departingcar = v.license;

//find and remove the license plate from the stack
for(int i=0; i<stack.size(); i++)
{
    if (departingcar != stack.top())
    {
        q.push(stack.top());
        stack.pop();
    }
    else
    {
        stack.pop();
        break;
    }  
 }

 //put the remaining cars back in the stack and empty out the queue
 while(!q.empty())
 {
    stack.push(q.front());
    q.pop();
 }
字符串出发车=v.license;
//查找并从堆栈中删除牌照

对于(inti=0;我知道你的教授真的用了
lol.txt
这样的名字吗?