/
plato
/
overloading
Обзор
Документация
Войти
/
plato
/
overloading
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
ex1/main.cpp
56 строк
1 KB
Evanivan
init commit
13 окт 2025, 01:23
13 окт 2025, 01:23
d414646
Код
Авторство
О чём код?
#include <iostream> #include <string> #include <exception> class Fraction { private: int numerator_; int denominator_; public: Fraction(int numerator, int denominator) { numerator_ = numerator; denominator_ = denominator; } bool operator==(Fraction other) { return numerator_ * other.denominator_ == denominator_ * other.numerator_; } bool operator!=(Fraction other) { return !(*this == other); } bool operator<(Fraction other) { return (this->numerator_ * other.denominator_) < (this->denominator_ * other.numerator_); } bool operator>(Fraction other) { return (other < *this); } bool operator<=(Fraction other) { return !(other < *this); } bool operator>=(Fraction other) { return !(other > *this); } }; 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; }