In C# programming.
Create a fractions class that represents fractions in the form a/b Your class should implement the following members:
int Numerator
int Denominator
Fraction(int numerator, int denominator) creates a new Fraction
double ToDecimal() returns the fraction as a double
Fraction Add(Fraction f) adds the fraction to the one passed in and simplifies the result
Fraction Multiply(Fraction f) multiplies the fraction by the one passed in and simplifies the result
Fraction Simplify() simplifies the fraction using the GreatestCommonDivisor method from the first Exercise
Create a test program that demonstrates the following:
1/2 = 0.5
1/7 + 1/5 = 12/35
1/4 * 2/3 * 4/5 = 2/15
/*C sharp program that demonstrats the Fraction class
and display the results of the
add and multiply operations of the Fraction to console
window.*/
//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FractionApp
{
class Program
{
static void Main(string[] args)
{
//create a Farction class
Fraction f1 = new Fraction(1, 2);
//print in decimal as 0.5
Console.WriteLine("{0}", f1.ToDecimal());
Fraction f2 = new Fraction(1, 7);
Fraction f3 = new Fraction(1, 5);
//call Add to add two fractions
Fraction add = f2.Add(f3);
add = add.simplify();//call simplify method
//print the numerator and denominator
Console.WriteLine("{0} / {1}", add.Numerator ,add.Denominator
);
//Create three fraction objects
Fraction f4 = new Fraction(1, 4);
Fraction f5 = new Fraction(2, 3);
Fraction f6 = new Fraction(4, 5);
//call multiply two times
Fraction mul = f4.Multiply(f5);
mul = mul.Multiply(f6);
//call simplify on multiply
mul = mul.simplify();
Console.WriteLine("{0} / {1}", mul.Numerator, mul.Denominator);
Console.ReadLine();
}
}
}
------------------------------------------------------------------------------------------------------------------------
//Fraction.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FractionApp
{
//class Fraction
class Fraction
{
/*default constructor*/
public Fraction()
{
//set 0 and 1 to numerator and denominator
Numerator = 0;
Denominator = 1;
}
/*constructor to set the numerator and denominator*/
public Fraction(int numerator, int denominator)
{
Numerator = numerator;
Denominator = denominator;
}
//Setter and getter methods
public int Numerator { get; set; }
public int Denominator { get; set; }
//Returns the decimal value of fraction
public double ToDecimal()
{
return ((double )Numerator / Denominator);
}
//Method to add two Fractions
public Fraction Add(Fraction f)
{
Fraction temp=new Fraction ();
temp.Numerator = Numerator * f.Denominator + Denominator *
f.Numerator;
temp.Denominator = Denominator * f.Denominator;
return temp;
}
//Method to multiplication of two Fractions
public Fraction Multiply(Fraction f)
{
Fraction temp = new Fraction();
temp.Numerator = Numerator * f.Numerator ;
temp.Denominator = Denominator * f.Denominator;
return temp;
}
/*Simplify the fraction*/
public Fraction simplify()
{
int gcd = GreatestCommonDivisor();
Numerator = Numerator / gcd;
Denominator = Denominator / gcd;
return new Fraction(Numerator, Denominator);
}
/*Returns the greatest common devisor*/
int GreatestCommonDivisor()
{
int gcd = 1;
for (int i = 1; i <= Numerator && i <= Denominator ;
i++)
{
if (Numerator % i == 0 && Denominator % i == 0)
gcd = i;
}
return gcd;
}
}
}
------------------------------------------------------------------------------------------------------------------------
Sample Output:

In C# programming. Create a fractions class that represents fractions in the form a/b Your class...
Create a new class named Fraction that models fractions, such as 2/3 or 45/9. Implement the following API: Constructor: Fraction(int numerator, int denominator) . String toString() so instances of the class can be printed. The format used above is sufficient. Fraction simplify() This method returns a new Fraction that is arithmetically equal to that given, but for which the numerator and denominator have no common factors. Create a testing program, TestFraction, that prompts the user to provide the numerator and...
I need help with the following Java code Consider a class Fraction of fractions. Each fraction is signed and has a numerator and a denominator that are integers. Your class should be able to add, subtract, multiply, and divide two fractions. These methods should have a fraction as a parameter and should return the result of the operation as a fraction. The class should also be able to find the reciprocal of a fraction, compare two fractions, decide whether two...
C++ Create a Rational Number (fractions) class like the one in Exercise 9.6 of the textbook. Provide the following capabilities: Create a constructor that prevents a 0 denominator in a fraction, reduces or simplifies fractions (by dividing the numerator and the denominator by their greatest common divisor) that are not in reduced form, and avoids negative denominators. Overload the addition, subtraction, multiplication, and division operators for this class. Overload the relational and equality operators for this class. Provide a function...
Create a fraction class. This will have two attributes, a numerator and a denominator, both int. This class will have constructors accessors and mutators (for the attributes) a toString method which will allow us to print the fraction in the form 3/4 an Add method so we can add two fractions a subtract method (subtracts one fraction from the other) a multiply method (multiply two fractions) a divide method (divides one fraction by the other) DO NOT (for now) worry...
Consider a class Fraction of fractions. Each fraction is signed and has a numerator and a denominator that are integers. Your class should be able to add, subtract, multiply, and divide two fractions. These methods should have a fraction as a parameter and should return the result of the operation as a fraction. The class should also be able to find the reciprocal of a fraction, compare two fractions, decide whether two fractions are equal, and convert a fraction to...
This in in C# There are two classes, class Fraction and class FractionDemo The user needs to be able to input a value for the numerator and the denominator Create a Fraction class with private fields that hold a positive int numerator and a positive int denominator. In addition, create Properties for each field with the set mutator such that the numerator is greater than or equal to 0 and the denominator is greater than 0 (illegal values should be...
java code
Write a class called FractionObject that represents a fraction with an integer numerator and denominator as fields. A Fraction Object object should have the following methods: A constructor with int numerator, int denominator as parameters - Constructs a new fraction object to represent the ratio (numerator/denominator). The denominator cannot be 0, so output a message if O is passed and set the numerator and denominator to 1. A constructor with no parameters - Constructs a new FractionObject to...
In C++ Fix any errors you had with HW5(Fraction class). Implement a function(s) to help with Fraction addition. \**************Homework 5 code*****************************/ #include<iostream> using namespace std; class Fraction { private: int wholeNumber, numerator, denominator; public: //get methods int getWholeNumber() { return wholeNumber; } int getNumerator() { return numerator; } int getDenominator() { return denominator; } Fraction()// default constructor { int w,n,d; cout<<"\nEnter whole number : "; cin>>w; cout<<"\nEnter numerator : "; cin>>n; cout<<"\nEnter denominator : "; cin>>d; while(d == 0)...
(Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class- the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should store the fraction in reduced form. The fraction 2/4 is equivalent to h and would be stored in the object as 1 in the numerator...
Assignment 1, Fraction Instructions For this assignment, you will create a class to store fractions. The class will hold two integer values: a numerator and a denominator. For your class we will stick to positive fractions, meaning the numerator and the denominator must both be greater than 0. In previous assignments, we had a requirement that your class be named Main. In this assignment, the class is required to be named Fraction. To get started, download the template file Fraction.java...