Rational class performs operations on fractions

Assignment Help C/C++ Programming
Reference no: EM13700779

Question: Rational fractions are of the form a/b , where a and b are integers and b ? 0. Suppose a / b and c / d are fractions.

Arithmetic operations on fractions are defined by the subsequent rules:

a / b + c / d = (ad + bc) / bd

a / b - c / d = (ad - bc) / bd

a / b * c / d =  ac / bd

(a / b)  / (c / d) = ad / bc, where c/d ? 0.

Fractions are compared as follows:

a / b   op   c/d   if   ad   op  bc, where op is any relational operator. For example,  a/b  <  c/d if  ad < bc.

Part 1: Create a class, called Rational, for performing arithmetic and relational operations on fractions.

Use integer variables to represent the private instance variables of the class - the numerator and the denominator.

Provide a constructor method that allows an object of this class to be initialized when it is declared. The constructor should store the fraction in reduced form (i.e. the fraction 2/4 would be stored as 1 in the numerator and 2 in the denominator). Provide a no-argument constructor in case no initializers are provided.

a. Overload the arithmetic operators ( +, -, *, / ) , so that the suitable symbol can be used to perform these operations. The result of each operation should be in reduced form.

b. Overload the relational operators ( <, <=, >, >=, ==, != ) , so that the appropriate symbol can be used to perform these operations.

c. Overload the stream insertion and stream extraction operators for input and output.

Part 2: Write a C++ program that, using the rational class performs operations on fractions. Test your class thoroughly.

Show the constructor method and overload the stream insertion and stream extraction operators

Reference no: EM13700779

Questions Cloud

How many moles of sbcl5 and sbcl3 : Question- Starting with 0.290mol SbCl3 and 0.170mol Cl2, how many moles of SbCl5, SbCl3, and Cl2 are present when equilibrium is established at 248?C in a 2.50?L flask?
Covert the subsequent decimal numbers into binary numbers : Write the results of the two numbers (in decimal) after the BIT operations and please covert the subsequent decimal numbers into binary numbers:  (using 2 bytes = 16 bits)
Calculate the heat needed to raise the temperature : Question- The specific heat of aluminum is 0.900J/g degrees C. Calculate the heat needed to raise the temperature of a 45.0 g block of aluminum from 20.5 degrees C to 297.4 degrees C
What is the maximum number of moles of al2o3 : Question- If 4.5 moles of Al and 3.3 moles of Fe2O3 are allowed to react, what is the maximum number of moles of Al2O3 that can be produced
Rational class performs operations on fractions : Write a C++ program that, using the rational class performs operations on fractions. Test your class thoroughly.
What compounds result from the reaction : Question- What happens to sodium azide when it is dissolved in water? What compounds result from this reaction?
Design an adt for a two color double stack : Design an adt for a two color double stack adt that consists of two stacks one red and one blue and has its operations color coded versions of the regular stack adt operations.
The oxidation number of chlorine goes from what to what : Question- As the reaction represented above proceeds to the right, the oxidation number of chlorine goes from what to what
Crossing a canyon on a cable bridge : Construct a Prolog program using in-depth research to find a solution to this problem. It must compile with no errors and follow the directions.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Suggest an application system

Prompt for user login to begin using the system, provide an avenue for users to enter test data - Suggest an application system which is able to perform some arithmetic computations, like commission system, encryption system, timer system, etc, fro..

  Calculates the sum of the cube roots of two integers.

Wrtie a program that calculates the sum of the cube roots of two integers. The program should use the following functions as well as a main funcion. 1) enter one positive value 2) compute the cube root of one integer 3) report the value of two intege..

  The program will read integers values

Write a C++ program to do the following. The program will read integers values one at a time from standard input (cin) until you read the value 150. assume that the number of values read in is at least 1 and less than or equal to 100

  Write an input validation loop

write an input validation loop that asks the user to enter a number in the range of 1 through 4.

  Write a recursive algorithm to print all of the subsets

Write a recursive algorithm to print all of the subsets for the set of the first positive integers.

  What more efficient way to write this function for matrix

What's a more efficient way to write this function for a matrix? This one has to go through all the numbers, but that would take too long. r_num is row and c_num is column

  Write a loop that will show the price of silver and gold

Write a loop that will show the price of silver and gold for 1 to 16 ounces in one ounce increments.

  Write an accessor function to get the angle

Write a friend function to compare the area of a rectangle with sides 12 and 8 to the area of a parallelogram with sides 14 and 18 and an acute angle of 40 degrees. Test it in main, and check the answer by hand.

  Write a program with three functions

Write a program with three functions: upper, lower, and reverse.

  Write a program that asks the user for non-negative integer

The factorial of n (written n!) is the product of the integers between 1 and n. Thus 4! = 1*2*3*4 = 24. By definition, 0! = 1.

  Objectivein this assignment you read a list of employees

objectivein this assignment you read a list of employees from a csv file and convert them into corresponding objects.

  Gcd between two positive integer numbers

Write a C++ code for calculating the GCD (Greatest Common Divisor) between two positive integer numbers. You  should  use Euclid's  original  subtraction  based  GCD algorithm ( not  using  modulo operator). You should write a function following t..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd