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; // broitel i imenitel
- public:
- Dropka(int _a = 1, int _b = 1) {
- a = _a;
- b = _b;
- }
- Dropka(const Dropka &t) { // copy constructor
- a = t.a;
- b = t.b;
- }
- ~Dropka() {
- }
- Dropka operator + (Dropka d2) {
- Dropka tmp(a ,b);
- int zaednicki_imenitel = b * d2.b;
- a *= (zaednicki_imenitel / b);
- d2.a *= (zaednicki_imenitel / d2.b);
- tmp.a = a + d2.a;
- tmp.b = zaednicki_imenitel;
- return tmp;
- }
- Dropka operator * (Dropka d2) {
- Dropka tmp(a, b);
- tmp.a *= d2.a;
- tmp.b *= d2.b;
- return tmp;
- }
- Dropka operator / (Dropka d2) {
- Dropka tmp(d2.b, d2.a);
- tmp.a *= a;
- tmp.b *= b;
- return tmp;
- }
- int get_a() const {
- return a;
- }
- int get_b() const {
- return b;
- }
- };
- int main() {
- int a, b;
- cin >> a >> b;
- Dropka d1(a, b);
- int x, y;
- cin >> x >> y;
- Dropka d2(x, y);
- d1 = d1 + d2;
- cout << d1.get_a() << " " << d1.get_b() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement