123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
-
- namespace UnitTestingCalculator
- {
- public class Calculator
- {
- double firstNum;
- double secondNum;
- public Calculator(double firstNum, double secondNum)
- {
- this.firstNum = firstNum;
- this.secondNum = secondNum;
- }
- // Cложение
- public double Addition() => firstNum + secondNum;
- // Вычитание
- public double Subtraction() => firstNum - secondNum;
- // Умножение
- public double Multiplication() => firstNum * secondNum;
- // Деление
- public double Division()
- {
- if (secondNum == 0)
- {
- Console.WriteLine("Нельзя делить на 0");
- return 0;
- }
- else
- {
- return firstNum / secondNum;
- }
- }
- // Возведение в степень
- public double Exponentiation()
- {
- double result = firstNum;
- if (secondNum == 0)
- {
- result = 1;
- }
- else
- {
- for (int i = 1; i < secondNum; i++)
- {
- result *= firstNum;
- }
- }
- return result;
- }
- }
- }
|