I have never seen this error before, what is it and how can I fix it?
Code:#include <iostream.h> #include <conio.h> const max_length=10; class Stack { private: int stack[max_length]; int top; public: Stack( ); void pop( ); void push( ); void print_stack( ); void show_working( ); }; void Stack::Stack( ) { top=-1; for(int count=0;count<max_length;count++) stack[count]=0; } void Stack::push( ) { int item; cout<<"\n\n\n\n\n\t Enter value to push onto Stack : "; cin>>item; if(top==(max_length-1)) cout<<"\n\n\t *** Error : Stack is full. \n"<<endl; else { top++; stack[top]=item; cout<<"\n\n\t *** "<<item<<" is pushed onto the Stack."<<endl; } cout<<"\n\n\n\t\t Pres any key to return to Menu. "; getch( ); } void Stack::pop( ) { if(top==-1) cout<<"\n\n\n\t *** Error : Stack is empty. \n"<<endl; else { cout<<"\n\n\n\t *** "<<stack[top]<<" is poped from the Stack."<<endl; stack[top]=0; top--; } cout<<"\n\n\n\t\t Pres any key to return to Menu. "; getch( ); } void Stack::print_stack( ) { if(top!=-1) { cout<<"\n\n\n\n\n\t Values pushed onto Stack are : \n"<<endl; for(int count=0;count<=top;count++) cout<<"\t Stack ["<<count<<"] = "<<stack[count]<<endl; } else cout<<"\n\n\n\n\n\t *** Nothing to show. "<<endl; cout<<"\n\n\n\t\t Pres any key to return to Menu. "; getch( ); } void Stack::show_working( ) { char Key=NULL; do { clrscr( ); gotoxy(5,5); cout<<"Sequential Stack"<<endl; gotoxy(10,8); cout<<"Select one:"<<endl; gotoxy(15,10); cout<<"- Press \P\ to Push a value"<<endl; gotoxy(15,12); cout<<"- Press \O\ to Pop a value"<<endl; gotoxy(15,14); cout<<"- Press \S\ to Print the values"<<endl; gotoxy(15,16); cout<<"- Press \E\ to Exit"<<endl; Input: gotoxy(10,20); cout<<" "; gotoxy(10,20); cout<<"Enter your Choice : "; Key=getche( ); if(int(Key)==27 || Key=='e' || Key=='E') break; else if(Key=='p' || Key=='P') push( ); else if(Key=='o' || Key=='O') pop( ); else if(Key=='s' || Key=='S') print_stack( ); else goto Input; } while(1); } int main( ) { Stack obj; obj.show_working( ); return 0; }



LinkBack URL
About LinkBacks


