Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdio>
- using namespace std;
- class Drob
- {
- public:
- int chisl, znam;
- Drob() : chisl(1), znam(1) {}
- Drob(int chisl, int znam) : chisl(chisl), znam(znam) {}
- double value()
- {
- return ((double)chisl) / znam;
- }
- void print()
- {
- cout << chisl << "/" << znam;
- }
- Drob add(Drob a)
- {
- int tchisl = chisl * a.znam + a.chisl * znam;
- int tznam = znam * a.znam;
- return Drob(tchisl, tznam);
- }
- };
- int main()
- {
- //freopen("output.txt", "w", stdout);
- Drob a;
- a.print();
- cout << "\n";
- Drob b(3, 5);
- b.print();
- cout << "\n";
- Drob c = a.add(b);
- c.print();
- cout << "\n";
- //getc(stdin);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement