/* * rational.h * * Created on: 28.02.2013 * Author: trifon */ #ifndef RATIONAL_H_ #define RATIONAL_H_ #include class Rational { private: int numer, denom; void reduce(); public: // конструктори // Rational(); Rational(int n=0, int d=1) ; Rational(Rational const&); Rational(double); // селектори int getNumerator() const { return numer; } int getDenominator() const; int getNumeratorPlus(int x) const { return numer + x; } void print() const; // мутатори void read(); friend Rational operator/(int, Rational const&); friend Rational operator+(int x, Rational const& r) { return Rational(x * r.denom + r.numer, r.denom); } int& operator[](int i) { if (i == 0) return numer; if (i == 1) return denom; cout << "Грешка!" << endl; return numer; } friend ostream& operator<<(ostream&, Rational const&); friend istream& operator>>(istream&, Rational&); double operator()() const; /* operator int() const; operator double() const; */ private: class GCD { private: int x, y; public: GCD(int a, int b) { x = abs(a); y = abs(b); // !!! x = numer; // !!! y = denom; // Rational r; // r.print(); // cout << r.numer; } int calculate(); }; };// rat1, rat2; // не може да се предефинира! /* class Rational { private: int n, d; }; */ Rational add(Rational,Rational); #endif /* RATIONAL_H_ */