Guest User

Untitled

a guest
Apr 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. using System;
  2. namespace Calculator
  3. {
  4.  
  5.  
  6. public class Calculator
  7. {
  8. public decimal currentValue;
  9. public decimal operand1;
  10. public decimal operand2;
  11. char opCode;
  12.  
  13. public Calculator()
  14. {
  15. this.currentValue = 0;
  16. this.operand1 = 0;
  17. this.operand2 = 0;
  18. this.opCode = ' ';
  19. }
  20.  
  21.  
  22. public void Clear()
  23. {
  24. this.currentValue = 0;
  25. this.operand1 = 0;
  26. this.operand2 = 0;
  27. this.opCode = ' ';
  28. }
  29.  
  30. public void Add(decimal value)
  31. {
  32. this.operand1 = value;
  33. this.currentValue = value;
  34. this.opCode = '+';
  35. }
  36.  
  37. public void Subtract(decimal value)
  38. {
  39. this.operand1 = value;
  40. this.currentValue = value;
  41. this.opCode = '-';
  42. }
  43.  
  44. public void Multiply(decimal value)
  45. {
  46. this.operand1 = value;
  47. this.currentValue = value;
  48. this.opCode = '*';
  49. }
  50.  
  51. public void Divide(decimal value)
  52. {
  53. this.operand1 = value;
  54. this.currentValue = value;
  55. this.opCode = '/';
  56. }
  57.  
  58. public void Equals()
  59. {
  60. switch (this.opCode)
  61. {
  62. case '+':
  63. currentValue = operand1 + operand2;
  64. break;
  65. case '-':
  66. currentValue = operand1 - operand2;
  67. break;
  68. case '*':
  69. currentValue = operand1 * operand2;
  70. break;
  71. case '/':
  72. currentValue = operand1 / operand2;
  73. break;
  74. }
  75.  
  76. operand1 = currentValue;
  77. }
  78.  
  79. public void Equals(decimal value)
  80. {
  81. operand2 = value;
  82.  
  83. switch (this.opCode)
  84. {
  85. case '+':
  86. currentValue = operand1 + operand2;
  87. break;
  88. case '-':
  89. currentValue = operand1 - operand2;
  90. break;
  91. case '*':
  92. currentValue = operand1 * operand2;
  93. break;
  94. case '/':
  95. currentValue = operand1 / operand2;
  96. break;
  97. }
  98.  
  99. operand1 = currentValue;
  100. }
  101.  
  102.  
  103. public void squareRoot(decimal value)
  104. {
  105. this.operand1 = value;
  106. currentValue = (decimal)Math.Sqrt(Convert.ToDouble(operand1));
  107. opCode = ' ';
  108. }
  109.  
  110. public void Fraction(decimal value)
  111. {
  112. this.operand1 = value;
  113. currentValue = 1 / operand1;
  114. opCode = ' ';
  115. }
  116. }
  117. }
Add Comment
Please, Sign In to add comment