Okay so my program is suppose to have 3 lanes (Lane 1, lane 2, and street). I am suppose to push cars onto lane one once lane 1 is full then push to lane 2 if a car is departing I am suppose to push the cars on top of the selected car that is leaving until I hit the car I want. My only problem is I cant get the program to print departures and arrivals along with their license plates. I also cant get the count to work. The count is suppose to count how many times the car was moved.
My code
#ifndef LabTwo
#define LabTwo
#include <cstdlib>
template<class StackType>
class Stack {
// LIFO objects
public:
Stack(int MaxStackSize = 10);
~Stack() { delete[] stack; }
bool IsEmpty() const { return top == -1; }
bool IsFull() const { return top == MaxTop; }
bool search(StackType value) const;
StackType Top() const;
void push(StackType x);
void pop();
private:
int top; // current top of stack
int MaxTop; // max value for top
StackType *stack; // element array
};
template<class StackType>
Stack<StackType>::Stack(int MaxStackSize)
{
//Pre: none'
//Post: Array of size MaxStackSaize to implement stack
// Stack constructor.
MaxTop = MaxStackSize - 1;
stack = new StackType[MaxStackSize];
top = -1;
}
template<class StackType>
StackType Stack<StackType>::Top() const
{
//Pre: stack is not empty
// Post: Returns top element.
if (IsEmpty())
throw logic_error("Top fails: Stack is empty");// Top fails
return stack[top];
}
template<class StackType>
void Stack<StackType>::push(StackType x)
{
//Pre: Stack is not full
//Post: Push x to stack.
// Stack has one more element
if (IsFull()) throw logic_error("Push fails: full stack"); // Push fails
stack[++top] = x;
}
template<class StackType>
void Stack<StackType>::pop()
{
//Pre: Stack is not Empty
//Post: Stack has one less element
if (IsEmpty()) {
throw logic_error("Pop fails: Stack is empty");
exit(1);
}; // Pop fails
top--;
}
//my search function
template<class StackType>
bool Stack<StackType>::search(StackType value) const
{
for (int i = 0; i < top; i++)
{
if (stack[i] == value)
{
returntrue;
}
}
returnfalse;
}
#endif