-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFraction.h
50 lines (38 loc) · 1.05 KB
/
Fraction.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
//
// Created by Frank Yang on 2023/9/1.
//
#include <iostream>
#ifndef FRACTIONUTILITY_FRACTION_H
#define FRACTIONUTILITY_FRACTION_H
class Fraction
{
private:
int numerator;
unsigned int denominator;
public:
explicit Fraction(int num=0, unsigned int deno=1);
inline void show() const
{
if (denominator == 1) std::cout << numerator << std::endl;
else if (numerator) std::cout << numerator << "/" << denominator << std::endl;
else std::cout << 0 << std::endl;
}
void update();
void modify(int num, unsigned int deno);
std::string fractionToString() const;
/* Operator overloading */
// OPPOSITE
Fraction getOpposite() const;
// PLUS
Fraction operator+ (const Fraction &f) const;
//MINUS
Fraction operator- (const Fraction &f) const;
// MULTIPLICATION
Fraction operator* (const Fraction &f) const;
// RECIPROCAL
Fraction getReciprocal() const;
// DIVISION
Fraction operator/ (const Fraction &f) const;
~Fraction();
};
#endif //FRACTIONUTILITY_FRACTION_H