Question: Problem Statement: W e have a nearly completed calculator desktop application. However, the calculate method i s missing the computation aspects o f the program,

Problem Statement:
We have a nearly completed calculator desktop application. However, the calculate method is missing
the computation aspects of the program, and we need your help! Dive into the code, and add the
missing mathematical functionality. You will need to only fix this portion of the code.
Code tasks:
1. Identify the Calculate method within the code behind.
2. ONLY MODIFY THIS METHOD!
3. Complete the switch statement:
a. Develop 4 cases that will match the currentOperation.
b. Use the two variables, firstNumber and secondNumber, found within the method.
c. Display the result to the labelResult control.
4. Optional: Find bugs within the program for brownie points.
Hints:
* Use the debugger to learn what variable inputs and outputs will be!
* Place an intelligent breakpoint to stop the program where you need information
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator
{
public partial class Calc : Form
{
private string currentNumber = "Empty";
private string currentOperation = "Blank";
public Calc()
{
InitializeComponent();
}
private void ButtonNumber_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
if (labelResult.Text == "Enter Calculation" || labelResult.Text == "Syntax Error")// initial
{
labelResult.Text = btn.Text;
}
else if (labelResult.Text =="/"|| labelResult.Text =="x"|| labelResult.Text =="-"|| labelResult.Text =="+")// handles number after operation
{
labelResult.Text = btn.Text;
}
else if (currentOperation == "Blank" && currentNumber == labelResult.Text)// handles new number after enter click
{
labelResult.Text = btn.Text;
}
else // grow number
{
labelResult.Text = labelResult.Text + btn.Text;
}
}
private void ButtonOperation_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
if (labelResult.Text == "Enter Calculation")// initial
{
// do nothing
return;
}
else if (currentOperation == "Blank")// first operation
{
currentNumber = labelResult.Text;
}
else
{
// calculate
ButtonEnter_Click(sender, e);
}
currentOperation = btn.Text;
labelResult.Text = btn.Text;
}
private void ButtonClear_Click(object sender, EventArgs e)// reset
{
labelResult.Text = "Enter Calculation";
currentNumber = "Empty";
currentOperation = "Blank";
}
private void ButtonEnter_Click(object sender, EventArgs e)
{
if (labelResult.Text == currentOperation)// handle case without second number
{
labelResult.Text = "Syntax Error";
currentNumber = "Empty";
currentOperation = "Blank";
return;
}
Calculate();
currentNumber = labelResult.Text;
currentOperation = "Blank";
}
private void Calculate()
{
string firstNumber = currentNumber;
string secondNumber = labelResult.Text;
switch (currentOperation)
{
// case 1- perform division
// case 2- perform multiplication
// case 3- perform subtraction
// case 4- perform addition
Enter Calculation
8
9
4
5
6
1
3
+
0 default: // reset
ButtonClear_Click(null, null);
break;
}
}
Problem Statement: W e have a nearly completed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!