{"id":31,"date":"2024-08-01T18:35:48","date_gmt":"2024-08-01T18:35:48","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalC%2B%2BProgramming\/?page_id=31"},"modified":"2025-01-20T20:21:56","modified_gmt":"2025-01-20T20:21:56","slug":"assignment-2","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/assignments\/assignment-2\/","title":{"rendered":"Assignment 2"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"A_Rational_Class\"><\/span>A Rational Class<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"has-text-align-left\"><strong>Note:<\/strong><\/p>\n\n\n\n<p>This assignment is intended to give you some exposure to writing a relatively simple C++ class. In particular, it is intended to show you how much the C++ compiler is doing for you automatically &#8212; sometimes it does what you want, and sometimes not.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Rational_Numbers\"><\/span>Rational Numbers<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Rational numbers are those numbers that can be represented as ratios of integers:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px\"><code>1\/2\t 57\/234\t -2\/3\t23\/405<\/code><\/pre>\n\n\n\n<p>(Note that all rational numbers are real numbers, but not all real numbers are, or can be, rational numbers.)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Rational_Class\"><\/span>The <code>Rational<\/code> Class<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Implement a class&nbsp;<strong>Rational<\/strong>, which supports rational numbers. The class should support the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Two <strong><code>int<\/code><\/strong> data members, <strong><code>numerator<\/code><\/strong> and <strong><code>denominator<\/code><\/strong>, which are private to the class. <br>These values will be kept in&nbsp;<em>normalized<\/em>&nbsp;form; that is, the value of the denominator will be the smallest integer that can represent the ratio. For example, 3\/6 is not normalized; 1\/2 is: 3\/6 can be normalized by dividing both top and bottom by 3, to produce 1\/2. If the&nbsp;<strong>Rational<\/strong>&nbsp;is negative, then only the numerator is negative &#8212; the denominator is always positive. Clearly, the denominator should never be allowed to be zero.<\/li>\n\n\n\n<li>Initialization of a class instance from a single <strong><code>int<\/code><\/strong>. The value of the <code><strong>int<\/strong><\/code> will be the numerator of the ratio.<\/li>\n\n\n\n<li>Initialization of a class instance from two <strong><code>int<\/code><\/strong>s. The values of the two <strong><code>int<\/code><\/strong>s will be the numerator and the denominator of the ratio.<\/li>\n\n\n\n<li>Instance cleanup (<em>if necessary; if not necessary, explain why not<\/em>)<\/li>\n\n\n\n<li>Initialization of a class instance from another instance of class&nbsp;<strong>Rational<\/strong>.<\/li>\n\n\n\n<li>Assignment of one&nbsp;<strong>Rational<\/strong>&nbsp;to another (<em>how is this different from the above?<\/em>)<\/li>\n\n\n\n<li>Assignment of an <strong><code>int<\/code><\/strong> to a&nbsp;<strong>Rational<\/strong>.<\/li>\n\n\n\n<li>Assignment of a&nbsp;<strong>Rational<\/strong>&nbsp;to a <strong><code>double<\/code><\/strong>.<\/li>\n\n\n\n<li>Assignment of a <strong><code>double<\/code><\/strong> to a&nbsp;<strong>Rational<\/strong>&nbsp;should be&nbsp;<strong><em>prohibited<\/em><\/strong>&nbsp;(<em>remember, mathematically, not all real numbers are rational numbers<\/em>).<\/li>\n\n\n\n<li>The addition of two&nbsp;<strong>Rational<\/strong>s (<strong><code>Rational<\/code><\/strong> + <strong><code>Rational<\/code><\/strong>) to produce another&nbsp;<strong>Rational<\/strong>.<\/li>\n\n\n\n<li>The addition of a&nbsp;<strong>Rational<\/strong>&nbsp;and a <strong><code>double<\/code><\/strong> (<strong><code>Rational<\/code><\/strong> + <strong><code>double<\/code><\/strong>) to produce a <strong><code>double<\/code><\/strong>.<\/li>\n\n\n\n<li>The addition of a <code><strong>double<\/strong><\/code> and a&nbsp;<strong>Rational<\/strong>&nbsp;(<strong><code>double<\/code><\/strong> + <strong><code>Rational<\/code><\/strong>) to produce a <strong><code>double<\/code><\/strong>.<\/li>\n\n\n\n<li>The subtraction of two&nbsp;<strong>Rational<\/strong>s (<strong><code>Rational<\/code><\/strong> &#8211; <strong><code>Rational<\/code><\/strong>) to produce another&nbsp;<strong>Rational<\/strong>.<\/li>\n\n\n\n<li>The subtraction of a <strong><code>double<\/code><\/strong> from a&nbsp;<strong>Rational<\/strong>&nbsp;(<strong><code>Rational<\/code><\/strong> &#8211; <strong><code>double<\/code><\/strong>) to produce a <strong><code>double<\/code><\/strong>.<\/li>\n\n\n\n<li>The subtraction of a&nbsp;<strong>Rational<\/strong>&nbsp;from a <strong><code>double<\/code><\/strong> (<strong><code>double<\/code><\/strong> &#8211; <strong><code>Rational<\/code><\/strong>) to produce a <strong><code>double<\/code><\/strong>.<\/li>\n\n\n\n<li>The multiplication of two&nbsp;<strong>Rational<\/strong>s (<strong><code>Rational<\/code><\/strong> * <strong><code>Rational<\/code><\/strong>) to produce another&nbsp;<strong>Rational<\/strong>.<\/li>\n\n\n\n<li>The multiplication of a&nbsp;<strong>Rationa<\/strong>l with a <strong><code>double<\/code><\/strong> (<strong><code>Rational<\/code><\/strong> * <strong><code>double<\/code><\/strong>) to produce a <strong><code>double<\/code><\/strong>.<\/li>\n\n\n\n<li>The multiplication of a double with a&nbsp;<strong>Rational<\/strong>&nbsp;(<strong><code>double<\/code><\/strong> * <strong><code>Rational<\/code><\/strong>) to produce a <strong><code>double<\/code><\/strong>.<\/li>\n\n\n\n<li>The division of two&nbsp;<strong>Rational<\/strong>s (<strong><code>Rational<\/code><\/strong> \/ <strong><code>Rational<\/code><\/strong>) to produce a&nbsp;<strong>Rational<\/strong>.<\/li>\n\n\n\n<li>The division of a&nbsp;<strong>Rational<\/strong>&nbsp;by a <strong><code>double<\/code><\/strong> (<strong><code>Rational<\/code><\/strong> \/ <strong><code>double<\/code><\/strong>) to produce a <strong><code>double<\/code><\/strong>.<\/li>\n\n\n\n<li>The division of a double by a&nbsp;<strong>Rational<\/strong>&nbsp;(<strong><code>double<\/code><\/strong> \/ <strong><code>Rational<\/code><\/strong>) to produce a <strong><code>double<\/code><\/strong>.<\/li>\n\n\n\n<li>The negation (unary minus) of a&nbsp;<strong>Rational<\/strong>&nbsp;(-<strong><code>Rational<\/code><\/strong>) to produce another&nbsp;<strong>Rational<\/strong>.<\/li>\n\n\n\n<li>The unary plus of a&nbsp;<strong>Rational<\/strong>&nbsp;(+<strong><code>Rational<\/code><\/strong>) to produce another&nbsp;<strong>Rational<\/strong>.<\/li>\n\n\n\n<li>A <strong><code>Print()<\/code><\/strong> member function that prints out the value of a&nbsp;<strong>Rational<\/strong>&nbsp;in its normalized form:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px;padding-left:50px\"><code><strong><code>(3\/4)<\/code><\/strong><em>(including the parentheses)<\/em> <\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Strategy\"><\/span>Strategy<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>It is very tempting to implement the above by writing all the constructors, methods, operators, etc. from the start. However, you may be surprised how much will work &#8216;magically&#8217;! It is not necessary to map each of the above operations into a specific class method (or normal function, as the case may be). <\/p>\n\n\n\n<p>I strongly suggest that you take a <em>minimalist approach<\/em>: start with the smallest class you can, and work from there, incrementally. See how much that minimal class already supports, and&nbsp;<em>understand why and how it supports it<\/em>. Then add what you need, as you discover what doesn&#8217;t work yet. As you add,&nbsp;<em>keep trying to understand how the new stuff works (or why it doesn&#8217;t work), and how things change as you add that functionality.<\/em>&nbsp;Use this as a learning experience! (<em>Please document what you did &#8211; as much for your own benefit, as for mine.<\/em>)<\/p>\n\n\n\n<p>Here&#8217;s a suggested approach (<em><strong>Please provide answers to the questions!<\/strong><\/em>):<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_1\"><\/span>Step 1<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>Create, in file&nbsp;<strong><code>rational.h<\/code><\/strong>, a class&nbsp;<strong>Rational<\/strong>, with private data members <strong><code>numerator<\/code><\/strong> and <strong><code>denominator<\/code><\/strong>, and a private member function&nbsp;<strong><code>Normalize()<\/code><\/strong>, which does basic checking of numerator and denominator values, and reduces the ratio to its normal form (i.e. <strong><code>numerator<\/code><\/strong> and <strong><code>denominator<\/code><\/strong> contain the smallest possible integer values).<br><br>Write a public constructor to construct a&nbsp;<strong>Rational<\/strong>&nbsp;from two&nbsp;<strong><code>int<\/code><\/strong>s, with appropriate default arguments, and a public member function&nbsp;<strong><code>Print()<\/code><\/strong>, to print out the&nbsp;<strong>Rational<\/strong>&nbsp;as described earlier (<strong><code>Print()<\/code><\/strong>&nbsp;will help with debugging&#8230;). In addition, create two public member functions, <strong><code>Numerator()<\/code><\/strong> and <strong><code>Denominator()<\/code><\/strong>. <br><br>Here&#8217;s the class to start off with:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  rational.h\n\/\/  Assignment 2: Rational Class\n\/\/\n\/\/  Created by Bryan Higgs on 10\/28\/24.\n\/\/\n\n#ifndef rational_h\n#define rational_h\n\nclass Rational\n{\n  public:\n    \/\/ Constructor\n    Rational(int num = 0, int den = 1); \/\/ &lt;implement here&gt;\n\n    \/\/ Print out the contents of the instance\n    void Print();   \/\/ Implemented in the rational.cpp file\n\n    \/\/ Access member functions\n    int Numerator()     { return m_num; }\n    int Denominator()   { return m_den; }\n\n  private:\n    \/\/ Private functions\n    void Normalize(); \/\/ To be implemented in the rational.cpp file\n\n    \/\/ Private data\n    int  m_num;    \/\/ numerator\n    int  m_den;    \/\/ denominator\n};\n\n#endif \/* rational_h *\/\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  rational.h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Assignment 2: Rational Class<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 10\/28\/24.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#ifndef<\/span><span style=\"color: #0000FF\"> rational_h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#define<\/span><span style=\"color: #0000FF\"> rational_h<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">class<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Rational<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">    \/\/ Constructor<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">num<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">den<\/span><span style=\"color: #000000\"> = <\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">);<\/span><span style=\"color: #008000\"> \/\/ &lt;implement here&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">    \/\/ Print out the contents of the instance<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><span style=\"color: #008000\">   \/\/ Implemented in the rational.cpp file<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">    \/\/ Access member functions<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Numerator<\/span><span style=\"color: #000000\">()     { <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> m_num; }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Denominator<\/span><span style=\"color: #000000\">()   { <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> m_den; }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">private:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">    \/\/ Private functions<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">Normalize<\/span><span style=\"color: #000000\">();<\/span><span style=\"color: #008000\"> \/\/ To be implemented in the rational.cpp file<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">    \/\/ Private data<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\">  m_num;<\/span><span style=\"color: #008000\">    \/\/ numerator<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\">  m_den;<\/span><span style=\"color: #008000\">    \/\/ denominator<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#endif<\/span><span style=\"color: #008000\"> \/* rational_h *\/<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>Your job is to fill in the&nbsp;<strong>&lt;implement here&gt;<\/strong>, and implement the&nbsp;<strong><code>Print()<\/code><\/strong> and&nbsp;<strong><code>Normalize()<\/code><\/strong> functions in the&nbsp;<strong><code>rational.cpp<\/code><\/strong> file.<\/p>\n\n\n\n<p>Once you have completed this step, you should be able to do simple construction of&nbsp;<strong>Rational<\/strong>&nbsp;types. Try this out by writing a separate&nbsp;<strong><code>testrat.cpp<\/code><\/strong> file, which will include the&nbsp;<strong><code>rational.h<\/code><\/strong> file, and by linking the two objects produced from compiling the&nbsp;<strong><code>rational.cpp<\/code><\/strong> and the&nbsp;<strong><code>testrat.cpp<\/code><\/strong> files.<\/p>\n<\/div>\n<\/div>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_2\"><\/span>Step 2<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>Without adding anything else to your&nbsp;<strong>Rational<\/strong>&nbsp;class, try defining an instance of class&nbsp;<strong>Rational<\/strong>,&nbsp;<em>initializing<\/em>&nbsp;it from another instance of class&nbsp;<strong>Rational<\/strong>. Does it work? If so, can you explain why?<br><br>Now (again without adding anything to your class), try&nbsp;<em>assigning<\/em>&nbsp;one instance of class&nbsp;<strong>Rational<\/strong>&nbsp;to another. Again, does it work? If so, why?<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_3\"><\/span>Step 3<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>What about assigning other types to an instance of class&nbsp;<strong>Rational<\/strong>? Try assigning an&nbsp;<strong><code>int<\/code><\/strong>&nbsp;(like the integer constant&nbsp;3) to a&nbsp;<strong>Rational<\/strong>. Does it work? If so, why, and is it reasonably efficient? If not, how would you make it more efficient?<br><br>What about assigning a&nbsp;<strong><code>double<\/code><\/strong>&nbsp;(like&nbsp;45.6) to a&nbsp;<strong>Rational<\/strong>? Does it work? Should it work?&nbsp;<\/p>\n\n\n\n<p><strong><em><u>NO!<\/u><\/em><\/strong>&nbsp;In general, a&nbsp;<strong><code>double<\/code><\/strong>&nbsp;value cannot be expressed mathematically as an exact rational number. So how would you prevent this assignment from working?<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_4\"><\/span>Step 4<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>Now try assigning a&nbsp;<strong>Rational<\/strong>&nbsp;to a <strong><code>double<\/code><\/strong>. Does it work? Why?\/Why not? What will you do about it?<br><br>Once you have&nbsp;<strong><code>double<\/code><\/strong> = <strong><code>Rational<\/code><\/strong>&nbsp;assignment working, try implementing the <em>unary minus<\/em> and <em>unary plus<\/em> operators:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>-Rational\t\n+Rational<\/strong><\/code><\/pre>\n\n\n\n<p>What should the type of this expression be? Does it work? What do you need to make it work?<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_5\"><\/span>Step 5<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>Now, try adding the binary (that is, 2-operand) arithmetic operations. <\/p>\n\n\n\n<p>Start with <em>addition<\/em>. First look at:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>Rational + Rational<\/strong><\/code><\/pre>\n\n\n\n<p>What should the type of this expression be? Does it work? What do you need to make it work?<\/p>\n\n\n\n<p>Once you have&nbsp;<strong><code>Rational<\/code><\/strong>+<strong><code>Rational<\/code><\/strong>&nbsp;working, try:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>Rational + double<\/strong><\/code><\/pre>\n\n\n\n<p>What should the type of this expression be? What in fact happens, and why? How do you make this work?<\/p>\n\n\n\n<p>Once you have&nbsp;<strong><code>Rational<\/code><\/strong>+<strong><code>double<\/code><\/strong>&nbsp;working, try reversing the order of the types:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>double + Rational<\/strong><\/code><\/pre>\n\n\n\n<p>What should the type of this expression be? Can you explain what you observe? What do you have to do to make this work?<\/p>\n\n\n\n<p>Now implement&nbsp;<em>subtraction<\/em>,&nbsp;<em>multiplication<\/em>&nbsp;and&nbsp;<em>division<\/em>&nbsp;for each of these combinations of types.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_6\"><\/span>Step 6<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>Make sure that a call to a constructor&nbsp;<strong><code>Rational<\/code><\/strong>(<strong><code>double<\/code><\/strong>, <strong><code>double<\/code><\/strong>)&nbsp;&#8212; for example:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>Rational r(3.0, 5.1);<\/strong><\/code><\/pre>\n\n\n\n<p>(or any other case where such a constructor might be called, explicitly or implicitly) &#8212;&nbsp;<strong><em>fails<\/em><\/strong>&nbsp;at compile time.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_7\"><\/span>Step 7<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p>At this point, most operations should be working. Once you have cleaned up any that are not, you now have three things to do:<\/p>\n\n\n\n<ol start=\"1\" style=\"list-style-type:lower-roman\" class=\"wp-block-list\">\n<li><strong>Check that each operation is indeed working, by thorough testing.<\/strong><\/li>\n\n\n\n<li><strong>Understand completely how each operation works.<\/strong><\/li>\n\n\n\n<li><strong>Determine whether each operation works sufficiently&nbsp;<em>accurately<\/em>&nbsp;(no undue loss of precision) and&nbsp;<em>efficiently<\/em>&nbsp;(no undue loss of performance).<\/strong><\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Normalize\"><\/span>How to Normalize<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>You will find that the following code for evaluating the\u00a0<em>greatest common divisor<\/em>\u00a0(GCD) of two integers will help you normalize your <strong><code>Rational<\/code><\/strong> class instances. <em>I expect you to turn this code into a private member function of class <strong><code>Rational<\/code><\/strong>, called\u00a0<strong><code>Normalize()<\/code><\/strong>.<\/em><\/p>\n\n\n\n<p>The function\u00a0<strong><code>Normalize()<\/code><\/strong> takes no arguments. <\/p>\n\n\n\n<p>Here is some code that implements a\u00a0<em>greatest common divisor<\/em>\u00a0function.\u00a0<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:60%\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  gcd.cpp\n\/\/  Assignment 2: Rational Class\n\/\/\n\/\/  Created by Bryan Higgs on 10\/31\/24.\n\/\/\n\n\/\/\n\/\/  Compute the greatest common divisor\n\/\/  of two integers, m and n.\n\/\/  (Uses Euclid's algorithm)\n\/\/\n\nint gcd(int m, int n)\n{\n  if ( (m == 0) || (n == 0) )\n    return 1;\n\n  if (m &lt; 0)\n    m = -m;\n  if (n &lt; 0)\n    n = -n;\n\n  \/\/ Euclid's algorithm...\n  int a, b, r;\n\n  if (n &gt; m)\n  {\n    a = n;\n    b = m;\n  }\n  else\n  {\n    a = m;\n    b = n;\n  }\n  r = 1;\n  while (r &gt; 0)\n  {\n    r = a % b;\n    a = b;\n    b = r;\n  }\n  return a;\n}\n\n#ifdef TESTING\n\/\/ This code is included for testing purposes.\n\/\/ Simply define the macro TESTING, and recompile this module;\n\/\/ it will be a standalone program that tests the above function.\n\/\/ Once you have completed the testing, undefine the macro TESTING,\n\/\/ and recompile.\n\/\/\n\/\/ NOTE: Most C++ compilers provide a way of defining a macro at\n\/\/       compile time.  If you are using a compiler from the command\n\/\/       line, there is usually a switch of some kind (-D ?) to support\n\/\/       this.  If you are using an IDE (Interactive Development\n\/\/       Environment), you will have to learn how to define a macro at\n\/\/       compile time from within the IDE.\n\n#include &lt;iostream&gt;\n\nstatic void print_gcd(int m, int n)\n{\n  std::cout &lt;&lt; &quot;GCD(&quot; &lt;&lt; m &lt;&lt; ',' &lt;&lt; n &lt;&lt; &quot;) = &quot; &lt;&lt; gcd(m, n) &lt;&lt; '\\n';\n}\n\nint main(int argc, const char * argv[])\n{\n  print_gcd(5, 4);\n  print_gcd(10, 20);\n  print_gcd(3, 9);\n  print_gcd(121, 99);\n  return 0;\n}\n#endif  \/\/ TESTING\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  gcd.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Assignment 2: Rational Class<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 10\/31\/24.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Compute the greatest common divisor<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  of two integers, m and n.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  (Uses Euclid&#39;s algorithm)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">gcd<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">m<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">n<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> ( (m == <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">) || (n == <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">) )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (m &lt; <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    m = -m;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (n &lt; <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    n = -n;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">  \/\/ Euclid&#39;s algorithm...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> a, b, r;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">if<\/span><span style=\"color: #000000\"> (n &gt; m)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    a = n;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    b = m;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">else<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    a = m;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    b = n;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  r = <\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">while<\/span><span style=\"color: #000000\"> (r &gt; <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    r = a % b;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    a = b;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    b = r;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> a;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#ifdef<\/span><span style=\"color: #0000FF\"> TESTING<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ This code is included for testing purposes.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ Simply define the macro TESTING, and recompile this module;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ it will be a standalone program that tests the above function.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ Once you have completed the testing, undefine the macro TESTING,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ and recompile.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ NOTE: Most C++ compilers provide a way of defining a macro at<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/       compile time.  If you are using a compiler from the command<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/       line, there is usually a switch of some kind (-D ?) to support<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/       this.  If you are using an IDE (Interactive Development<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/       Environment), you will have to learn how to define a macro at<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/       compile time from within the IDE.<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;iostream&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">void<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">print_gcd<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">m<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">n<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;GCD(&quot;<\/span><span style=\"color: #000000\"> &lt;&lt; m &lt;&lt; <\/span><span style=\"color: #A31515\">&#39;,&#39;<\/span><span style=\"color: #000000\"> &lt;&lt; n &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;) = &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; <\/span><span style=\"color: #795E26\">gcd<\/span><span style=\"color: #000000\">(m, n) &lt;&lt; <\/span><span style=\"color: #A31515\">&#39;<\/span><span style=\"color: #EE0000\">\\n<\/span><span style=\"color: #A31515\">&#39;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">char<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">print_gcd<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">5<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">print_gcd<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">10<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">20<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">print_gcd<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">9<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #795E26\">print_gcd<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">121<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #098658\">99<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#endif<\/span><span style=\"color: #008000\">  \/\/ TESTING<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<p>Change the\u00a0<strong><code>gcd()<\/code><\/strong>\u00a0function so that it becomes a member function of the class &#8212; when you make it a member function of the class, can you eliminate the <strong><code>m<\/code><\/strong> and <strong><code>n<\/code><\/strong> parameters?.<\/p>\n<\/div>\n<\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Testing_Your_Program\"><\/span>Testing Your Program<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>The following program should work correctly with your <strong><code>Rational<\/code><\/strong> class implementation. Test your class against this program, and verify the results against those expected.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(3 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"\/\/\n\/\/  testrat.cpp\n\/\/  Assignment 2: Rational Class\n\/\/\n\/\/  Created by Bryan Higgs on 10\/31\/24.\n\/\/\n\n#include &lt;iostream&gt;\n#include &quot;rational.h&quot;\n\n\/\/\n\/\/ Main program to test the Rational class\n\/\/\nint main(int argc, const char * argv[])\n{\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check constructor with two ints:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;Rational a(3,4);&quot;;\n Rational a(3,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;a: &quot;;\n a.Print();\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check constructor with one int:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;Rational b(3);&quot;;\n Rational b(3);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;b: &quot;;\n b.Print();\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check copy constructor:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;Rational c(b);&quot;;\n Rational c(b);\n std::cout &lt;&lt; std::endl &lt;&lt;&quot;c: &quot;;\n c.Print();\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational = Rational assignment:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;a = b;&quot;;\n a = b;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;a: &quot;;\n a.Print();\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational = int assignment:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;a = 1;&quot;;\n a = 1;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;a: &quot;;\n a.Print();\n\n#ifdef CHECK_ERRORS \/\/ Define CHECK_ERRORS to test this\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational = double assignment:&quot;\n         &quot; (Should not work!):&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;a = 1.0;&quot;;\n a = 1.0;  \/\/ Should not compile\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;a: &quot;;\n a.Print();\n#endif\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check double = Rational assignment:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x = Rational(3,4);&quot;;\n double x;\n x = Rational(3,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x: &quot; &lt;&lt; x;\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational + Rational addition:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c = Rational(3,4) + Rational(1,4);&quot;;\n c = Rational(3,4) + Rational(1,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c: &quot;;\n c.Print();\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check double + Rational addition:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x = 37.25 + Rational(3,4);&quot;;\n x = 37.25 + Rational(3,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x: &quot; &lt;&lt; x;\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational + double addition:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x = Rational(3,4) + 37.25;&quot;;\n x = Rational(3,4) + 37.25;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x: &quot; &lt;&lt; x;\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational - Rational subtraction:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c = Rational(3,4) - Rational(1,4);&quot;;\n c = Rational(3,4) - Rational(1,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c: &quot;;\n c.Print();\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check double - Rational subtraction:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x = 37.25 - Rational(3,4);&quot;;\n x = 37.25 - Rational(3,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x: &quot; &lt;&lt; x;\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational - double subtraction:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x = Rational(3,4) - 37.25;&quot;;\n x = Rational(3,4) - 37.25;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x: &quot; &lt;&lt; x;\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational * Rational multiplication:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c = Rational(3,4) * Rational(1,4);&quot;;\n c = Rational(3,4) * Rational(1,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c: &quot;;\n c.Print();\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check double * Rational multiplication:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x = 37.25 * Rational(3,4);&quot;;\n x = 37.25 * Rational(3,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x: &quot; &lt;&lt; x;\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational * double multiplication:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x = Rational(3,4) * 37.25;&quot;;\n x = Rational(3,4) * 37.25;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x: &quot; &lt;&lt; x;\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational \/ Rational division:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c = Rational(3,4) \/ Rational(1,4);&quot;;\n c = Rational(3,4) \/ Rational(1,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c: &quot;;\n c.Print();\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check double \/ Rational division:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x = 37.25 \/ Rational(3,4);&quot;;\n x = 37.25 \/ Rational(3,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x: &quot; &lt;&lt; x;\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational \/ double division:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x = Rational(3,4) \/ 37.25;&quot;;\n x = Rational(3,4) \/ 37.25;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;x: &quot; &lt;&lt; x;\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational negation:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c = -Rational(3,4);&quot;;\n c = -Rational(3,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c: &quot;;\n c.Print();\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Check Rational unary plus:&quot;;\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c = +Rational(3,4);&quot;;\n c = +Rational(3,4);\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;c: &quot;;\n c.Print();\n\n std::cout &lt;&lt; std::endl &lt;&lt; &quot;====Destructors about to be checked...\\n&quot;;\n  \n return 0;\n}\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  testrat.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Assignment 2: Rational Class<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/  Created by Bryan Higgs on 10\/31\/24.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&lt;iostream&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#include<\/span><span style=\"color: #0000FF\"> <\/span><span style=\"color: #A31515\">&quot;rational.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/ Main program to test the Rational class<\/span><\/span>\n<span class=\"line\"><span style=\"color: #008000\">\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">main<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000FF\">int<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argc<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #0000FF\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">char<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">*<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">argv<\/span><span style=\"color: #000000\">[])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check constructor with two ints:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Rational a(3,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> Rational <\/span><span style=\"color: #795E26\">a<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;a: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">a<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check constructor with one int:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Rational b(3);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> Rational <\/span><span style=\"color: #795E26\">b<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;b: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">b<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check copy constructor:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;Rational c(b);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> Rational <\/span><span style=\"color: #795E26\">c<\/span><span style=\"color: #000000\">(b);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt;<\/span><span style=\"color: #A31515\">&quot;c: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">c<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational = Rational assignment:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;a = b;&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> a = b;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;a: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">a<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational = int assignment:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;a = 1;&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> a = <\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;a: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">a<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#ifdef<\/span><span style=\"color: #0000FF\"> CHECK_ERRORS<\/span><span style=\"color: #008000\"> \/\/ Define CHECK_ERRORS to test this<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational = double assignment:&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">         <\/span><span style=\"color: #A31515\">&quot; (Should not work!):&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;a = 1.0;&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> a = <\/span><span style=\"color: #098658\">1.0<\/span><span style=\"color: #000000\">;<\/span><span style=\"color: #008000\">  \/\/ Should not compile<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;a: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">a<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #AF00DB\">#endif<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check double = Rational assignment:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x = Rational(3,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">double<\/span><span style=\"color: #000000\"> x;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> x = <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; x;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational + Rational addition:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c = Rational(3,4) + Rational(1,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> c = <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">) + <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">c<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check double + Rational addition:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x = 37.25 + Rational(3,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> x = <\/span><span style=\"color: #098658\">37.25<\/span><span style=\"color: #000000\"> + <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; x;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational + double addition:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x = Rational(3,4) + 37.25;&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> x = <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">) + <\/span><span style=\"color: #098658\">37.25<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; x;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational - Rational subtraction:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c = Rational(3,4) - Rational(1,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> c = <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">) - <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">c<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check double - Rational subtraction:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x = 37.25 - Rational(3,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> x = <\/span><span style=\"color: #098658\">37.25<\/span><span style=\"color: #000000\"> - <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; x;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational - double subtraction:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x = Rational(3,4) - 37.25;&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> x = <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">) - <\/span><span style=\"color: #098658\">37.25<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; x;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational * Rational multiplication:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c = Rational(3,4) * Rational(1,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> c = <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">) * <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">c<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check double * Rational multiplication:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x = 37.25 * Rational(3,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> x = <\/span><span style=\"color: #098658\">37.25<\/span><span style=\"color: #000000\"> * <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; x;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational * double multiplication:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x = Rational(3,4) * 37.25;&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> x = <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">) * <\/span><span style=\"color: #098658\">37.25<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; x;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational \/ Rational division:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c = Rational(3,4) \/ Rational(1,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> c = <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">) \/ <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">1<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">c<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check double \/ Rational division:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x = 37.25 \/ Rational(3,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> x = <\/span><span style=\"color: #098658\">37.25<\/span><span style=\"color: #000000\"> \/ <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; x;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational \/ double division:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x = Rational(3,4) \/ 37.25;&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> x = <\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">) \/ <\/span><span style=\"color: #098658\">37.25<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;x: &quot;<\/span><span style=\"color: #000000\"> &lt;&lt; x;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational negation:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c = -Rational(3,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> c = -<\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">c<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Check Rational unary plus:&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c = +Rational(3,4);&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> c = +<\/span><span style=\"color: #795E26\">Rational<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #098658\">3<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #098658\">4<\/span><span style=\"color: #000000\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;c: &quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">c<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #795E26\">Print<\/span><span style=\"color: #000000\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::cout &lt;&lt; <\/span><span style=\"color: #267F99\">std<\/span><span style=\"color: #000000\">::endl &lt;&lt; <\/span><span style=\"color: #A31515\">&quot;====Destructors about to be checked...<\/span><span style=\"color: #EE0000\">\\n<\/span><span style=\"color: #A31515\">&quot;<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\"> <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #098658\">0<\/span><span style=\"color: #000000\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>A Rational Class Note: This assignment is intended to give you some exposure to writing a relatively simple C++ class. In particular, it is intended to show you how much the C++ compiler is doing for you automatically &#8212; sometimes it does what you want, and sometimes not. Rational Numbers Rational numbers are those numbers [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":29,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-31","page","type-page","status-publish","hentry"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":3,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/31\/revisions"}],"predecessor-version":[{"id":1597,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/31\/revisions\/1597"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/29"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/media?parent=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}