Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Calculator
- {
- public class Calculator
- {
- public decimal currentValue;
- public decimal operand1;
- public decimal operand2;
- char opCode;
- public Calculator()
- {
- this.currentValue = 0;
- this.operand1 = 0;
- this.operand2 = 0;
- this.opCode = ' ';
- }
- public void Clear()
- {
- this.currentValue = 0;
- this.operand1 = 0;
- this.operand2 = 0;
- this.opCode = ' ';
- }
- public void Add(decimal value)
- {
- this.operand1 = value;
- this.currentValue = value;
- this.opCode = '+';
- }
- public void Subtract(decimal value)
- {
- this.operand1 = value;
- this.currentValue = value;
- this.opCode = '-';
- }
- public void Multiply(decimal value)
- {
- this.operand1 = value;
- this.currentValue = value;
- this.opCode = '*';
- }
- public void Divide(decimal value)
- {
- this.operand1 = value;
- this.currentValue = value;
- this.opCode = '/';
- }
- public void Equals()
- {
- switch (this.opCode)
- {
- case '+':
- currentValue = operand1 + operand2;
- break;
- case '-':
- currentValue = operand1 - operand2;
- break;
- case '*':
- currentValue = operand1 * operand2;
- break;
- case '/':
- currentValue = operand1 / operand2;
- break;
- }
- operand1 = currentValue;
- }
- public void Equals(decimal value)
- {
- operand2 = value;
- switch (this.opCode)
- {
- case '+':
- currentValue = operand1 + operand2;
- break;
- case '-':
- currentValue = operand1 - operand2;
- break;
- case '*':
- currentValue = operand1 * operand2;
- break;
- case '/':
- currentValue = operand1 / operand2;
- break;
- }
- operand1 = currentValue;
- }
- public void squareRoot(decimal value)
- {
- this.operand1 = value;
- currentValue = (decimal)Math.Sqrt(Convert.ToDouble(operand1));
- opCode = ' ';
- }
- public void Fraction(decimal value)
- {
- this.operand1 = value;
- currentValue = 1 / operand1;
- opCode = ' ';
- }
- }
- }
Add Comment
Please, Sign In to add comment