Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

e. What difficulties did they encounter?

Answered: 1 week ago