Ilya_konstantinov

Untitled

Oct 2nd, 2025 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include "frac.h"
  4.  
  5. int main() {
  6.     Fraction frac;
  7.     std::string command;
  8.    
  9.     std::cin >> frac;
  10.    
  11.     while (std::cin >> command) {
  12.         if (command == "+") {
  13.             Fraction other;
  14.             std::cin >> other;
  15.             frac = frac + other;
  16.         }
  17.         else if (command == "-") {
  18.             Fraction other;
  19.             std::cin >> other;
  20.             frac = frac - other;
  21.         }
  22.         else if (command == "*") {
  23.             Fraction other;
  24.             std::cin >> other;
  25.             frac = frac * other;
  26.         }
  27.         else if (command == "/") {
  28.             Fraction other;
  29.             std::cin >> other;
  30.             frac = frac / other;
  31.         }
  32.         else if (command == "+=") {
  33.             Fraction other;
  34.             std::cin >> other;
  35.             frac += other;
  36.         }
  37.         else if (command == "-=") {
  38.             Fraction other;
  39.             std::cin >> other;
  40.             frac -= other;
  41.         }
  42.         else if (command == "*=") {
  43.             Fraction other;
  44.             std::cin >> other;
  45.             frac *= other;
  46.         }
  47.         else if (command == "/=") {
  48.             Fraction other;
  49.             std::cin >> other;
  50.             frac /= other;
  51.         }
  52.         else if (command == "=") {
  53.             Fraction other;
  54.             std::cin >> other;
  55.             frac = other;
  56.         }
  57.         else if (command == "show" || command == "print") {
  58.             std::cout << frac << '\n';
  59.         }
  60.         else if (command == "double") {
  61.             std::cout << std::fixed << std::setprecision(6) << static_cast<double>(frac) << '\n';
  62.         }
  63.         else if (command == "exit" || command == "quit") {
  64.             break;
  65.         }
  66.     }
  67.    
  68.     std::cout << (frac < Fraction(1)) << '\n';
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment