Hello I'm trying to create a stack program that only contains even numbers, basically the program will have some hard coded odd numbers but MUST filter them out and only display the even. This is what I have so far.
Also in my .cpp file I believe it's my int EvenStack::GetevenNumber() function that needs to be adjusted, but i'm not sure how to do that? From reading online i'm thinking it needs something saying it's divisible by 2?
One error i'm receiving in main:
27|error: no matching function for call to 'EvenStack::GetevenNumber(std::stack<int>&)'|
#include "EvenStack.h"
EvenStack::EvenStack()
{
m_even_number = 0;
}
EvenStack::EvenStack (int EvenNumber)
{
m_even_number = EvenNumber;
}
EvenStack::~EvenStack()
{
//dtor
}
int EvenStack::GetevenNumber() // The getEvenNumbers fucntion receives a stack of integers (implemented in the by STL stack)
//and pushes all of the even numbers from the input stack (preserving their original order) onto the EvenStack object.
{
return m_even_number;
}
void EvenStack::SetevenNumber (int EvenNumber)
{
m_even_number = EvenNumber;
}
//pushes element on to the stack
bool EvenStack::push(int item)
{
if (top >= (MAX-1)) {
cout << "Stack Overflow!!!";
returnfalse;
}
else {
myStack[++top] = item;
cout<<item<<endl;
returntrue;
}
}
//removes or pops elements out of the stack
int EvenStack::pop()
{
if (top < 0) {
cout << "Stack Underflow!!";
return 0;
}
else {
int item = myStack[top--];
return item;
}
}
//check if stack is empty
bool EvenStack::emptyStack()
{
return (top < 0);
}
A comment mentioned using the STL stack, so do you really need to implement a whole stack yourself?
yes.
: The getEvenNumbers function receives a stack of integers (implemented in the by STL stack) and pushes all of the even numbers from the input stack (preserving their original order) onto the EvenStack object. For example, given the stack { 4, 5, 3, 2, 6, 9, 2 } (where 4 is at the top of the stack), the function pushes { 4, 2, 6, 2 }. The initial stack should retain its original values when the function ends.
I may have explained it wrong so I just sent the whole prompt, i'll put my updated .cpp file. From my understanding that ^^ needs to be put in my: int EvenStack::GetEvenNumbers() function.