Challenge 4: Implement a Calculator Class
In this exercise, you have to implement a calculator which can perform addition, subtraction, multiplication, and division.
We'll cover the following...
We'll cover the following...
Problem Statement
Write a C# class called Calculator with:
-
privatefields:_num1and_num2(double type)
-
Methods:
-
Add(), a method which returns the sum of two numbers. -
Subtract(), a method which returns the difference of_num1and_num2(num2 - num1). -
Multiply(), a method which returns the result of multiplication of numbers. -
Divide(), a method which returns the result of division of_num2by_num1.
-
-
Define a parameterized constructor which takes two parameters
num1andnum2and assigns these parameters to the respective fields in the class.
Input
Passing numbers in the parameterized constructor
Output
Addition, Subtraction, Division, and Multiplication
Sample Input
Calculator calc = new Calculator(10, 94);
calc.Add()
calc.Subtract()
calc.Multiply()
calc.Divide()
Sample Output
104
84
940
9.4