blob: 3e3ca44af3dfc717ab6dbb5c146165b0cf0fe4cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/***************************************************************************
ratio.h - class ratio
-------------------
begin : Tue Nov 27 16:40:42 CET 2001
copyright : (C) 2001-2004 by Sebastian Stein
email : seb.kde@hpfsc.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef RATIO_H
#define RATIO_H
#include <qtextstream.h>
/** Represents a ratio
* This class represents 1 ratio. There are several functions provided to
* modify the numerator and denominator. It is also possible to calculate with
* objects of the class ratio. Overloaded operation functions are provided for
* this task.
* \author Sebastian Stein */
class ratio
{
public:
/** constructor */
ratio(int pnumerator = 0, int pdenominator = 1);
/** copy constructor */
ratio(const ratio & copy_ratio);
/** destructor */
~ratio();
/** returns the ratio as QTextStream object */
QTextStream & display(QTextStream & str) const;
/** returns the numerator */
int numerator() const;
/** returns the denominator */
int denominator() const;
/** set numerator and reduce the ratio */
void setNumerator(int pnumerator = 0, bool reduce = true);
/** set denominator and reduce the ratio */
void setDenominator(int pdenominator = 1, bool reduce = true);
/** operator overloading for: c = object + summand */
ratio operator+(ratio addend);
/** operator overloading for: c = object - subtrahend */
ratio operator-(ratio subtrahend);
/** operator overloading for: c = object * factor */
ratio operator*(ratio factor);
/** operator overloading for: c = object / divisor */
ratio operator/(ratio divisor);
/** set numerator with dummy and denominator = 1 */
ratio operator=(int dummy);
/** compares the current ratio with a given one */
bool operator==(ratio right);
/** compares the current ratio with a given one */
bool operator<(ratio right);
/** compares the current ratio with a given one */
bool operator>(ratio right);
/** exchange numerator and denominator */
void reziproc();
/** reduce the ratio */
void reduce();
private:
/** numerator */
int m_numerator;
/** denominator */
int m_denominator;
/** change sign of the ratio */
void change_sign();
}
;
/* ------ some prototyps of non class functions ------ */
/** it is possible to code: cout << ratio_object << endl; */
QTextStream & operator<<(QTextStream & str, const ratio & pratio);
#endif
|