(Solved) : Exercise Ll Design Form Lets User Enter Number Grade Displays Letter Grade User Clicks Cal Q44105027 . . .
-
In this exercise, you’ll design a form that lets the user entera number grade and then displays the letter grade when the userclicks the Calculate button.
- Start a new project namedLastnameFirstNameCalculateLetterGrade. Be sure to store thesolution in its own directory.
- Add the labels, text boxes, and buttons to the form as shownabove. Then, set the properties of these controls as follows:
Defaultname Property Setting
label1 Text &Number grade:
TextAlign MiddleLeft
TabIndex 0
label2 Text Letter grade:
TextAlign MiddleLeft
textBox1 Name txtNumberGrade
TabIndex 1
textBox2 Name txtLetterGrade
ReadOnly True
TabStop False
button1 Name btnCalculate
Text &Calculate
TabIndex 2
button2 Name btnExit
Text E&xit
TabIndex 3
- Now, set the properties of the form as follows:
Defaultname Property Setting
Form1 Text Calculate Letter Grade
AcceptButton btnCalculate
CancelButton btnExit
StartPosition CenterScreen
- Use the Form Designer to adjust the size and position of thecontrols and the size of the form so they look as shown above.
- Rename the form to frmCalculateGrade. When you’re asked if youwant to rename any references to the form, click the Yesbutton.
- Open the CalculateLetterGrade project you created in your firsthomework.
- Display the form in the Form Designer, and double-click theCalculate button to generate a Click event handler for it. Then,add this statement to the event handler to get the number grade theuser enters:
-
decimalnumberGrade = Convert.ToDecimal(txtNumberGrade.Text);
- Add this statement to the event handler to declare andinitialize the variable that will hold the letter grade:
-
stringletterGrade = “”;
Then, add this if-else statement toset the letter grade:
if(numberGrade >= 88)
{
letterGrade = “A”;
}
else if(numberGrade >= 80 && numberGrade <= 87)
{
letterGrade = “B”;
}
else if(numberGrade >= 68 && numberGrade <= 79)
{
letterGrade = “C”;
}
else if(numberGrade >= 60 && numberGrade <= 67)
{
letterGrade = “D”;
}
else
{
letterGrade = “F”;
}
- Add this statement to display the letter grade in the LetterGrade text box:
-
txtLetterGrade.Text = letterGrade;
- Finally, add this statement to move the focus back to theNumber Grade text box:
-
txtNumberGrade.Focus();
- Return to the Form Designer, and then double-click the Exitbutton to generate a Click event handler for it. Then, add thisstatement to the event handler to close the form:
-
this.Close();
- Run the application, enter a number between 0 and 100, and thenclick the Calculate button. A letter grade should be displayed andthe focus should return to the Number Grade text box. Next, enter adifferent number and press the enter key to display the lettergrade for that number. When you’re done, press the Esc key to endthe application.
PLEASE SHOW ALL THE WORK ON C# MY CODE IS NOT WORKING
Expert Answer
Answer to In this exercise, you’ll design a form that lets the user enter a number grade and then displays the letter grade whe…
OR