Advertisement
Hakunin

OBP1_V6

Apr 20th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.61 KB | None | 0 0
  1. /////////////////////////////////////////////////////////// main.cpp /////////////////////////////////////////////////////////
  2.  
  3.  
  4. #include <iostream>
  5. #include "KutijaPeza.h"
  6. #include "Pez.h"
  7.  
  8. int main() {
  9.  
  10.     Pez P1;
  11.     KutijaPeza K1;
  12.  
  13.     K1 = KutijaPeza();
  14.     P1 = Pez("limun");
  15.     P1.ispisPez();
  16.  
  17.     K1.UnistiPez();
  18.     K1.DodajPez(P1);
  19.  
  20.  
  21.     return 0;
  22. }
  23.  
  24. /////////////////////////////////////////////////////////// Pez.h  /////////////////////////////////////////////////////////
  25.  
  26. //
  27. // Created by korisnik on 20.4.2017..
  28. //
  29.  
  30. #ifndef UNTITLED_PEZ_H
  31. #define UNTITLED_PEZ_H
  32.  
  33. #include <iostream>
  34. using namespace std;
  35.  
  36.  
  37. const string ukus[] = {"jabuka","malina","pomorandza","ananas"};
  38.  
  39. class Pez {
  40. private:
  41.     int idPeza;
  42.     string ukus;
  43. public:
  44.     Pez();
  45.     Pez(string uk);
  46.     void ispisPez();
  47. };
  48.  
  49.  
  50. #endif //UNTITLED_PEZ_H
  51.  
  52. /////////////////////////////////////////////////////////// Pez.cpp  /////////////////////////////////////////////////////////
  53. //
  54. // Created by korisnik on 20.4.2017..
  55. //
  56.  
  57. #include "Pez.h"
  58. #include <stdlib.h>
  59. #include <iostream>
  60.  
  61. using namespace std;
  62.  
  63. static int idbr=0;
  64.  
  65. Pez::Pez() {
  66.     int tmp = rand()%3;
  67.     this->ukus=ukus[tmp];
  68.     idPeza=idbr;
  69.     idbr++;
  70. }
  71.  
  72. Pez::Pez(string ukus) {
  73.     this->ukus=ukus;
  74.     idPeza=idbr;
  75.     idbr++;
  76. }
  77.  
  78. void Pez::ispisPez() {
  79.     cout << "PEZ ID: " << idPeza << " ,UKUS: " << ukus << endl;
  80. }
  81.  
  82. /////////////////////////////////////////////////////////// KutijaPeza.h  /////////////////////////////////////////////////////////
  83.  
  84. //
  85. // Created by korisnik on 20.4.2017..
  86. //
  87.  
  88. #ifndef UNTITLED_KUTIJAPEZA_H
  89. #define UNTITLED_KUTIJAPEZA_H
  90.  
  91. #include "Pez.h"
  92.  
  93. const int MAX=10;
  94.  
  95. class KutijaPeza {
  96. private:
  97.     Pez** pptr;
  98.     int count;
  99. public:
  100.     KutijaPeza();
  101.     void DodajPez(Pez);
  102.     Pez UzmiPez(int);
  103.     void UnistiPez();
  104. };
  105.  
  106.  
  107. #endif //UNTITLED_KUTIJAPEZA_H
  108.  
  109.  
  110. /////////////////////////////////////////////////////////// KutijaPeza.cpp  /////////////////////////////////////////////////////////
  111.  
  112. //
  113. // Created by korisnik on 20.4.2017..
  114. //
  115.  
  116. #include "KutijaPeza.h"
  117.  
  118. KutijaPeza::KutijaPeza() {
  119.     pptr = new Pez*[MAX];
  120.  
  121.     for(int i=0;i<MAX-1;i++){
  122.         pptr[i] = new Pez();
  123.     }
  124.  
  125.     count=MAX-1;
  126. }
  127.  
  128. void KutijaPeza::DodajPez(Pez A) {
  129.     if( count==MAX-1){
  130.         cout << "KUTIJA PEZA JE PUNA, NEMA  MESTA ZA JOS!!" << endl;
  131.     }
  132.     else
  133.     {
  134.         pptr[count]=new Pez(A);
  135.         count++;
  136.     }
  137. }
  138.  
  139. Pez KutijaPeza::UzmiPez(int a) {
  140.     count--;
  141.     return *pptr[a-1];
  142. }
  143.  
  144. void KutijaPeza::UnistiPez() {
  145.     delete pptr[count];
  146.     count--;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement