Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #define STOS_MAX 100
  5.  
  6. using namespace std;
  7.  
  8.  
  9. template<typename T>class Stos {
  10.  
  11.     private:
  12.         T data[STOS_MAX];
  13.         int size;
  14.  
  15.     public:
  16.         Stos() {    
  17.             size = 0;
  18.         }
  19.  
  20.         ~Stos() { }  
  21.  
  22.         int PobierzElementNaGorze() {
  23.             if (size == 0) {
  24.                 cout<<"Stos jest pusty!"<<endl;
  25.                 return -1;
  26.             }
  27.             return data[size-1];
  28.         }
  29.  
  30.         void Dodaj(int d) {
  31.  
  32.             if (size < STOS_MAX)
  33.                 data[size++] = d;
  34.             else
  35.                 cout<<"Stos jest pełen!"<<endl;
  36.         }
  37.  
  38.         void Zdejmij() {
  39.  
  40.             if (size == 0)
  41.                 cout<<"Stos jest pusty!"<<endl;
  42.             else
  43.                 size--;
  44.         }
  45.        
  46.         void Rozmiar(){
  47.             cout<<"Na stosie jest "<< size<<" elementow"<<endl;
  48.         }
  49.        
  50.         void UsunCoTrzeciElement(){
  51.             if (size == 0) {
  52.                 cout<<"Stos jest pusty!"<<endl;
  53.             }else{
  54.                 for(int i=0; i<STOS_MAX;i+3){
  55.                     data[STOS_MAX] = 0;
  56.                 }
  57.                
  58.             }          
  59.         }
  60. };
  61.  
  62. int main()
  63. {
  64.     Stos<int> obiekt;
  65.     obiekt.Dodaj(22);
  66.     obiekt.Dodaj(32);
  67.     obiekt.Dodaj(100);
  68.     obiekt.Dodaj(111);
  69.     obiekt.Dodaj(100);
  70.     obiekt.Rozmiar();
  71.     obiekt.UsunCoTrzeciElement();
  72.     system("PAUSE");
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement