1 /***************************************************************************
4 begin : Tue Nov 27 16:40:42 CET 2001
5 copyright : (C) 2001-2004 by Sebastian Stein
6 email : seb.kde@hpfsc.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
21 #include <qtextstream.h>
23 /** Represents a ratio
24 * This class represents 1 ratio. There are several functions provided to
25 * modify the numerator and denominator. It is also possible to calculate with
26 * objects of the class ratio. Overloaded operation functions are provided for
28 * \author Sebastian Stein */
33 ratio(int pnumerator
= 0, int pdenominator
= 1);
35 /** copy constructor */
36 ratio(const ratio
& copy_ratio
);
41 /** returns the ratio as QTextStream object */
42 QTextStream
& display(QTextStream
& str
) const;
44 /** returns the numerator */
45 int numerator() const;
47 /** returns the denominator */
48 int denominator() const;
50 /** set numerator and reduce the ratio */
51 void setNumerator(int pnumerator
= 0, bool reduce
= true);
53 /** set denominator and reduce the ratio */
54 void setDenominator(int pdenominator
= 1, bool reduce
= true);
56 /** operator overloading for: c = object + summand */
57 ratio
operator+(ratio addend
);
59 /** operator overloading for: c = object - subtrahend */
60 ratio
operator-(ratio subtrahend
);
62 /** operator overloading for: c = object * factor */
63 ratio
operator*(ratio factor
);
65 /** operator overloading for: c = object / divisor */
66 ratio
operator/(ratio divisor
);
68 /** set numerator with dummy and denominator = 1 */
69 ratio
operator=(int dummy
);
71 /** compares the current ratio with a given one */
72 bool operator==(ratio right
);
74 /** compares the current ratio with a given one */
75 bool operator<(ratio right
);
77 /** compares the current ratio with a given one */
78 bool operator>(ratio right
);
80 /** exchange numerator and denominator */
83 /** reduce the ratio */
92 /** change sign of the ratio */
97 /* ------ some prototyps of non class functions ------ */
99 /** it is possible to code: cout << ratio_object << endl; */
100 QTextStream
& operator<<(QTextStream
& str
, const ratio
& pratio
);