SHARE
TWEET

thisthis

a guest Jan 12th, 2017 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. //#include
  4. using namespace std;
  5.  
  6. //---------------------
  7. //------- Class -------
  8. //---------------------
  9.  
  10. class tNadoba{
  11.     private:
  12.         string napln;
  13.         int kapacita, objem;
  14.     public:
  15.         tNadoba(int);
  16.         bool Napln(string, int);
  17.         tNadoba operator+=(int);
  18.         tNadoba operator-=(int);
  19.         tNadoba operator+=(tNadoba);
  20.         tNadoba operator-=(tNadoba);
  21. };
  22. //------- konstr -------
  23. tNadoba::tNadoba(int k = 0){
  24.     this->kapacita = k;
  25. }
  26. //--------------------
  27. //------- Func -------
  28. //--------------------
  29. bool tNadoba::Napln(string nap, int obj){
  30.     if(this->kapacita >= obj + this->objem){
  31.         this->objem += obj;
  32.         return true;
  33.     }
  34.     else return false;
  35. }
  36.  
  37.  
  38.  
  39. //---------------------
  40. //------- MAIN --------
  41. //---------------------
  42. int main(int argc, char** argv) {
  43.     tNadoba bandaska(10), flasa(1.5), sudok(5), pivny_pohar(0.5);
  44.    
  45.     if (sudok.Napln("pivo", 5))
  46.         cout << "Kupili sme plny sudok: " << sudok << endl;
  47.     int i = 0;
  48.     while (sudok -= pivny_pohar)
  49.     {
  50.         cout << "Uliali sme " << ++i << " pohar: " << pivny_pohar << endl;
  51.         while (pivny_pohar -= 0.25)
  52.             cout << "Splachli sme do hrdla 1/4 litra, stav: " << pivny_pohar << endl;
  53.     }
  54.    
  55.     while (bandaska.Napln("benzin", 2))
  56.         cout << "Bandasku sme naplnili 2 l, stav: " << bandaska << endl;
  57.     while (bandaska -= flasa)
  58.     {
  59.         cout << "Odliali sme z bandasky do flase:\n";
  60.         cout << " - stav bandasky: " << bandaska << "\n";
  61.         cout << " - stav flase: " << flasa << "\n";
  62.         while (flasa -= 1)
  63.           cout << "Z flase sme odliali 1 l, stav: " << flasa << endl;
  64.     }
  65.     cout << "Zaverecny stav bandasky: " << bandaska << endl;
  66.    
  67.     return 0;
  68. }
RAW Paste Data
Top