Stacks Program (Parking Lot) utilizing vector class

Well I'm currently working on a Stacks program using the vector class. The program operates for a parking lot business whereby it enters license plate numbers of income cars into the stack, while that is done, a ticket number (Id) is provided.

The situation is when a customer wants to cash out, the ticket Id is provided and the program removes license plates stored at the top of the stack until the id matches for that corresponding license plate and stored in a new stack. I stumble on the issue of removing the license plate number checking out and restoring back the other elements into the original stack with its corresponding Id number. Can anyone help me?

Please and thanks in advance.

Here's the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

class CarStack
{
   private:

   int maxSize;
   vector <double> stackVect, stackVector;
   int top;

   public:
   //-------------------------------------------------
   CarStack(int size) : maxSize (size), top(-1) //constructor
   {
       stackVect.reserve(maxSize); //size of vector
   }
   //-------------------------------------------------
   void push(double j) //inserting item on top
   {
       if (isFull())
       {
           cout<<"Database is FULL!. "<<j<<" could not be inserted! \n";
           return;
       }
       stackVect [++top] = j;
       cout<<j<<" has been inserted. \n";
   } //inserting item ending
   //-------------------------------------------------
   double pop()
   {
       int temp;
       if (isEmpty())
       {
           cout<<"Database is EMPTY."<<endl;
           return false;
       }

       temp=stackVect[top];
       cout<<temp;
       return stackVect[top];
   }
   //-------------------------------------------------
   double peek()
   {
       int temp;
       if (isEmpty())
       {
           cout<<"Database is EMPTY."<<endl;
           return false;
       }

       temp=stackVect[top];
       cout<<temp;
       return stackVect[top];
   }
   //-------------------------------------------------
   bool isEmpty()
   {
       return (top== -1);
   }
   //-------------------------------------------------
   bool isFull()
   {
       return (top == maxSize-1);
   }
   //-------------------------------------------------
   void showmenu()
    {
    cout<<"Please select one of the following to continue \n"
        <<"1. Adding Cars into Database  \n"
        <<"2. Delete a Car from the Database \n"
        <<"3. PEEKING the car that was entered most recently \n"
        <<"4. Quiting the program \n";
    }
   //-------------------------------------------------
};

class Carreplace
{
    private:
    int maxSize;
    vector <double> stackVect, stackVector;
    int top;

    public:
   //-------------------------------------------------
   Carreplace(int size1) : maxSize(size1), top(-1) //constructor
   {
       stackVect.reserve(maxSize); //size of vector
   }
   //-------------------------------------------------
   void push(double m) //inserting item on top
   {
       if (isFull())
       {
           return;
       }
       stackVect [++top] = m;

   } //inserting item ending
   //-------------------------------------------------
   double pop()
   {
       int temp;
       if (isEmpty())
       {
           return false;
       }

       temp=stackVect[top];
       cout<<temp;
       return stackVect[top];
   }
   //-------------------------------------------------
   double peek()
   {
       int temp;
       if (isEmpty())
       {
           return false;
       }

       temp=stackVect[top];
       cout<<temp;
       return stackVect[top];
   }
   //-------------------------------------------------
   bool isEmpty()
   {
       return (top== -1);
   }
   //-------------------------------------------------
   bool isFull()
   {
       return (top == maxSize-1);
   }
   //-------------------------------------------------
};

int main()
{
     int num = 0;
     int id = 0;
     int x;
     int ticketnumber;
     int choice, element, nElem;
     cout<<"Welcome to the Parking Lot Manager Program \n";
     cout<<"Let's begin by entering the number of cars that will be added into the database for today \n"
         <<"    Note if no value is entered, the initial amount of cars that can be stored will be a 100 \n";
         cin>>num;
         if(num == 0)
         {
             cout<<"Let's begin with a 100 slots to store cars \n"<<endl;
             num = 100;
         }
         CarStack theStack(num); //make new stack, size specified by user
         Carreplace theStack1(100); //making new stack in background, size initialized
         theStack.showmenu();
         cin>>choice;
         while (choice != 4)
        {
            switch (choice)
            {
                case 1: //Inserting into STACK
                    cout<<"How much cars are being parked today? \n";
                    cin>>nElem;
                    for (int j=0; j<nElem; j++)
                    {
                        cout<<"Please enter the numbers below one by one \n";
                        cin>>element;
                        theStack.push(element);
                        id++;
                        cout<<"The ticket number for that car is "<<id<<endl;
                        cout<<endl;
                    }
                    theStack.showmenu();
                    cin>>choice;
                break;

                case 2: //Deleting elements in the STACK
                    cout<<"Please provide the ticket number of the customer that will be checking out \n";
                    cin>>ticketnumber;
                    while (ticketnumber != id)
                    {
                        cout<<"Locating license plate number of car for the ticket number provided \n";
                        theStack.pop();
                        id--;
                        x = theStock.pop();
                        theStack1.push(x);
                        cout<<"The license plate number of the car has been located \n Printing reciept for customer \n"<<endl;
                        cout<<"Please wait... \n    Doing a little housekeepiing \n"
                    }
                    theStock.pop();
                    //theStack1.pop();    
                    theStack.showmenu(); //Here's where the tricky part is
                    cin>>choice;
                break;

                case 3: //Peeking first element of STACK
                    cout<<"To view element on top of stack press #1 \n";
                    int input;
                    cin>>input;
                    while (input == 1)
                    {
                        cout<<"The element is ";
                        theStack.peek();
                        cout<<endl;
                        cout<<"To view element on top once more press the #1 \n";
                        cin>>input;
                    }
                    theStack.showmenu();
                    cin>>choice;
                break;

            }
        }
    return 0;
}
Last edited on
Is this a homework where you had to do things in a certain way?
The task would be much easier if you use a struct to hold a license plate and id.
Also why use the vector like an array?
Much easier to use the vector functions push_back, size(), ...
Topic archived. No new replies allowed.