Untitled
unknown
plain_text
2 years ago
987 B
2
Indexable
Never
#include <iostream> #include <stdlib.h> using namespace std; class Fraction { private: int first, second; int nod(int a, int b) { while (a && b) { if (a > b) { a = a % b; } else { b = b % a; } } return max(a, b); } int common_denominator = nod(first, second); int reduce(int n, int common_denominator) { n /= common_denominator; return n; } public: Fraction() { cout << "Числитель и знаменатель не определены." << endl; } Fraction(int first, int second) : first(first), second(second) {} void show_fraction() { first = reduce(first, common_denominator); second = reduce(second, common_denominator); cout << "Обыкновенная дробь: " << first << "/" << second << endl; cout << "Десятичная дробь: " << (float) first / second << endl; } }; int main() { setlocale(0, ""); Fraction my_fraction(3, 9); my_fraction.show_fraction(); }