moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kbruch / src / ratio.h
blob3e3ca44af3dfc717ab6dbb5c146165b0cf0fe4cf
1 /***************************************************************************
2 ratio.h - class ratio
3 -------------------
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 /***************************************************************************
10 * *
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. *
15 * *
16 ***************************************************************************/
18 #ifndef RATIO_H
19 #define RATIO_H
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
27 * this task.
28 * \author Sebastian Stein */
29 class ratio
31 public:
32 /** constructor */
33 ratio(int pnumerator = 0, int pdenominator = 1);
35 /** copy constructor */
36 ratio(const ratio & copy_ratio);
38 /** destructor */
39 ~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 */
81 void reziproc();
83 /** reduce the ratio */
84 void reduce();
85 private:
86 /** numerator */
87 int m_numerator;
89 /** denominator */
90 int m_denominator;
92 /** change sign of the ratio */
93 void change_sign();
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);
102 #endif