Question: please text answer don t put a picture CSC 330 PROJECT 1 Rational fractions are of the form a / b , where a and

please text answer don t put a picture

CSC 330 PROJECT 1

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 following 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.

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 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 or use a single constructor with default parameters.

a) Overload the arithmetic operators ( +, -, *, / ) , so that the appropriate 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.

2. Write a C++ program that, using the Rational class, performs operations on fractions. Test your class

thoroughly.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!