Question
In this exercise, youll design a form that lets the user enter a number grade and then displays the letter grade when the user clicks
-
In this exercise, youll design a form that lets the user enter a number grade and then displays the letter grade when the user clicks the Calculate button.
- Start a new project named LastnameFirstNameCalculateLetterGrade. Be sure to store the solution in its own directory.
- Add the labels, text boxes, and buttons to the form as shown above. Then, set the properties of these controls as follows:
Default name 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:
Default name Property Setting
Form1 Text Calculate Letter Grade AcceptButton btnCalculate CancelButton btnExit StartPosition CenterScreen
- Use the Form Designer to adjust the size and position of the controls and the size of the form so they look as shown above.
- Rename the form to frmCalculateGrade. When youre asked if you want to rename any references to the form, click the Yes button.
- Open the CalculateLetterGrade project you created in your first homework.
- Display the form in the Form Designer, and double-click the Calculate button to generate a Click event handler for it. Then, add this statement to the event handler to get the number grade the user enters:
-
decimal numberGrade = Convert.ToDecimal(txtNumberGrade.Text);
- Add this statement to the event handler to declare and initialize the variable that will hold the letter grade:
-
string letterGrade = "";
Then, add this if-else statement to set 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 Letter Grade text box:
-
txtLetterGrade.Text = letterGrade;
- Finally, add this statement to move the focus back to the Number Grade text box:
-
txtNumberGrade.Focus();
- Return to the Form Designer, and then double-click the Exit button to generate a Click event handler for it. Then, add this statement to the event handler to close the form:
-
this.Close();
- Run the application, enter a number between 0 and 100, and then click the Calculate button. A letter grade should be displayed and the focus should return to the Number Grade text box. Next, enter a different number and press the enter key to display the letter grade for that number. When youre done, press the Esc key to end the application.
PLEASE SHOW ALL THE WORK ON C# MY CODE IS NOT WORKING
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started