DO THIS IN C-Sharp (C#) Create a file called Fraction.cs that contains a class called Fraction. The Fraction class should have 2 private fields: double numerator and double denominator and each should have public properties with default getters and setters. The Fraction class should have five (5) constructors: A constructor that allows the user to initialize both the numerator and denominator fields. A constructor that allows the user to initizlize the numerator and sets the denominator to 1, A constructor that takes in a string of the form "num / den" that sets the numerator and denominator based off of the stirng. For this, use the string.Split(" / ") method to get the numerator and denominator into a string array, then use Int32.Parse() to turn them into actual integers. A default constructor that defaults the numerator to 0 and the denominator to 1. The class should contain six (6) methods: Add(Fraction o) that adds two fractions together and returns a new Fraction [Don't worry about reducing to lowest form]. Sub(Fraction o) that subtracts two fractions and returns a new Fraction[a.Sub(b) should be equivalent to a - b] Mult(Fraction o) that multiplies two fractions together and returns a new Fraction. Div(Fraction o) that divides two fractions together and returns a new Fraction. ToDecimal() that returns the value of dividing the numerator and denominator. ToString() that displays the fraction as "num / den" No need to implement the operator static methods
DO THIS IN C-Sharp (C#)
Create a file called Fraction.cs that contains a class called Fraction.
The Fraction class should have 2 private fields: double numerator and double denominator and each should have public properties with default getters and setters.
The Fraction class should have five (5) constructors:
A constructor that allows the user to initialize both the numerator and denominator fields.
A constructor that allows the user to initizlize the numerator and sets the denominator to 1,
A constructor that takes in a string of the form "num / den" that sets the numerator and denominator based off of the stirng.
For this, use the string.Split(" / ") method to get the numerator and denominator into a string array, then use Int32.Parse() to turn them into actual integers.
A default constructor that defaults the numerator to 0 and the denominator to 1.
The class should contain six (6) methods:
Add(Fraction o) that adds two fractions together and returns a new Fraction [Don't worry about reducing to lowest form].
Sub(Fraction o) that subtracts two fractions and returns a new Fraction[a.Sub(b) should be equivalent to a - b]
Mult(Fraction o) that multiplies two fractions together and returns a new Fraction.
Div(Fraction o) that divides two fractions together and returns a new Fraction.
ToDecimal() that returns the value of dividing the numerator and denominator.
ToString() that displays the fraction as "num / den"
No need to implement the operator static methods.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 8 images