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?
#include <iostream>
#include <cstring>
#include <vector>
usingnamespace 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;
returnfalse;
}
temp=stackVect[top];
cout<<temp;
return stackVect[top];
}
//-------------------------------------------------
double peek()
{
int temp;
if (isEmpty())
{
cout<<"Database is EMPTY."<<endl;
returnfalse;
}
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())
{
returnfalse;
}
temp=stackVect[top];
cout<<temp;
return stackVect[top];
}
//-------------------------------------------------
double peek()
{
int temp;
if (isEmpty())
{
returnfalse;
}
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;
}