Advertisement
sellmmaahh

tut12-zad6

Aug 3rd, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <stdexcept>
  4. #include <functional>
  5. #include <algorithm>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. class Jed {
  11.     int inc;
  12.  
  13. public:
  14.     Jed (int jard, int stopa, int inc ) { Jed::inc=inc+stopa*12+jard*3*12; }
  15.  
  16.     Jed (double metri) { inc=int (metri*100/2.54); }
  17.  
  18.      void Daj (int &jardi, int &stope, int &inc);
  19.  
  20.      double DajMetre () const { return inc*2.54/100; }
  21.      friend Jed &operator+(Jed a, Jed b) {
  22.          Jed c(0);
  23.          c.inc=a.inc+b.inc;
  24.          return c;
  25.      }
  26.      friend Jed &operator+=(Jed &a, const Jed &b) {
  27.          return a=a+b;
  28.      }
  29.      friend Jed &operator++(Jed &a) {
  30.         a.inc++;
  31.         return a;
  32.      }
  33.      friend Jed operator++(Jed &a, int) {
  34.          Jed pom(a);
  35.          a.inc++;
  36.          return pom;
  37.      }
  38.      friend Jed operator *(Jed a, double x) {
  39.          return (0,0,int(a.inc*x));
  40.      }
  41.      friend Jed operator* (double x, Jed a) {
  42.          return (0,0,int(x*a.inc));
  43.      }
  44.      friend double operator/ (Jed a, Jed b) {
  45.          return a.inc/b.inc;
  46.      }
  47.      friend ostream &operator <<(ostream &tok, const Jed &a) {
  48.          tok<<a.inc%36<<" yd "<<(a.inc%36)/12<<" ft "<<a.inc<<" in ";
  49.          return tok;
  50.      }
  51.      };
  52.  
  53.   void Jed::Daj (int &jardi, int &stope, int &inc) {
  54.          jardi=Jed::inc%36;
  55.          stope=(Jed::inc%36)/12;
  56.          inc=(Jed::inc%36)%12;
  57.          if (inc<0) throw "Neispravan parametar!";
  58.          if (inc>11) {
  59.                 inc=0;
  60.          stope+=1;
  61.          }
  62.          if (stope<0) throw "Neispravan parametar!";
  63.          if (stope>2) {
  64.                 stope=0; jardi+=1;
  65.          }
  66.      }
  67.  
  68.      int main () {
  69.          Jed a(3,4,2),b(12);
  70.          cout<<a<<endl;
  71.          cout<<b<<endl;
  72.          Jed c(a+b);
  73.          cout<<"Zbir :"<<c<<endl;
  74.          cout<<"Metri: "<<a.DajMetre();
  75.          return 0;
  76.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement