Question

Using C#, create a class in a file MathOP.cs. MathOP.cs needs to include the following methods MathAdd: to add two numb...

Using C#, create a class in a file MathOP.cs.

MathOP.cs needs to include the following methods

  1. MathAdd: to add two numbers
  2. MathSub: to subtract two numbers

Next, create a new class MathOP2 (MathOP2.cs) that Inherits from MathOP.cs.

MathOP2.cs needs to include the following methods

  1. MathMult: to multiply two numbers
  2. MathDiv: to divide two numbers
  3. Allinone: accepts two parameters and set 4 class variables: v_add, v_subtract, v_multiply, and v_divide and show how these values are retrieved.

Finally, create a program TestMathOP.cs to test the classes.                                                               

TestMathOP.cs needs to do the following:

     Enter the First number >>

     Enter the Second Number >>

     The sum of the numbers is

     The subtraction of the two numbers is

    The multiplication of the two numbers is

    The division of the two numbers is

     Do you want to exist (Y/N)?

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear student please find the below code for each of the three files

MathOP.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication12
{
public class MathOP
{
public float MathAdd(float a, float b)
{
return a + b;
}
public float MathSub(float a, float b)
{
return a - b;
}
}
}

MathOP2.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication12
{
public class MathOP2: MathOP
{
public float v_add, v_subtract, v_multiply, v_divide;
public float MathMult(float a, float b)
{
return a * b;
}
public float MathDiv(float a, float b)
{
return a / b;
}
public void Allinone(float a,float b)
{
v_add=MathAdd(a,b);
v_subtract=MathSub(a,b);
v_multiply=MathMult(a,b);
v_divide=MathDiv(a,b);
}
}
}

TestMathOP.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication12
{
class TestMathOP
{
static void Main(string[] args)
{
float a, b;
MathOP2 mOP = new MathOP2();
while (true)
{
Console.WriteLine("Enter the First number >>");
a = float.Parse(Console.ReadLine());
Console.WriteLine("Enter the Second Number >>");
b = float.Parse(Console.ReadLine());
mOP.Allinone(a, b);
Console.WriteLine("The sum of the numbers is" + mOP.v_add.ToString());
Console.WriteLine("The subtraction of the two numbers is" + mOP.v_subtract.ToString());
Console.WriteLine("The multiplication of the two numbers is" + mOP.v_multiply.ToString());
Console.WriteLine("The division of the two numbers is" + mOP.v_divide.ToString());
Console.WriteLine("Do you want to exit (Y/N)?");
char m = Console.ReadKey().KeyChar;
if (m == 'Y' || m == 'y')
break;
}
}
}
}

Screenshot of output:

Enter the First number >> 25 Enter the Second Number >> 5 The sum of the numbers is30 The subtraction of the two numbers is20

If you have any doubt please comment below for Clarification also do not forget to hit the like button Thank You :)

Add a comment
Know the answer?
Add Answer to:
Using C#, create a class in a file MathOP.cs. MathOP.cs needs to include the following methods MathAdd: to add two numb...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a new class MathOP2 (MathOP2.java) that Inherits from MathOP You need to add multiply method...

    Create a new class MathOP2 (MathOP2.java) that Inherits from MathOP You need to add multiply method and divide method, both methods accepts two parameters and return a value. Create a test program with documentation to test all operators (at least 4) The TestMathOP should do the following      Enter the First number >> 5.5      Enter the Second Number >> 7.5      The sum of the numbers is 13      The subtract of the two numbers is -2.00      Do...

  • c++ Q.2. a) Create a C++ class template called MathCalc, to perform arithmetic operations between two...

    c++ Q.2. a) Create a C++ class template called MathCalc, to perform arithmetic operations between two numbers. These arithmetic operations are addition, subtraction, multiplication and division. The MathCalc class template accepts two type parameters, which can be defined as: template <class T, class U>. This allows MathCalc to carry out arithmetic operations between two different data types. MathCalc has the following public methods, described here in pseudocode: i. Ret Sum(augend, addend); Ret is the return value of the method. ii....

  • (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to...

    (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...

  • With this program you are going to design a math practice program for younger users. You...

    With this program you are going to design a math practice program for younger users. You will ask the user to enter two numbers. Only numbers may be entered. If the user enters a word, the program should disregard the entry and wait for an integer entry. There will not be another prompt if the user enters data other than whole numbers (integers). Here is a sample run: Your static methods should accept two integers and return an integer. Do...

  • Create a ComplexNo class for two imaginary numbers. Provide (in addition to add, subtract, multiply, and...

    Create a ComplexNo class for two imaginary numbers. Provide (in addition to add, subtract, multiply, and divide methods) a method for equals (which returns boolean), and toString( ) method (that returns a string representing the receiving object). Throw an exception if an attempt is made to divide by 0 (0 + 0i). Your implementation should return the results of each operation WITHOUT changing the operands. Exxample: Enter the first complex number's real part => 1.0 Enter the first complex number's...

  • Can somebody help me with this assignment. I will highly appreciate. Also, please display the output...

    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...

  • Write another program called calculator that inherits from class average and also has methods that has:...

    Write another program called calculator that inherits from class average and also has methods that has: two methods multiply() to calculate the product of the numbers. One method will have two parameters which are both ints. The second method has three parameters: two ints and a Double. Another method “Power” that finds the power of a number using methods. For example, if the user types in: 5 and 3, the program should print out 125. 3. And another method “Factorial”...

  • Write another program called calculator that inherits from class average and also has methods that has:...

    Write another program called calculator that inherits from class average and also has methods that has: two methods multiply() to calculate the product of the numbers. One method will have two parameters which are both ints. The second method has three parameters: two ints and a Double. Another method “Power” that finds the power of a number using methods. For example, if the user types in: 5 and 3, the program should print out 125. 3. And another method “Factorial”...

  • Hello, In Python Enhance the prior assignment by doing the following 1) Create a class that...

    Hello, In Python Enhance the prior assignment by doing the following 1) Create a class that contain all prior functions MyLib # This function adds two numbers def addition(a, b): return a + b # This function subtracts two numbers def subtraction(a, b): return a - b # This function multiplies two numbers def multiplication(a, b): return a * b # This function divides two numbers # The ZeroDivisionError exception is raised when division or modulo by zero takes place...

  • DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to...

    DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to solve the problem using short methods that work together to solve the operations of add, subtract multiply and divide.   A constructor can call a method called setSignAndRemoveItIfItIsThere(). It receives the string that was sent to the constructor and sets a boolean variable positive to true or false and then returns a string without the sign that can then be processed by the constructor to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT