Purchase Solution

Write a program to do rational number arithmetic in C++

Not what you're looking for?

Ask Custom Question

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

Attachments
Purchase this Solution

Solution Summary

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

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Javscript Basics

Quiz on basics of javascript programming language.

C# variables and classes

This quiz contains questions about C# classes and variables.

Basic Networking Questions

This quiz consists of some basic networking questions.