forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathTestRational.cpp.html
48 lines (40 loc) · 4.45 KB
/
TestRational.cpp.html
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
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite">
<title>TestRational.cpp</title>
</head>
<body style="background-color:white">
<pre><i><span style="color:#9A1900">// File TestRational.cpp</span></i>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><iostream></span>
<b><span style="color:#0000FF">using</span></b> <b><span style="color:#0000FF">namespace</span></b> std<span style="color:#990000">;</span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000">"Rational.h"</span>
<span style="color:#009900">int</span> <b><span style="color:#000000">main</span></b><span style="color:#990000">()</span> <span style="color:#FF0000">{</span>
<span style="color:#008080">Rational</span> x<span style="color:#990000">,</span> y<span style="color:#990000">,</span> z<span style="color:#990000">;</span>
<i><span style="color:#9A1900">// 1/2 + 1/3 = 5/6</span></i>
x <span style="color:#990000">=</span> <b><span style="color:#000000">Rational</span></b><span style="color:#990000">(</span><span style="color:#993399">1</span><span style="color:#990000">,</span> <span style="color:#993399">2</span><span style="color:#990000">);</span>
y <span style="color:#990000">=</span> <b><span style="color:#000000">Rational</span></b><span style="color:#990000">(</span><span style="color:#993399">1</span><span style="color:#990000">,</span> <span style="color:#993399">3</span><span style="color:#990000">);</span>
z <span style="color:#990000">=</span> x<span style="color:#990000">.</span><b><span style="color:#000000">plus</span></b><span style="color:#990000">(</span>y<span style="color:#990000">);</span>
z<span style="color:#990000">.</span><b><span style="color:#000000">print</span></b><span style="color:#990000">();</span>
<i><span style="color:#9A1900">// 8/9 + 1/9 = 1</span></i>
x <span style="color:#990000">=</span> <b><span style="color:#000000">Rational</span></b><span style="color:#990000">(</span><span style="color:#993399">8</span><span style="color:#990000">,</span> <span style="color:#993399">9</span><span style="color:#990000">);</span>
y <span style="color:#990000">=</span> <b><span style="color:#000000">Rational</span></b><span style="color:#990000">(</span><span style="color:#993399">1</span><span style="color:#990000">,</span> <span style="color:#993399">9</span><span style="color:#990000">);</span>
z <span style="color:#990000">=</span> x<span style="color:#990000">.</span><b><span style="color:#000000">plus</span></b><span style="color:#990000">(</span>y<span style="color:#990000">);</span>
z<span style="color:#990000">.</span><b><span style="color:#000000">print</span></b><span style="color:#990000">();</span>
<i><span style="color:#9A1900">// 4/17 * 7/3 = 28/51</span></i>
x <span style="color:#990000">=</span> <b><span style="color:#000000">Rational</span></b><span style="color:#990000">(</span><span style="color:#993399">4</span><span style="color:#990000">,</span> <span style="color:#993399">17</span><span style="color:#990000">);</span>
y <span style="color:#990000">=</span> <b><span style="color:#000000">Rational</span></b><span style="color:#990000">(</span><span style="color:#993399">7</span><span style="color:#990000">,</span> <span style="color:#993399">3</span><span style="color:#990000">);</span>
z <span style="color:#990000">=</span> x<span style="color:#990000">.</span><b><span style="color:#000000">times</span></b><span style="color:#990000">(</span>y<span style="color:#990000">);</span>
z<span style="color:#990000">.</span><b><span style="color:#000000">print</span></b><span style="color:#990000">();</span>
<i><span style="color:#9A1900">// 0/6 = 0</span></i>
x <span style="color:#990000">=</span> <b><span style="color:#000000">Rational</span></b><span style="color:#990000">(</span><span style="color:#993399">0</span><span style="color:#990000">,</span> <span style="color:#993399">6</span><span style="color:#990000">);</span>
x<span style="color:#990000">.</span><b><span style="color:#000000">print</span></b><span style="color:#990000">();</span>
<b><span style="color:#0000FF">return</span></b> <span style="color:#993399">0</span><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
</pre>
</body>
</html>