• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# rational

a guest Apr 7th, 2020 188 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.     int a;
2.     cin >> a;
3.
4.     int p, q;
5.     cin >> p >> q;
6.     const Rational rc(p, q); // q != 0 is guaranteed by author of tests
7.     cout << rc.getNumerator() << ' ' << rc.getDenominator() << endl;
8.
9.     Rational r1, r2;
10.     cin >> r1 >> r2;
11.
12.     cout << r1 << endl;
13.     cout << r2 << endl;
14.
15.     try {
16.         cout << 1/r1 << endl;
17.     } catch (const RationalDivisionByZero& ex) {
18.         cout << "Cannot get reciprocal of r1." << endl;
19.     }
20.
21.     try {
22.         cout << rc/r2 << "   " <<rc << "/" << r2 << endl;
23.     } catch (const RationalDivisionByZero& ex) {
24.         cout << "Cannot divide by r2." << endl;
25.     }
26.
27.     cout << "here I am sure..\n";
28.     cout << (r1 < r2) << ' ' << r1 << '<' << r2  << endl;
29.     cout << (r1 <= r2) << ' ' << r1 << "<=" << r2 << endl;
30.     cout << (r1 > r2) << ' ' << r1 << '>' << r2 << endl;
31.     cout << (r1 >= r2) << ' ' << r1 << ">=" << r2 << endl;
32.     cout << (r1 == r2) << ' ' << r1 << "==" << r2 << endl;
33.     cout << (r1 != r2)  << ' ' << r1 << "!=" << r2<< endl;
34.
35.     cout << (r1 < a) << ' ' << r1 << '<' << a << endl;
36.     cout << (r1 <= a) << ' ' << r1 << "<=" << a << endl;
37.     cout << (r1 > a) << ' ' << r1 << '>' << a << endl;
38.     cout << (r1 >= a) << ' ' << r1 << ">=" << a << endl;
39.     cout << (r1 == a) << ' ' << r1 << "==" << a << endl;
40.     cout << (r1 != a) << ' ' << r1 << "!=" << a << endl;
41.
42.     cout << (a < r2) << ' ' << a << '<' << r2 << endl;
43.     cout << (a <= r2) << ' ' << a << "<=" << r2 << endl;
44.     cout << (a > r2)  << ' ' << a << '>' << r2 << endl;
45.     cout << (a >= r2) << ' ' << a << ">=" << r2 << endl;
46.     cout << (a == r2) << ' ' << a << "==" << r2 << endl;
47.     cout << (a != r2) << ' ' << a << "!=" << r2 << endl;
48.     cout << "here I am NOT sure..\n";
49.
50.     cout << rc + a << " = " << rc << " + " <<  a << endl;
51.     cout     << a + rc << " = " << a << " + " <<  rc << endl;
52.     cout     << -rc * r1 << " = " << -rc << " * " <<  r1 << endl;
53.     cout     << (+r1 - r2 * rc) * a << " = " << "(" << +r1 << " - " <<  r2 << " * " << rc << ")" <<  "*" <<  a << endl;
54.
55.     cout  << "    ++" << r1 << "   " << ++r1 << endl;
56.     cout << r1 << endl;
57.     cout  << "   " << r1 << "++" << "    " << r1++ << endl;
58.     cout << r1 << endl;
59.     cout  << "    --" << r1 << "    " << --r1 << endl;
60.     cout << r1 << endl;
61.     cout  << "   " << r1 << "--   " << r1-- << endl;
62.     cout << r1 << endl;
63.     cout << "++++" << r1 << "    " << ++++r1 << endl;
64.     cout << r1 << endl;
65.
66.     cout << "((((" << r1 << "+=" << r2<<")" << "/="<< Rational(-5,3) <<") -=" << rc <<") *=" << a<<")" << "        " << ((((r1 += r2) /= Rational(-5,3)) -= rc) *= a) << endl;
67.     cout <<"(" << r1<< "+=" << r2 <<"/=" << 3<< ")"<<"     " << (r1 += r2 /= 3) << endl;
68.     cout << r1 << endl;
69.     cout << r2 << endl;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top