PLEASE USE OBJECT ORIENTED PROGRAMMING IN C# USING MICROSOFT VISUAL.
*****PLEASE USE C#(C SHARP)*****
Also please dont use BigInteger
thanks it's really appreciated for all the help
PLEASE MAKE IT SO ITS USER INPUT
SOURCE CODE:
using System;
namespace ConsoleApp3
{
class Rational
{
public int Numerator { get; set; }
public int Denominator { get; set; }
public Rational(int numerator, int denominator)
{
//Reduced form
reduce(ref numerator, ref denominator);
this.Numerator = numerator;
this.Denominator = denominator;
}
public Rational()
{
Numerator = 0;
Denominator = 1;
}
//Calculates GCD of two numbers
int gcd(int n, int m)
{
if (n < m)
return gcd(m, n);
if (m == 0)
return n;
return gcd(m, n % m);
}
public void reduce(ref int numerator,ref int denominator)
{
int k = gcd(numerator, denominator);
numerator /= k;
denominator /= k;
}
public Rational add(Rational y)
{
int den=Denominator*y.Denominator;
int num = (Numerator y.Denominator) + (y.Numerator
Denominator);
//and check if simplification is possible.
return new Rational(num, den);
}
public Rational subtract(Rational y)
{
int den = Denominator * y.Denominator;
int num = (Numerator y.Denominator) - (y.Numerator
Denominator);
//and check if simplification is possible.
return new Rational(num, den);
}
public Rational multiply(Rational y)
{
int den = Denominator * y.Denominator;
int num = Numerator * y.Numerator;
//and check if simplification is possible.
return new Rational(num, den);
}
public Rational divide(Rational y)
{
int den = Denominator * y.Numerator;
int num = Numerator * y.Denominator;
//and check if simplification is possible.
return new Rational(num, den);
}
public void display()
{
Console.WriteLine("The Rational Number is:
"+Numerator+"/"+Denominator);
}
public void displayFloatFormat()
{
Console.WriteLine("The Rational Number in floating point format is:
" + Numerator/(double)Denominator);
Console.WriteLine();
}
}
class Program
{
static void Main(string[] args)
{
//Creating two rational numbers
Rational num1 = new Rational(10, 20);
num1.display();
num1.displayFloatFormat();
Rational num2 = new Rational(21,63);
num2.display();
num2.displayFloatFormat();
//Addition Operation
Console.WriteLine("==============Performing Addition num1+num2
=============");
Rational res=num1.add(num2);
res.display();
res.displayFloatFormat();
//subtraction Operation
Console.WriteLine("==============Performing Subtraction num1-num2
=============");
Rational res1 = num1.subtract(num2);
res1.display();
res1.displayFloatFormat();
//multiplication Operation
Console.WriteLine("==============Performing multiplication
num1*num2 =============");
res = num1.multiply(num2);
res.display();
res.displayFloatFormat();
//division Operation
Console.WriteLine("==============Performing division num1/num2
=============");
res = num1.divide(num2);
res.display();
res.displayFloatFormat();
}
}
}
==================================================
SCREENSHOT FOR THE CODE:
SCREENSHOT FOR THE OUTPUT:
If you have any doubts, please comment down here.
Please hit a LIKE if you like the answer.
Happy Learning..!!
PLEASE USE OBJECT ORIENTED PROGRAMMING IN C# USING MICROSOFT VISUAL. *****PLEASE USE C#(C SHARP)*...
Please use Java language. Thanks in advance. HOME WORK due 09. 18.2019 (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 2...
(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...
Can somebody help me with this assignment. I will highly appreciate. Also, please display the output as well. I need to use JAVA to to write the program. This is the sample output provided by my professor. HOME WORK: due 09.17.2019 (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...
(Rational class) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integers variables to represent the private data of the class- the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case are no initializers are provided and should store the fraction in reduced form. For example, the fraction 3/6 would be...
C++...please help follow exact steps output needs to be the exact same Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the elass 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 contain default values in case no initializers are provided and should store the fraction in reduced...
Object Oriented Programming Please write the code in C++ Please answer the question in text form 9.5 (complex Class) Create a class called complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form where i is V-I Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in...
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...
C++ and/or using Xcode... Define a class of rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, 1/2, 3/4, 64/2, and so forth are all rational numbers. (By 1/2, etc., we mean the everyday meaning of the fraction, not the integer division this expression could produce in a C++ program). Represent rational numbers as two values of type int, one for the numerator and one for the denominator. Call...
In mathematics, a rational number is any number that can be expressed as the quotient or fraction p/q of two integers, p and q, with the denominator q not equal to zero. Since q may be equal to 1, every integer is a rational number. Define a class that can represent for a rational number. Use the class in a C++ program that can perform all of the following operations with any two valid rational numbers entered at the keyboard...
C++ 1st) [Note: This assignment is adapted from programming project #7 in Savitch, Chapter 10, p.616.] Write a rational number class. Recall that a rational number is a ratio-nal number, composed of two integers with division indicated. The division is not carried out, it is only indicated, as in 1/2, 2/3, 15/32. You should represent rational numbers using two int values, numerator and denominator. A principle of abstract data type construction is that constructors must be present to create objects...