Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main :
- #include <iostream>
- #include "broj.h"
- using namespace std;
- int main()
- {
- MojBroj b1(), b2(2), b3(3);
- cout << b1 << endl;
- cout << b2 << endl;
- cout << b3 << endl;
- }
- header:
- #ifndef BROJ_H_INCLUDED
- #define BROJ_H_INCLUDED
- #include <iostream>
- using namespace std;
- class MojBroj
- {
- private:
- double vrednost;
- public:
- MojBroj();
- MojBroj(double );
- MojBroj(const MojBroj &);
- void setVrednost(double );
- //double getVrednost() const {}
- friend MojBroj operator + (const MojBroj &, const MojBroj &);
- friend MojBroj operator - (const MojBroj &, const MojBroj &);
- friend MojBroj operator * (const MojBroj &, const MojBroj &);
- friend MojBroj operator / (const MojBroj &, const MojBroj &);
- friend MojBroj operator += (const MojBroj &, const MojBroj &);
- friend MojBroj operator -= (const MojBroj &, const MojBroj &);
- friend MojBroj operator *= (const MojBroj &, const MojBroj &);
- friend MojBroj operator /= (const MojBroj &, const MojBroj &);
- friend ostream& operator<<(ostream& , const MojBroj &);
- };
- #endif // BROJ_H_INCLUDED
- #include "broj.h"
- MojBroj::MojBroj()
- {
- vrednost = 1;
- }
- MojBroj::MojBroj(double v)
- {
- vrednost = v;
- }
- MojBroj::MojBroj(const MojBroj & v)
- {
- vrednost=v.vrednost;
- }
- MojBroj operator +(const MojBroj &b1, const MojBroj &b2)
- {
- MojBroj rez(b1.vrednost+b2.vrednost);
- return rez;
- }
- MojBroj operator -(const MojBroj &b1, const MojBroj &b2)
- {
- MojBroj rez(b1.vrednost-b2.vrednost);
- return rez;
- }
- MojBroj operator *(const MojBroj &b1, const MojBroj &b2)
- {
- MojBroj rez(b1.vrednost*b2.vrednost);
- return rez;
- }
- MojBroj operator /(const MojBroj &b1, const MojBroj &b2)
- {
- MojBroj rez(b1.vrednost/b2.vrednost);
- return rez;
- }
- MojBroj operator +=(const MojBroj &b1, const MojBroj &b2)
- {
- return b1+=b2;
- }
- MojBroj operator -=(const MojBroj &b1, const MojBroj &b2)
- {
- return b1-=b2;
- }
- MojBroj operator *=(const MojBroj &b1, const MojBroj &b2)
- {
- return b1*=b2;
- }
- MojBroj operator /=(const MojBroj &b1, const MojBroj &b2)
- {
- return b1/=b2;
- }
- ostream& operator << (ostream &out, const MojBroj &br)
- {
- out << br.vrednost ;
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement