Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////// main.cpp /////////////////////////////////////////////////////////
- #include <iostream>
- #include "KutijaPeza.h"
- #include "Pez.h"
- int main() {
- Pez P1;
- KutijaPeza K1;
- K1 = KutijaPeza();
- P1 = Pez("limun");
- P1.ispisPez();
- K1.UnistiPez();
- K1.DodajPez(P1);
- return 0;
- }
- /////////////////////////////////////////////////////////// Pez.h /////////////////////////////////////////////////////////
- //
- // Created by korisnik on 20.4.2017..
- //
- #ifndef UNTITLED_PEZ_H
- #define UNTITLED_PEZ_H
- #include <iostream>
- using namespace std;
- const string ukus[] = {"jabuka","malina","pomorandza","ananas"};
- class Pez {
- private:
- int idPeza;
- string ukus;
- public:
- Pez();
- Pez(string uk);
- void ispisPez();
- };
- #endif //UNTITLED_PEZ_H
- /////////////////////////////////////////////////////////// Pez.cpp /////////////////////////////////////////////////////////
- //
- // Created by korisnik on 20.4.2017..
- //
- #include "Pez.h"
- #include <stdlib.h>
- #include <iostream>
- using namespace std;
- static int idbr=0;
- Pez::Pez() {
- int tmp = rand()%3;
- this->ukus=ukus[tmp];
- idPeza=idbr;
- idbr++;
- }
- Pez::Pez(string ukus) {
- this->ukus=ukus;
- idPeza=idbr;
- idbr++;
- }
- void Pez::ispisPez() {
- cout << "PEZ ID: " << idPeza << " ,UKUS: " << ukus << endl;
- }
- /////////////////////////////////////////////////////////// KutijaPeza.h /////////////////////////////////////////////////////////
- //
- // Created by korisnik on 20.4.2017..
- //
- #ifndef UNTITLED_KUTIJAPEZA_H
- #define UNTITLED_KUTIJAPEZA_H
- #include "Pez.h"
- const int MAX=10;
- class KutijaPeza {
- private:
- Pez** pptr;
- int count;
- public:
- KutijaPeza();
- void DodajPez(Pez);
- Pez UzmiPez(int);
- void UnistiPez();
- };
- #endif //UNTITLED_KUTIJAPEZA_H
- /////////////////////////////////////////////////////////// KutijaPeza.cpp /////////////////////////////////////////////////////////
- //
- // Created by korisnik on 20.4.2017..
- //
- #include "KutijaPeza.h"
- KutijaPeza::KutijaPeza() {
- pptr = new Pez*[MAX];
- for(int i=0;i<MAX-1;i++){
- pptr[i] = new Pez();
- }
- count=MAX-1;
- }
- void KutijaPeza::DodajPez(Pez A) {
- if( count==MAX-1){
- cout << "KUTIJA PEZA JE PUNA, NEMA MESTA ZA JOS!!" << endl;
- }
- else
- {
- pptr[count]=new Pez(A);
- count++;
- }
- }
- Pez KutijaPeza::UzmiPez(int a) {
- count--;
- return *pptr[a-1];
- }
- void KutijaPeza::UnistiPez() {
- delete pptr[count];
- count--;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement