Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

C# Operator Overloading


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: +, -, *, / Attachments




Answer Attachments Screenshots
Purchase Answer