-
Notifications
You must be signed in to change notification settings - Fork 0
/
program18-3.cc
67 lines (46 loc) · 915 Bytes
/
program18-3.cc
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
// Working with Fractions in C++
#include <iostream>
// Define Class
class Fraction
{
private:
int numerator;
int denominator;
public:
void setNumerator(int num);
void setDenominator(int denom);
int Numerator(void);
int Denominator(void);
void print(Fraction f);
};
// Define Class Methods (Setters, Getters, print)
void Fraction::setNumerator(int num)
{
numerator = num;
}
void Fraction::setDenominator(int denom)
{
denominator = denom;
}
int Fraction::Numerator(void)
{
return numerator;
}
int Fraction::Denominator(void)
{
return denominator;
}
void Fraction::print(Fraction f)
{
std::cout << "The value of the fraction is " << numerator <<
'/' << denominator << '\n';
}
// Main Routine (analogous to C)
int main(void)
{
Fraction myFract;
myFract.setNumerator(1);
myFract.setDenominator(3);
myFract.print(myFract);
return 0;
}