Create a simple calculator program using the Windows Application function within
ID: 3935923 • Letter: C
Question
Create a simple calculator program using the Windows Application function within Visual Studio. You will need to use at least one form level variable and display it when the ‘=’ button is pressed. Note: the form level variable must be able to hold decimal numbers. Hint: Since the variable is used only to hold a value I would leave it a string and convert it to a number when I needed to. This will avoid some potential problems.
I should be able to put numbers into the display at the top by selecting the text box and entering numbers from the keyboard or by selecting the numbers one by one on the calculator form.
For some extra credit implement the old memory button ‘M+’ and ‘M-‘ as well as the Memory clear and memory remind ‘MC’ ‘MR’.
|Simple Calculator 123 1 2 4 5 9Explanation / Answer
//CalculatorUtilities.cs using System; using System.Windows.Controls; using System.Windows; using System.Windows.Media; using System.Globalization; namespace Microsoft.Windows.Controls.Core.Utilities { static class CalculatorUtilities { public static Calculator.CalculatorButtonType GetCalculatorButtonTypeFromText(string text) { switch (text) { case "0": return Calculator.CalculatorButtonType.Zero; case "1": return Calculator.CalculatorButtonType.One; case "2": return Calculator.CalculatorButtonType.Two; case "3": return Calculator.CalculatorButtonType.Three; case "4": return Calculator.CalculatorButtonType.Four; case "5": return Calculator.CalculatorButtonType.Five; case "6": return Calculator.CalculatorButtonType.Six; case "7": return Calculator.CalculatorButtonType.Seven; case "8": return Calculator.CalculatorButtonType.Eight; case "9": return Calculator.CalculatorButtonType.Nine; case "+": return Calculator.CalculatorButtonType.Add; case "-": return Calculator.CalculatorButtonType.Subtract; case "*": return Calculator.CalculatorButtonType.Multiply; case "/": return Calculator.CalculatorButtonType.Divide; case "%": return Calculator.CalculatorButtonType.Percent; case "": return Calculator.CalculatorButtonType.Back; case " ": case "=": return Calculator.CalculatorButtonType.Equal; } //the check for the decimal is not in the switch statement. To help localize we check against the current culture's decimal seperator if (text == CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator) return Calculator.CalculatorButtonType.Decimal; //check for the escape key if (text == ((char)27).ToString()) return Calculator.CalculatorButtonType.Clear; return Calculator.CalculatorButtonType.None; } public static Button FindButtonByCalculatorButtonType(DependencyObject parent, Calculator.CalculatorButtonType type) { for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.