Stacks. Help !!

Write your question here.

Ask user to enter 5 values for pop

I have three different files . One for stackmain.cpp, the header file, and just the regular c++. I have errors in my header file and stackmain.cp

This the regular c++ file
#include <iostream>
#include <string>
using namespace std;
const int MAX = 5;

class StackNumbers{
public:
StackNumbers(); // constructor
~StackNumbers(); //destroyer
bool push (int n); //insert
int pop(); // retrieve value and return as int
bool isEmpty(); // see if its empty or not
private:
int numbers[MAX];
int top;
};




This is the header file
include "StackNumbers.h"
#include <iostream>
int MAX;
string top;
int numbers;
using namespace std;

StackNumbers::StackNumbers() //create
{
top = -1;
}
StackNumbers::~StackNumbers() // destroy
{
}
bool StackNumbers:: push(int v) // increase value of top
{
bool b= false;
if(top < MAX -1)
{
++top;
numbers[top]=v;
b=true;
}
return b;
}
int StackNumbers:: pop()
{
if(!isEmpty)
--top;
}



This is the StacksMain
#include <iostream>
#include <iomanip>
#include <string>
#include "StacksNumbers.h"
using namespace std;

int values;

int main()
{
cout << "Enter five values for pop" << endl;
cin >> values;
}
Last edited on
I have errors in my header file and stackmain.cp
What errors?

Please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/
stacknumbers.h
line 4: You declare MAX as a const int

stacknumbers.cpp
line 3. You declare MAX as a simple int. Both are in the global scope. You can't declare the same variable twice with different attributes.

Line 4 string top What is this for? You have int top as a member variable.

Line 28: isEmpty is a function. You need () to call it.

Line 30: pop() is declared as type int, but doesn't return anything.

main.cpp
line 12: Your prompt says to enter 5 numbers, but you only input one.

You never instantiate your stack.

Your labels for the header and implementation file are reversed.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
Topic archived. No new replies allowed.