Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Dropka{
- private:
- int a, b;
- public:
- Dropka(int _a = 1, int _b = 1) {
- a = _a;
- b = _b;
- }
- Dropka(const Dropka &d) {
- a = d.a;
- b = d.b;
- }
- Dropka& operator = (const Dropka &d) {
- a = d.a;
- b = d.b;
- return *this;
- }
- ~Dropka() {
- }
- Dropka& operator += (const Dropka &d) {
- int zi = b * d.b;
- a *= (zi / d.b);
- int tmp_a = d.a * (zi / b);
- a += tmp_a;
- b = zi;
- return *this;
- }
- Dropka& operator *= (const Dropka &d) {
- a *= d.a;
- b *= d.b;
- return *this;
- }
- Dropka& operator /= (const Dropka &d) {
- a *= d.b;
- b *= d.a;
- return *this;
- }
- bool operator < (const Dropka &d) {
- int zaednicki_imenitel = b * d.b;
- int tmp_a1 = a * (zaednicki_imenitel / b);
- int tmp_a2 = d.a * (zaednicki_imenitel / d.b);
- return (tmp_a1 < tmp_a2);
- }
- int get_a() const {
- return a;
- }
- int get_b() const {
- return b;
- }
- };
- int main() {
- Dropka d1(2, 3);
- Dropka d2(3, 4);
- if(d1 < d2) {
- cout << "pomala dropka" << endl;
- }
- else {
- cout << "pogolema" << endl;
- }
- cout << d1.get_a() << " " << d1.get_b() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement