By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,435 Members | 1,372 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,435 IT Pros & Developers. It's quick & easy.

is this main program right to this class?

P: 23
i want u to check this main program if it is right? plz

Enum error_code{overflow,under flow,success};
Const int maxstack=100;
Template<class stacktype>
Class stack{
Private:
Stacktype entry [maxstack];
int count;
public:
stack();
error_code push(const stacktype & item);
erroe_code pop();
eror_code top(stacktype &item) const;
bool empty() const;
bool full() const;
void clear();
int size() const;
};
Template<class stacktype>
Error_code stack<stacktype>::push(const stacktype &item)
{if (full())
Return overflow;
Entry[count]=item;
Count++;
Return success;
}
Template<class stacktype>
Error_code stack<stacktype>::top(stacktype &item) const
{
if (empty())
Return underflow;
Entry[count-1]=item;
Return success;
}
Template<class stacktype>
Error_code stack<stacktype>::pop( )
{
if (empty())
Return underflow;
Count--;
Return success;
}

Void main()
{stack<int> obj;
Obj.push("john");
Obj.push("sarah");
If (obj.push("malak")!=success)
{
Cout<<"problem"<<endl;
Exit(1);
}
Obj.pop();
Temp="salam";
Obj.top(temp);
Cout<<temp<<endl;
}//end of main
Dec 27 '06 #1
Share this Question
Share on Google+
1 Reply


100+
P: 1,646
i want u to check this main program if it is right? plz
Hi does it do what you want it to do?
Dec 27 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.