Advertisement
AnaGocevska

Untitled

Mar 22nd, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.06 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Smetka
  6. {
  7. private:
  8.     string brojSmetka;
  9.     string pin;
  10.     float sostojba;
  11.  
  12. public:
  13.     Smetka()
  14.     {
  15.         this->brojSmetka="";
  16.         this->pin="";
  17.         this->sostojba=0;
  18.     }
  19.  
  20.     Smetka(string brojSmetka, string pin, float sostojba)
  21.     {
  22.         this->brojSmetka=brojSmetka;
  23.         this->pin=pin;
  24.         this->sostojba=sostojba;
  25.     }
  26.  
  27.     string getBrojSmetka()
  28.     {
  29.         return this->brojSmetka;
  30.     }
  31.  
  32.     void setBrojSmetka(string brojSmetka)
  33.     {
  34.         this->brojSmetka=brojSmetka;
  35.     }
  36.     string getPin()
  37.     {
  38.         return this->pin;
  39.     }
  40.  
  41.     void setPin(string pin)
  42.     {
  43.         this->pin=pin;
  44.     }
  45.  
  46.     float getSostojba()
  47.     {
  48.         return this->sostojba;
  49.     }
  50.  
  51.     void setSostojba(float sostojba)
  52.     {
  53.         this->sostojba=sostojba;
  54.     }
  55.  
  56.     // PECATI
  57.     void pecatiSmetka ()
  58.     {
  59.         cout<<" Broj na smetka: "<< this->brojSmetka<< endl;
  60.         cout<<"Pin: "<< this->pin<<endl;
  61.         cout<<"Sostojba: "<<this->sostojba<<endl;
  62.     }
  63.  
  64.     bool proverka(string pin)
  65.     {
  66.         if(this->pin==pin)
  67.             return true;
  68.         return false;
  69.     }
  70.  
  71.     void IzvadiPari(int iznos)
  72.     {
  73.         if(iznos<=sostojba)
  74.         {
  75.             this->sostojba-=iznos;
  76.             cout<<"Novata sostojba na vasata smetka e : "<<this->sostojba<< endl;
  77.         }
  78.         else
  79.         {
  80.             cout<<"Nemate dovolno sredstva"<<endl;
  81.         }
  82.     }
  83. }; // kraj na klasa Smetka
  84.  
  85. class Korisnik
  86. {
  87. private:
  88.     string imePrezime;
  89.     Smetka s;
  90.  
  91. public:
  92.  
  93.     Korisnik()
  94.     {
  95.         this->imePrezime="";
  96.         this->s=Smetka();
  97.     }
  98.  
  99.     Korisnik(string imePrezime, Smetka s)
  100.     {
  101.         this->imePrezime=imePrezime;
  102.         this->s=Smetka(s.getBrojSmetka(),s.getPin(),s.getSostojba());
  103.     }
  104.  
  105.     string getImePrezime()
  106.     {
  107.         return this->imePrezime;
  108.     }
  109.  
  110.     void setImePrezime(string imePrezime)
  111.     {
  112.         this->imePrezime=imePrezime;
  113.     }
  114.  
  115.     Smetka getS()
  116.     {
  117.         return this->s;
  118.     }
  119.  
  120.     void setS(Smetka s)
  121.     {
  122.         this->s.setBrojSmetka(s.getBrojSmetka());
  123.         this->s.setPin(s.getPin());
  124.         this->s.setSostojba(s.getSostojba());
  125.     }
  126.  
  127.     //PECATI
  128.     void pecatiKorisnik ()
  129.     {
  130.         cout<<"Ime i prezime na korisnikot: "<<this->imePrezime<<endl;
  131.         cout<<"Podatoci za smetkata na korisnikot: ";
  132.         s.pecatiSmetka();
  133.     }
  134. };// kraj na klasa Korisnik
  135.  
  136. class Bankomat
  137. {
  138. private:
  139.     int sostojba;
  140.     Korisnik k[3];
  141.     int ima(Korisnik x)
  142.     {
  143.         for(int i=0; i<3; i++)
  144.         {
  145.             if(this->k[i].getImePrezime() == x.getImePrezime() && this->k[i].getS().getBrojSmetka() == x.getS().getBrojSmetka())
  146.                 return i;
  147.         }
  148.         return -1;
  149.     }
  150.  
  151. public:
  152.  
  153.     Bankomat()
  154.     {
  155.         this->sostojba=0;
  156.         int n;
  157.         for(int i=0; i<n; i++)
  158.         {
  159.             this->k[i]=Korisnik();
  160.         }
  161.     }
  162.  
  163.     Bankomat(int sostojba, Korisnik k[3])
  164.     {
  165.         this->sostojba=sostojba;
  166.         int n;
  167.         for(int i=0; i<n; i++)
  168.         {
  169.             this->k[i]=Korisnik(k[i].getImePrezime(), k[i].getS());
  170.         }
  171.     }
  172.  
  173.     int getSostojba()
  174.     {
  175.         return this->sostojba;
  176.     }
  177.  
  178.     void setSostojba(int sostojba)
  179.     {
  180.         this->sostojba=sostojba;
  181.     }
  182.  
  183.     Korisnik *getK()
  184.     {
  185.         return this->k;
  186.     }
  187.  
  188.     void setK(Korisnik k[3])
  189.     {
  190.         for(int i=0; i<3; i++)
  191.         {
  192.             this->k[i].setImePrezime(k[i].getImePrezime());
  193.             this->k[i].setS(k[i].getS());
  194.         }
  195.     }
  196.  
  197.     void IzvadiPari(Korisnik k1, string pin, int iznos)
  198.     {
  199.         if(iznos<=sostojba)
  200.         {
  201.             int poz=this->ima(k1);
  202.             if(poz!=-1 && this->k[poz].getS().proverka(pin))
  203.             {
  204.                 this->k[poz].getS().IzvadiPari(iznos);
  205.             }
  206.             else
  207.             {
  208.                 cout<<"Korisnikot ne postoi ili Pogreshen pin"<<endl;
  209.             };
  210.             else
  211.             {
  212.                 cout<<"Nema dovolno sredstva"<<endl;
  213.             }
  214.         }
  215.     }
  216.     // PECATI
  217. void pecatiBankomat(int n)
  218. {
  219.     cout<<"Sostojbata na bankomatot e: "<<sostojba<<endl;
  220.     cout<<"Listata na korisnci e: ";
  221.     for(int i=0; i<n;i++)
  222.     {
  223.         k[i].pecatiKorisnik();
  224.     }
  225. }
  226. }; // kraj na klasa Bankomat
  227.  
  228.  
  229. int main()
  230. {
  231.     string imePrezime, pin;
  232.     int iznos, sostojba;
  233.     float sostojbaS; //sostojba na smetka
  234.     Korisnik niza[3];
  235.  
  236.     for(i=0; i<3; i++)
  237.     {
  238.         cin>>imePrezime>>brojSmetka>>pin>>sostojbaS;
  239.         Smetka s1(brojSmetka, pin, sostojbaS);
  240.         this->k[i]=Korisnik(imePrezime, s1);
  241.     }
  242.  
  243.     cin>>sostojba;
  244.     Bankomat b(sostojba, niza)
  245.     while(1)
  246.     {
  247.         cin>>imePrezime;
  248.         if(imePrezime=="!")
  249.             break;
  250.         cin>>brojSmetka>>pin>>sostojba;
  251.         Smetka s(brojSmetka,pin,sostojba);
  252.         Korisnik A(imePrezime, s);
  253.         cin>>iznos;
  254.         b.IzvadiPari(A,pin,iznos);
  255.     }
  256.     return 0;
  257. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement