Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "razlomak.h"
- #include <iostream>
- using namespace std;
- razlomak::razlomak()
- {
- _x=0;
- _y=1;
- }
- razlomak::razlomak(int x, unsigned int y)
- {
- _x=x;
- if (y!=0)
- _y=y;
- else
- _y=1;
- }
- razlomak::razlomak(const razlomak &x)
- {
- _x=x._x;
- _y=x._y;
- }
- int razlomak::vratiBr(void) const {return _x;}
- unsigned int razlomak::vratiIm(void) const {return _y;}
- razlomak razlomak::pomnozi(const razlomak &a) const
- {
- return razlomak(_x*a._x, _y*a._y);
- }
- razlomak razlomak::saberi(const razlomak &a) const
- {
- return razlomak(_x*a._y+a._x*_y,_y*a._y);
- }
- razlomak razlomak::skrati() const
- {
- int x=_x;
- unsigned y=_y;
- while (x!=y)
- if (x>y)
- x-=y;
- else
- y-=x;
- y=_y/x;
- x=_x/x;
- return razlomak(x,y);
- }
- razlomak& razlomak::operator= (const razlomak &r)
- {
- if (this != &r)
- {
- _x = r._x;
- _y = r._y;
- }
- return *this;
- }
- istream& operator>> (istream& in, razlomak& r)
- {
- char c;
- in >> r._x >> c >> r._y;
- return in;
- }
- ostream& operator<< (ostream& out, const razlomak& r)
- {
- out << r._x << "/" << r._y;
- return out;
- }
Add Comment
Please, Sign In to add comment