Advertisement
Guest User

حل الكويز اذا حد متغلق

a guest
May 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class stackone
  4. {
  5. private:
  6. int *ar;
  7. int top, siz;
  8. public:
  9. stackone()
  10. {
  11. top=-1;
  12. cout<<endl<<"Enter stack size ";
  13. cin>>siz;
  14. ar = new int[siz];
  15. }
  16. void push(int m)
  17. {
  18. if(top==siz-1)
  19. cout<<endl<<" Stack overflow no push ";
  20. else
  21. {
  22. top++;
  23. ar[top]=m;
  24. cout<<endl<<m<<" Push successful ";
  25. }
  26. }
  27. void printTop()
  28. {
  29. if(top == -1)
  30. {
  31. cout<<"Stack is EMPTY"<<endl;
  32. }
  33. else{
  34.  
  35. int t = ar[top];
  36. cout<<"Top value is "<<t<<endl;
  37. }
  38.  
  39. }
  40. int getSize()
  41. {
  42. if(top == -1)
  43. {
  44. cout<<"Stack is EMPTY"<<endl;
  45. }
  46. else
  47. {
  48. int i =0 ;
  49. for(i=0; i<=top; i++)
  50. {
  51.  
  52. }
  53. cout<<"Stack size is "<<i<<endl;
  54. }
  55. }
  56. };
  57. int main()
  58. {
  59. stackone *ob = new stackone();
  60. int choice;
  61. do
  62. {
  63. cout<<endl<<"\t STACK OPERATIONS ";
  64. cout<<endl<<"1. Push a value ";
  65. cout<<endl<<"2. Print topmost value ";
  66. cout<<endl<<"3. Print number of values in stack ";
  67. cout<<endl<<"Select choice [4 to exit ] ";
  68. cin>>choice;
  69. switch(choice)
  70. {
  71. case 1:
  72.  
  73.  
  74. int n;
  75. cout<<"Enter value to push : ";
  76. cin>>n;
  77. ob->push(n);
  78. break;
  79.  
  80.  
  81. case 2:
  82. ob->printTop();
  83. break;
  84. case 3:
  85. ob->getSize();
  86. break;
  87. default:
  88. cout<<endl<<" give 4 for exit ";
  89. }
  90. }
  91. while(choice !=4);
  92. cout<<endl<<"Thanks for testing me ";
  93.  
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement