This is a C# project . I am expected to create as this image shows. If the image isnot clearly
showing , it\'s the Chegg\'s system. Please , if you see it quit long, assist me with the starting and
hinting bulltes point or functions that may simplify. Thannks...
The design of the Calculator form
Operation
· To clear the contents of memory, the user clicks the MC button. To save the value that’s
currently displayed in memory, the user clicks the MS button. To recall the value that’s currently
in memory and display it in the calculator, the user clicks the MR button. And to add the value
that’s currently displayed to the value in memory, the user clicks the M+ button.
· An M is displayed in the box above the MC button whenever the memory contains a value.
· See project 12-1 for additional details.
Specifications
· Create a class named MemoryCalculator that inherits the Calculator class described in
project 12-1. The MemoryCalculator class should add properties and methods as needed to
implement the memory function.
Note:
· MemoryCalculator class design:
Method Description
MemoryStore Stores the calculator’s current value in memory.
MemoryRecall Sets the calculator’s current value to the value stored in memory.
MemoryAdd Adds the calculator’s current value to the value currently stored in
memory.
MemoryClear Clears the current memory value.
Solution
Calculator.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator
{
public class Calculator
{
public decimal currentValue;
private decimal operand1;
public decimal operand2;
private Operator op;
public enum Operator { Addd, Subtract, Multiply, Divide, None };
//Needed to be changed from private to public
public Calculator()
{
this.currentValue = 0;
this.operand1 = 0;
this.operand2 = 0;
this.op = Operator.None;
}
public decimal CurrentValue
{
get { return this.currentValue; }
}
public void Clear()
{
this.currentValue = 0;
this.operand1 = 0;
this.operand2 = 0;
this.op = Operator.None;
}
public void Add(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Addd;
}
public void Subtract(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Subtract;
}
public void Multiply(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Multiply;
}
public void Divide(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Divide;
}
public void Equals(decimal val)
{
operand2 = val;
switch (this.op)
{
case Operator.Addd:
currentValue = operand1 + operand2;
break;
case Operator.Subtract:
currentValue = operand1 - operand2;
break;
case Operator.Multiply:
currentValue = operand1 * operand2;
break;
case Operator.Divide:
//Try catch to prevent dividing by zero
try
{
currentValue = operand1 / operand2;
}
catch (DivideByZeroException)
{
MessageBox.Show(\"You cannot divide by zero\", \"Error!\");
}
break;
case Opera.
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
This is a C# project . I am expected to create as this image shows. .pdf
1. This is a C# project . I am expected to create as this image shows. If the image isnot clearly
showing , it's the Chegg's system. Please , if you see it quit long, assist me with the starting and
hinting bulltes point or functions that may simplify. Thannks...
The design of the Calculator form
Operation
· To clear the contents of memory, the user clicks the MC button. To save the value that’s
currently displayed in memory, the user clicks the MS button. To recall the value that’s currently
in memory and display it in the calculator, the user clicks the MR button. And to add the value
that’s currently displayed to the value in memory, the user clicks the M+ button.
· An M is displayed in the box above the MC button whenever the memory contains a value.
· See project 12-1 for additional details.
Specifications
· Create a class named MemoryCalculator that inherits the Calculator class described in
project 12-1. The MemoryCalculator class should add properties and methods as needed to
implement the memory function.
Note:
· MemoryCalculator class design:
Method Description
MemoryStore Stores the calculator’s current value in memory.
MemoryRecall Sets the calculator’s current value to the value stored in memory.
MemoryAdd Adds the calculator’s current value to the value currently stored in
memory.
MemoryClear Clears the current memory value.
Solution
Calculator.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator
{
2. public class Calculator
{
public decimal currentValue;
private decimal operand1;
public decimal operand2;
private Operator op;
public enum Operator { Addd, Subtract, Multiply, Divide, None };
//Needed to be changed from private to public
public Calculator()
{
this.currentValue = 0;
this.operand1 = 0;
this.operand2 = 0;
this.op = Operator.None;
}
public decimal CurrentValue
{
get { return this.currentValue; }
}
public void Clear()
{
this.currentValue = 0;
this.operand1 = 0;
this.operand2 = 0;
this.op = Operator.None;
}
public void Add(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Addd;
}
public void Subtract(decimal val)
{
this.operand1 = val;
this.currentValue = val;
3. this.op = Operator.Subtract;
}
public void Multiply(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Multiply;
}
public void Divide(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Divide;
}
public void Equals(decimal val)
{
operand2 = val;
switch (this.op)
{
case Operator.Addd:
currentValue = operand1 + operand2;
break;
case Operator.Subtract:
currentValue = operand1 - operand2;
break;
case Operator.Multiply:
currentValue = operand1 * operand2;
break;
case Operator.Divide:
//Try catch to prevent dividing by zero
try
{
currentValue = operand1 / operand2;
}
catch (DivideByZeroException)
4. {
MessageBox.Show("You cannot divide by zero", "Error!");
}
break;
case Operator.None:
currentValue = operand2;
break;
}
operand1 = currentValue;
}
public void SquareRoot(decimal val)
{
this.operand1 = val;
currentValue = (decimal)Math.Sqrt(Convert.ToDouble(operand1));
op = Operator.None;
}
public void Reciprocal(decimal val)
{
this.operand1 = val;
currentValue = 1 / operand1;
op = Operator.None;
}
}
}
MemoryCalculator.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculator
{
public class MemoryCalculator : Calculator
{
//variable to hold the memory
5. private static decimal memoryStorage;
private static string dispValue;
public MemoryCalculator(decimal memory)
{
this.MemoryStorage = memory;
}
//added string constructor to get the display value from form1
//this will allow me to add what ever is inputed to be added to memoryStorage
(MemoryAdd function)
public MemoryCalculator(string displayValue)
{
this.DisplayValue = displayValue;
}
public string DisplayValue
{
get
{
return dispValue;
}
set
{
dispValue = value;
}
}
public decimal MemoryStorage
{
get
{
return memoryStorage;
}
set
{
memoryStorage = value;
}
}
public decimal memoryStore()
6. {
//save memoryStorage
memoryStorage = this.MemoryStorage;
//going to return this to put in the txtMemory text box
return memoryStorage;
}
public decimal memoryAdd()
{
//declare array to define what numbers to add
decimal[] addens = { Convert.ToDecimal(this.DisplayValue), memoryStorage };
//add memoryStorage and current value
memoryStorage = addens.Sum();
return memoryStorage;
}
public void memoryClear()
{
//set memoryStorage to 0
memoryStorage = 0;
}
public decimal memoryRecall()
{
// return memoryStorage
return memoryStorage;
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
7. using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string displayString;
//Needs to be decimal
private decimal displayValue;
private bool newValue;
private bool decimalEntered;
private Calculator Calc = new Calculator();
//define MemoryCalculator class
private MemoryCalculator calcMem = new MemoryCalculator(0);
private void Form1_Load(object sender, System.EventArgs e)
{
//Initializes values
displayValue = 0;
displayString = "";
newValue = true;
decimalEntered = false;
}
private void btnNumber_Click(object sender, System.EventArgs e)
{
if (newValue)
{
displayString = "";
newValue = false;
11. }
}
private void btnEquals_Click(object sender, System.EventArgs e)
{
if (newValue)
Calc.Equals(displayValue);
else
Calc.Equals(displayValue);
displayValue = Calc.CurrentValue;
txtDisplay.Text = displayValue.ToString();
newValue = true;
decimalEntered = false;
}
private void btnMS_Click(object sender, EventArgs e)
{
//pass displayValue to the MemoryCalculator class
calcMem = new MemoryCalculator(displayValue);
calcMem.memoryStore();
txtMemory.Text = 'M'.ToString();
}
private void btnMAdd_Click(object sender, EventArgs e)
{
calcMem = new MemoryCalculator(displayValue.ToString());
calcMem.memoryAdd();
txtMemory.Text = 'M'.ToString();
}
private void btnMC_Click(object sender, EventArgs e)
{
calcMem.memoryClear();
txtMemory.Text = ' '.ToString();
}
private void btnMR_Click(object sender, EventArgs e)
{
//store recalled memory into a variable to be used to display text, and set displayValue
text
12. decimal recalledMemory = calcMem.memoryRecall();
displayValue = recalledMemory;
txtDisplay.Text = (recalledMemory.ToString());
//reset memory after it is recalled
calcMem.memoryClear();
txtMemory.Text = ' '.ToString();
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Note: i cant able to upload Form1.Designer.cs file due to more character. we have limited to post
65,000 characters only