-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRational.h
113 lines (96 loc) · 2.4 KB
/
Rational.h
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
103
104
105
106
107
108
109
110
111
112
113
/** Rational class to handle rational numbers in a C++ code.
*
* #include "Rational.h" <BR>
* -llib
*
*/
#ifndef RATIONAL_H
#define RATIONAL_H
// SYSTEM INCLUDES
#include<iostream>
// Rational class definition
class Rational {
public:
// LIFECYCLE
/** Default + Overloaded constructor.
*/
Rational(int = 0, int = 1);
// Use compiler-generated copy constructor, assignment, and destructor.
// Rational(const Rational&);
// Rational& operator=(const Rational&);
// ~Rational();
// OPERATIONS
/** Adds two Rational numbers.
* The result is returned in reduced form.
*
* @param rRational Reference to Rational to be added.
*
* @return Reference to Rational of resultant.
*/
const Rational& AddRational(const Rational& rRational);
/** Subtracts two Rational numbers.
* The result is returned in reduced form.
*
* @param rRational Reference to Rational to be subtracted.
*
* @return Reference to Rational of resultant.
*/
const Rational& SubtractRational(const Rational& rRational);
/** Multiplies two Rational numbers.
* The result is returned in reduced form.
*
* @param rRational Reference to Rational to be multiplied.
*
* @return Reference to Rational of resultant.
*/
const Rational& MultiplyRational(const Rational& rRational);
/** Divides two Rational numbers.
* The result is returned in reduced form.
*
* @param rRational Reference to Rational to be divided.
*
* @return Reference to Rational of resultant.
*/
const Rational& DivideRational(const Rational& rRational);
/** Prints Rational number in fraction(a/b) form.
*
* @param void.
*
* @return void.
*/
void PrintFraction()const;
/** Prints Rational number in floating-point(a.b) form.
*
* @param void.
*
* @return void.
*/
void PrintFloat()const;
// ACCESS
// setters
void SetNumerator(int = 0);
void SetDenominator(int = 1);
void SetRational(int = 0, int = 1);
/**
# @overload void SetRational(const Rational&);
*/
void SetRational(const Rational&);
// getters
int GetNumerator()const;
int GetDenominator()const;
const Rational& GetRational()const;
private:
/** utility function that converts the rational into reduced form.
*
* @param void.
*
* @return void.
*/
void ReducedForm();
// DATA MEMBERS
int mNumerator;
int mDenominator;
};
// end class Rational
#endif
// _RATIONAL_H_