Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I could really use some help with this porblem Must be form application in C# pl

ID: 3835850 • Letter: I

Question

I could really use some help with this porblem

Must be form application in C# please make solution very simple as I am a beginner

-------------------------------------------------------------------------------------------------------------------------------------------------------

In this exercise, you’ll add data validation to the Simple Calculator form of extra exercise A5-E1.

1.Open the SimpleCalculator project in the Assignment5SimpleCalculatorValidation directory.

2.     Code methods named

IsPresent,

IsDecimal, and

IsWithinRange

that work like the methods described in Murach’s chapter 7 of the book.

3.     Code a method named IsOperator that checks that the text box that’s passed to it contains a value of +, -, *, or /.

4.     Code a method named IsValidData that checks that the Operand 1 and Operand 2 text boxes contain a decimal value between 0 and 1,000,000 (non-inclusive) and that the Operator text box contains a valid operator.

5.     Delete all of the catch blocks from the try-catch statement in the btnCalculate_Click event handler except for the one that catches any exception. Then, add code to this event handler that performs the calculation and displays the result only if the values of the text boxes are valid.

6.     Test the application to be sure that all the data is validated properly.

The Code that needs to be modified( remember it is a form application) picture of form are below

The code that must be modified

private void btnCalculate_Click(object sender, EventArgs e)
{
decimal operand1 = Convert.ToDecimal(txtOperand1.Text);
string operator1 = txtOperator.Text;
decimal operand2 = Convert.ToDecimal(txtOperand2.Text);
decimal result = Calculate(operand1, operator1, operand2);

result = Math.Round(result, 4);
this.txtResult.Text = result.ToString();
txtOperand1.Focus();
}

private decimal Calculate(decimal operand1, string operator1,
decimal operand2)
{
decimal result = 0;
if (operator1 == "+")
result = operand1 + operand2;
else if (operator1 == "-")
result = operand1 - operand2;
else if (operator1 == "*")
result = operand1 * operand2;
else if (operator1 == "/")
result = operand1 / operand2;
return result;
}

private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

Thanks

a Simple Calculator X Operand 1 86 Operator: Operand 2 11.11 7.7408 Result: Calculate

Explanation / Answer

private bool IsOperator()
{

if ( txtOperator1.txt != "+" || txtOperator1.txt != "-" || txtOperator1.txt != "*" || txtOperator1.txt != "/" )

{

return false;

}

else if ( txtOperator2.txt != "+" || txtOperator2.txt != "-" || txtOperator2.txt != "*" || txtOperator2.txt != "/" )

{

return false;

}

else

{

return true;

}

}

private bool IsValidData()

{

if ( (Convert.ToInt32(txtOperator1.txt) > 0) && (Convert.ToInt32(txtOperator2.txt) < 1000000) )

{

return true;

}

else

{

return false;

}

}

These are the 2 functions which you can call before doing rhe calculation to see if the text boxes have the right value and is validated.

Thanks

Nikhil

Let me know if mroe dount is there

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote