Computer Science Homework Solutions
Problem
#140470

Building Classes

Write a program to do rational number arithmetic, representing each rational number as a class that has instance variables for the numerator and the denominator.  The program should read and display all rational numbers in the format a/b, or simply a if the denominator is 1. I have enclosed what I have however it doesn't work right. In c++

Input ---------------------------- Output
3/8 + 1/6--------------------------13/24
3/8 - 1/6---------------------------5/24
3/8 * 1/6--------------------------1/16
3/8 / 1/6---------------------------9/4
3/8 I -------------------------------8/3 ---------------invert a/b
8/3 M ----------------------------- 2 + 2/3-----------Write a/b as a mixed fraction
6/8 R ------------------------------3/4 ---------------reduce a/b to lowest terms
6/8 G ------------------------------2------------------Greatest common divisor of num ..
1/6 L 3/8-------------------------24 ------------- Lowest common denom of a/b and c/d
1/6 < 3/8------------------------true------------a/b < c/d
1/6 < = 3/8 -------------------- true------------a/b <= c/d
1/6 > 3/8 -----------------------false------------a/b > c/d
1/6 >= 3/8----------------------false -----------a/b >= c/d
3/8 = 9/24----------------------true-------------a/b = c/d
2/3 X + 2 = 4/5--------------X = -9/5--solution of linear equation (a/b)X = c/d = e/f

Attached file(s):
Attachments
rationalnum.zip  View File

Solution Summary

Create class that has instance variables for the numerator and the denominator, then overload some functions to achieve the rational number arithmetic.

Solution
What is this?
By OTA - Overall OTA Rating
Yanfang Li, PhD - 4.9/5
Purchase Cost Now
$2.19 CAD (was ~$31.92)
Included in Download
  • Plain text response
  • Attached file(s):
    • rationalnum_1.zip
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
Browse