Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write a class called Arithmetic to perform arithmetic calculations with f

ID: 3586019 • Letter: P

Question

Please write a class called Arithmetic to perform arithmetic calculations with fractions. Use integer variables to represent the private data of the class – numerator and denominator. Write a constructor function to initialize when it is declared. Provide public member functions for addition, multiplication, subtraction, and division. Please, print rational numbers in double – point format. Also calculate the area of a rectangle. However, you need to dynamically allocate memory for the object rectangle by creating a pointer to it. The program should check for the user input values.

Explanation / Answer

C# Source Code:

using System;

public class Arithmetic

{
public static void Main()

{

double numarator;

double denominator;

double numaratory;

double denominatory;
int choice;

Console.WriteLine("Enter x");

  

var x=Console.ReadLine();

Console.WriteLine("Enter y");

var y=Console.ReadLine();

string[] val=new string[2];

  

val=x.Split('/');

  

numarator=Convert.ToInt32(val[0]);

  

denominator=Convert.ToInt32(val[1]);

double xval=(double)(numarator/denominator);

string[] val1=new string[2];

  

val1=y.Split('/');

  

numaratory=Convert.ToInt32(val1[0]);

  

denominatory=Convert.ToInt32(val1[1]);

double yval=(double)(numaratory/denominatory);

Console.WriteLine(" Sum of X+Y is "+(xval+yval));

Console.WriteLine("Sub of X-Y is "+(xval-yval));

Console.WriteLine(" Mul of X+Y is "+(xval*yval));

Console.WriteLine(" Div of X/Y is "+(xval/yval));

}

}

Output: