C# has several numeric types, including natural, real, and irrational numbers. One numeric type that's missing is a Rational number. A rational number, as the name suggests is a ratio between 2 natural numbers and is usually represented as a fraction in the form 1/2, 5/4, -79/13, etc.
Create a C# struct with a constructor that takes two integer parameters, either or both of which may be positive or negative. Include two read-only properties, Numerator and Denominator, that return the numerator and denominator of the fraction respectively of type int. Also, override the ToString() method to give a string representation of the rational number as described in the preceding paragraph.
var r1 = new Rational(1, 2);
r1.Numerator ➞ 1
r1.Denominator ➞ 2
r1.ToString() ➞ "1/2"
var r2 = new Rational(10, 8);
r2.Numerator ➞ 5
r2.Denominator ➞ 4
r2.ToString() ➞ "5/4"
var r3 = new Rational(2, -1);
r3.Numerator ➞ -2
r3.Denominator ➞ 1
r3.ToString() ➞ "-2"
var r4 = new Rational(-16, -64);
r4.Numerator ➞ 1
r4.Denominator ➞ 4
r4.ToString() ➞ "1/4"ArgumentException should be raised by the constructor function.Numerator and Denominator values should be reduced to their lowest possible integer values to maintain the ratio (examples r2 and r4 above).Denominator should return 1 but the ToString() method should only show the integer value (example r3 above).Numerator and the Denominator is positive (example r3 above).Numerator and Denominator are positive (example r4 above).Parts 2 and 3 of this series will build on the Rational struct developed here to include arithmetical operations, comparison operators, and conversion to and from other numeric types. They can be found here.