Issue with stack and fractions program

My goal is to implement a stack of fractions. Put 3 fractions on the stack, retrieve them and print out. The code compiles without errors, however, I do not think I am using the stack correctly and only printing out. Any suggestions is appreciated.

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

class frac
{

private:

int numr;
int den;


public:

//frac() : numr (0), den (1)


void getfrac()
{
char shchar;
cout << "Enter your fraction please: ";
cin >> numr >> shchar >> den;
cout << "\n";
}
void displayfrac()
{
cout << numr << "/" << den;
}
};



class Stack
{

private:

enum { MAX = 10};
frac st[MAX];
frac top;


public:
Stack()
{ top = -1; }

void push (int var)
{ st[++top] = var; }

int pop()
{return st[top --]; }
};

int main()
{

Stack s1;
frac frac1, frac2, frac3;

frac1.getfrac();
frac2.getfrac();
frac3.getfrac();

s1:push(frac1);
s1:push(frac2);
s1:push(frac3);


frac1.displayfrac();
cout << "\n";
frac2.displayfrac();
cout << "\n";
frac3.displayfrac();
cout << "\n";

cout << "1: " << s1.pop() << endl;
cout << "2: " << s1.pop() << endl;
cout << "3: " << s1.pop() << endl;


return 0;
Topic archived. No new replies allowed.