Here is the header file I was given to use
//
// ministack.h
//
#ifndef MINISTACK_H
#define MINISTACK_H
const int MINI_STACK_SIZE = 5; // Fixed number of element in stack
class MiniStack
{
private:
int num; // Number of values stored in MiniStack
char* stackPtr; // Pointer to array representing stack
public:
MiniStack(); // Default constructor
void Push(char ch); // Adds element to top of stack assuming stack not full
void Pop(); // Removes element from top of stack
void MakeEmpty(); // Empties ministack
char Top(); // Returns copy of value stored at top of stack
bool IsFull() const; // Returns true if ministack is full; false otherwise
bool IsEmpty() const; // Returns true if ministack empty; false otherwise
void Print() const; // Prints stack contents, top to bottom
~MiniStack(); // Destructor
};
#endif
I am having prolems with the print function. It wont let me just use a cout statement what do I need to use. Here is my code that I wrote
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>
#include <new>
#include <cstddef>
#include "ministack.h"
#include "bigstack.h"
MiniStack::MiniStack() // Default constructor
{
stackPtr = new char[MINI_STACK_SIZE];
num = 0;
}
void MiniStack::Push(char ch) // Adds element to top of stack assuming stack not full
{
stackPtr[num] = ch;
num++;
}
void MiniStack::Pop() // Removes element from top of stack
{
num--;
}
void MiniStack::MakeEmpty() // Empties ministack
{
num = -1;
}
char MiniStack::Top() // Returns copy of value stored at top of stack
{
return stackPtr[num];
}
bool MiniStack::IsFull() const // Returns true if ministack is full; false otherwise
{
return (num == MINI_STACK_SIZE-1);
}
bool MiniStack::IsEmpty() const // Returns true if ministack empty; false otherwise
{
if (num == -1)
return true;
else
return false;
}
void MiniStack::Print() const // Prints stack contents, top to bottom
{
}
MiniStack::~MiniStack() // Destructor
{
num--;
}
Please what am I doing wrong. Also does this code look right I think it is but I am not 100% on this.