Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Cpp A rational number is a quotient of two integers.For example, 12/5,12/-4,-3/4, and 4/6 are all rational numbers .A rational number is said to

In Cpp

A rational number is a quotient of two integers.For example, 12/5,12/-4,-3/4, and 4/6 are all rational numbers .A rational number is said to be in reduced form if its denominator is positive and its numerator and denominator have no common divisor other than 1

For example,the reduced forms of the rational numbers given above are 12/5, -3/1, -3/4 and 2/3.

Write a class called Rational with a constructor Rational ( int, int) that takes two integers, a numerator and a denominator,and stores those two values in reduced form in corresponding private members.The class should have a private member function void reduce( ) that is used to accomplish the transformation to reduced form. The class should have an overloaded insertion operator << that will be used for output of objects of the class.

Part 2

Modify the class Rational of Programming Challenge 8 to add overloaded operators+,-,*,and/to be used for addition, subtraction,multiplication,and division.Test the class by reading and processing from the key board (or from a file) a series of rational expressions such as

2/3 + 2/8

2/3 * - 2/8

2/3 - 2/ 8

2/3 / 2/8

To facilitate parsing of the input, you may assume that numbers and arithmetic operators are separated by white space.

You should be turning in a Rational.h, Rational.cpp and rationaldriver.cpp that has your main.

All meaningful rational number code should be encapsulated in your Rational class.

Make sure to overload the asked for operators.

Make sure to create Rationals for each of the 4 stated examples in Rational Arithmetic I and show they reduce by using the overloaded << to output to the console.

Make sure to test your overloaded arithmetic expressions using the 4 expressions outlined in Rational Arithmetic II and output the resulting Rationals.

Use console for I/O. Use consts where appropriate.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions