Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <stdexcept>
- #include <functional>
- #include <algorithm>
- using namespace std;
- class Jed {
- int inc;
- public:
- Jed (int jard, int stopa, int inc ) { Jed::inc=inc+stopa*12+jard*3*12; }
- Jed (double metri) { inc=int (metri*100/2.54); }
- void Daj (int &jardi, int &stope, int &inc);
- double DajMetre () const { return inc*2.54/100; }
- friend Jed &operator+(Jed a, Jed b) {
- Jed c(0);
- c.inc=a.inc+b.inc;
- return c;
- }
- friend Jed &operator+=(Jed &a, const Jed &b) {
- return a=a+b;
- }
- friend Jed &operator++(Jed &a) {
- a.inc++;
- return a;
- }
- friend Jed operator++(Jed &a, int) {
- Jed pom(a);
- a.inc++;
- return pom;
- }
- friend Jed operator *(Jed a, double x) {
- return (0,0,int(a.inc*x));
- }
- friend Jed operator* (double x, Jed a) {
- return (0,0,int(x*a.inc));
- }
- friend double operator/ (Jed a, Jed b) {
- return a.inc/b.inc;
- }
- friend ostream &operator <<(ostream &tok, const Jed &a) {
- tok<<a.inc%36<<" yd "<<(a.inc%36)/12<<" ft "<<a.inc<<" in ";
- return tok;
- }
- };
- void Jed::Daj (int &jardi, int &stope, int &inc) {
- jardi=Jed::inc%36;
- stope=(Jed::inc%36)/12;
- inc=(Jed::inc%36)%12;
- if (inc<0) throw "Neispravan parametar!";
- if (inc>11) {
- inc=0;
- stope+=1;
- }
- if (stope<0) throw "Neispravan parametar!";
- if (stope>2) {
- stope=0; jardi+=1;
- }
- }
- int main () {
- Jed a(3,4,2),b(12);
- cout<<a<<endl;
- cout<<b<<endl;
- Jed c(a+b);
- cout<<"Zbir :"<<c<<endl;
- cout<<"Metri: "<<a.DajMetre();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement