These are the three files. I removed the implementation in the stackk.cpp, but both main.cpp and stackk.h contain all those lines.
Code:
// File: main.cpp
//---------------------------
#include <cstdlib>
#include <iostream>
#include "stackk.h"
using namespace std;
//---------------------------------------------------------
int main( int argc, char *argv[] ) {
//---------------------------------------------------------
stackk a_stack; // Stack we want to use
a_stack.init( );
// Push three value on the stack
a_stack.push(1);
a_stack.push(2);
a_stack.push(3);
// Pop the item from the stack
std::cout << "Expect a 3 ->" << a_stack.pop() << '\n';
std::cout << "Expect a 2 ->" << a_stack.pop() << '\n';
std::cout << "Expect a 1 ->" << a_stack.pop() << '\n';
system("PAUSE");
return EXIT_SUCCESS;
}
Code:
// File: stackk.h
const int STACK_SIZE = 100; // Maximum size of a stack
class stackk
{
private:
int count; // Number of items in the stack
int data[STACK_SIZE]; // The items themselves
public:
void init( ); // Initialize the stack
void push(const int item); // Push an item on the stack
int pop( ); // Pop an item from the stack
};
Code:
// File: stackk.cpp
//------------------------------
#include <cstdlib>
#include <iostream>
#include <assert.h>
#include "stackk.h"
inline void stackk::init()
{ ... }
inline void stackk::push( const int item )
{ ... }
inline int stackk::pop()
{ ... }