Question: in C# In C#, Define a class for rational numbers named Rational . A rational number is a number that can be represented as two

in C#

In C#, Define a class for rational numbers named Rational. A rational number is a number that can be represented as two intergers with division indicated, but the division is not carried out. For example, 1/2, 3/4, 64/2, and so forth.

In the class represent rational numbers as two int values, numerator and denominator.

Name the class Rational so it will work with the provided test program.

The default constructor should initialized the numerator to zero and the denominator to 1 (0/1). Use either the constructor header initialization section or the body to assign the default values.

Define an overloaded constructor which takes two arguments of the type int. The first argument is the numerator and the second is the denominator. Assign the arguments to the the associated property name, ie: Numerator = numerator;

Define a property to get and set the numerator and one to get and set the denominator.

Define a read-only (get with no set) property that returns a string version of the rational number which includes the numerator, a slash, and the denominator (3/5). Name the property Fraction. This is the property that is used throughout the provided program to display the current values. This property basically serves the purpose of a ToString method, which provides a string respentation of the data in the object.

Allow simple arithmetic by overloading the following math operators: +, -, *, /

When you conduct an arithmetic operation, you do NOT have to simplify the result. For example, 4/5 * 5/10 = 20/50, does NOT need to be simplified to 2/5.

Allow for the comparison of two objects of the type Rational, by overloading the following comparison operators: = =, !=, <, > These functions should return a bool value.

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!