Creating a stack class in C++ Create a class called Stack for storing integers. The data members are
  an integer array for storing the integers and an integer for storing
  the top of stack (tos). Include member functions for initializing tos
  to 0, pushing an element to the stack and for popping an element from
  the stack. The push() function should check for “stack overflow” and
  pop() should check for “stack underflow”.


#include&lt;iostream&gt;
using namespace std;
#define SIZE 50
class Stack {
    int stackArray[SIZE];
    int tos;
public:
    Stack() {
        tos = 0;
    }
    void push(int);
    int pop();
    void set(int);


};

void Stack::push(int value) {

    if (tos &lt; SIZE) {
        stackArray[tos++] = value;
    }
    else
        cout &lt;&lt; "Stack overflow" &lt;&lt; endl;

}
void Stack::set(int a) {
    tos = a;

}
int Stack::pop() {
    if (tos == 0) {
        cout &lt;&lt; "Stack underflow " &lt;&lt; endl;
    }
    else {
        return stackArray[--tos];
    }

}
int main() {
    Stack s;
    for (int i = 0; i &lt; 50; i++) {
        s.push(i);
    }
    for (int i = 0; i &lt; 51; i++) {
        cout &lt;&lt; s.pop() &lt;&lt; " " &lt;&lt; i &lt;&lt; endl;
    }
}
Overall, this looks pretty good. If it were me, I'd use a more descriptive name for the top of the stack such as topOfStack or just top. tos doesn't really mean anything, so without a comment describing it, I would be confused seeing that in code. (And if you need to write a comment to explain a variable name, you've probably named it incorrectly.)

I'm not sure your set() method works correctly. From the description it sounds like it shouldn't take any arguments and should set tos to 0. But it's possible I misunderstood. If you set the top to some passed-in value, then you have a bunch of junk on the stack between its previous value and the current value, which probably isn't what you want.