Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include "frac.h"
- int main() {
- Fraction frac;
- std::string command;
- std::cin >> frac;
- while (std::cin >> command) {
- if (command == "+") {
- Fraction other;
- std::cin >> other;
- frac = frac + other;
- }
- else if (command == "-") {
- Fraction other;
- std::cin >> other;
- frac = frac - other;
- }
- else if (command == "*") {
- Fraction other;
- std::cin >> other;
- frac = frac * other;
- }
- else if (command == "/") {
- Fraction other;
- std::cin >> other;
- frac = frac / other;
- }
- else if (command == "+=") {
- Fraction other;
- std::cin >> other;
- frac += other;
- }
- else if (command == "-=") {
- Fraction other;
- std::cin >> other;
- frac -= other;
- }
- else if (command == "*=") {
- Fraction other;
- std::cin >> other;
- frac *= other;
- }
- else if (command == "/=") {
- Fraction other;
- std::cin >> other;
- frac /= other;
- }
- else if (command == "=") {
- Fraction other;
- std::cin >> other;
- frac = other;
- }
- else if (command == "show" || command == "print") {
- std::cout << frac << '\n';
- }
- else if (command == "double") {
- std::cout << std::fixed << std::setprecision(6) << static_cast<double>(frac) << '\n';
- }
- else if (command == "exit" || command == "quit") {
- break;
- }
- }
- std::cout << (frac < Fraction(1)) << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment