Advertisement
GerexD

V

Oct 11th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #include <iostream>
  2. /**
  3. Készítsd el a Vere/m osztályt, melynek mezôi:
  4. -v[100] egy tömb/
  5. -teto a verem tetejéne/k indexe:
  6. és amelynek metódusai:/
  7. - push() - egy elem beszúrása a verem tetej/ére, ha lehetséges
  8. - pop () - elem kivétele a verem tetejérol/
  9. - kiir() - verem tartalmának kiíratása, a/ verem aljától kezdve
  10. - ossz() - elemek összegét téríti vissza/
  11. - dupla() - a felso elemet megduplazza, ha van ilyen csak a push és pop metódusokat felhasználva/
  12. */
  13. using namespace std;
  14. class verem
  15. {
  16. private:
  17. int v[101];
  18. int teto=0;
  19. public:
  20. void push(int szam)
  21. {if(teto<100)
  22. {
  23. teto++;
  24. v[teto]=szam;
  25. } else cout<<"Tele a verem te snitch"<<endl;
  26. }
  27.  
  28. int pop()
  29. {if(teto>0){
  30. int x=v[teto];
  31. teto--;
  32. return x;}
  33. else{ cout<<"Ures a verem te snitch"<<endl;
  34. return -1;}
  35. }
  36.  
  37. void kiir()
  38. {
  39. for(int i=1;i<=teto;i++)
  40. cout<<v[i]<<" ";
  41. cout<<endl;
  42.  
  43. }
  44. int ossz()
  45. {
  46. int s=0;
  47. for(int i=1;i<=teto;i++)
  48. s+=v[i];
  49. return s;
  50. }
  51. void dupla()
  52. {
  53. int x=pop();
  54. if(x!=-1) push(2*x);
  55. }
  56. };
  57. int main()
  58. {
  59. verem v;
  60. int x=1,a;
  61. while(x!=6)
  62. {
  63. cout<<"1.Push"<<endl;
  64. cout<<"2.Pop"<<endl;
  65. cout<<"3.Kiir"<<endl;
  66. cout<<"4.Osszeg"<<endl;
  67. cout<<"5.Duplaz"<<endl;
  68. cout<<"6.Kilepes"<<endl;
  69. cout<<"Valassz MOST te snitch "<<endl;
  70. cin>>x;
  71. switch(x)
  72. {
  73. case 1:{cout<<"A ";cin>>a;v.push(a);break;}
  74. case 2:{v.pop();break;}
  75. case 3:{v.kiir();break;}
  76. case 4:{cout<<"Az osszeg "<<v.ossz()<<endl;break;}
  77. case 5:{v.dupla();break;}
  78.  
  79. }
  80.  
  81. }
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement