Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Calculations using bool

Name: Anonymous 2012-03-06 11:13

A useful technique for performing high precision math is to represent numbers as rationals, that is by the ratio of two integers. In this assignment you will implement the four functions described below, which provide the basic calculation operations on rational numbers. The functions you are to implement are as follows:

bool ratAdd(int ln, int ld, int rn, int rd, int& on, int& od)
Addition of the rational numbers.

bool ratSub(int ln, int ld, int rn, int rd, int& on, int& od)
Subtraction of the rational numbers.

bool ratMult(int ln, int ld, int rn, int rd, int& on, int& od)
Multiplication of the rational numbers.

bool ratDiv(int ln, int ld, int rn, int rd, int& on, int& od)
Division of the rational numbers.

In all cases:
ln/ld and rn/rd are the left and right operand, respectively,
on/od is the result, which must be expressed in lowest terms, and
the returned value is false if and only if a denominator is 0.


This is another programming assignment of mine, have no idea how i would even start! Any help is appreciated!

Name: Anonymous 2012-10-27 12:12

[code]ln   rn   ln rd + rn ld
-- + -- = -------------
ld   rd       ld rd[code]
The rest are obvious. You can shorten any rational to its minimal size by dividing numerator and denominator by the gcd of both. For that you'll want to implement the binary gcd algorithm (can be found on wikipedia)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List