/
AirLexa
/
origin
Обзор
Документация
Войти
/
AirLexa
/
origin
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
Lesson_09/Task_1/Task_1.cpp
55 строк
1 KB
AirLexa
добавил Lesson_09/Task_1/Task_1.cpp
27 окт 2025, 12:57
27 окт 2025, 12:57
850fd26
Код
Авторство
О чём код?
#include <iostream> class Fraction { private: int numerator_; int denominator_; public: Fraction(int numerator, int denominator) { numerator_ = numerator; denominator_ = denominator; } double div_() { return static_cast<double>(numerator_) / static_cast<double>(denominator_); } bool operator==(Fraction other) { return div_() == other.div_(); } bool operator!=(Fraction other) { return !(*this == other); } bool operator<(Fraction other) { return div_() < other.div_(); } bool operator>(Fraction other) { return !(*this < other) && *this != other; } bool operator<=(Fraction other) { return *this < other || *this == other; } bool operator>=(Fraction other) { return *this > other || *this == other; } }; int main() { Fraction f1(4, 3); Fraction f2(6, 11); std::cout << "f1" << ((f1 == f2) ? " == " : " not == ") << "f2" << '\n'; std::cout << "f1" << ((f1 != f2) ? " != " : " not != ") << "f2" << '\n'; std::cout << "f1" << ((f1 < f2) ? " < " : " not < ") << "f2" << '\n'; std::cout << "f1" << ((f1 > f2) ? " > " : " not > ") << "f2" << '\n'; std::cout << "f1" << ((f1 <= f2) ? " <= " : " not <= ") << "f2" << '\n'; std::cout << "f1" << ((f1 >= f2) ? " >= " : " not >= ") << "f2" << '\n'; return 0; }