Question
C++ Problem Is this the proper way of using a pure virtual funtion and stack, and if so how can i get the program working?
C++ Problem
Is this the proper way of using a pure virtual funtion and stack, and if so how can i get the program working?
Thank You
//StackInterface.cpp
#include
#ifndef STACKINTERFACE_H
#define STACKINTERFACE_H
template
class StackInterface
{
public:
virtual bool isEmpty{} const = 0;
virtual bool push(const T& newEntry) = 0;
virtual bool pop() = 0;
virtual T peek() const = 0;
virtual ~StackInterface() {}
};
#endif
//OurStack.h
#include
#include
#ifndef OURSTACK_H
#define OURSTACK_H
#include "StackInterface.h"
template
class OurStack :public StackInterface
{
private:
stack OurStack;
public:
bool isEmpty() const; //Test if stack is empty
T& top();//Returns refference to top
bool pop(); // removes top of stack
bool push(const T& newEntry);
};
#include"OurStack.cpp"
#endif
//Ourstack.cpp
#include "OurStack.h"
#include
#include
template
OurStack
{
}
template
bool OurStack
return OurStack.empty();
}
template
bool OurStack
OurStack.push(newEntry);
if (OurStack.top() == newEntry)
return true;
else
return false;
}
template
bool OurStack
if (!OurStack.empty()) {
OurStack.pop();
return true;
}
else
return false;
}
template
T OurStack::top() {
return OurStack.top();
}
// Main.cpp
#include
#include
#include"OurStack.h"
#include"StackInterface.h"
using namespace std;
int main() {
OurStack
if (testStack.isEmpty) {
cout << "Empty Stack";
}
testStack.push(4);
testStack.push(5);
testStack.push(3);
testStack.push(2);
testStack.push(1);
cout << "Current Top to remove is: " << testStack.pop();
cout << " Current top now: " << testStack.top();
system("pause");
return 0;
}
Thank You!!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started