Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This Module is mainly to practice If ... Then ... ElseIf ... with creating a project in VB Open Visual Basic and create a new
This Module is mainly to practice If ... Then ... ElseIf ... with creating a project in VB
- Open Visual Basic and create a new Project. Select Windows Form New Project window. You will save this project in your CS 3 folder and name it as:yourlastname-firstname-Grader.
- In this project user inputs three test scores, a button calculates the average and displays the average and grade. Another button clears the entries.
- Create a form withsevenlabels,threetextboxes andtwobuttons, similar to below form layout with each control.
- Here are the properties of the form and each control:
- Form: change thetitleof the form to: - Grader
- Label1, Text: Test1; Name: leave as is, you dont use labels in the program
- Label2, Text: Test2; Name: leave as is
- Label3, Text: Test3; Name: leave as is
- Label4, Text: Average; Name: leave as is
- Label5, Text: Grade; Name: leave as is
- Label6, Text: blank; Name: lblAverage ; BorderStyle: Fixed 3D; AutoSize: False
- Label7, Text: blank; Name: lblGrade ; BorderStyle: Fixed 3D; AutoSize: False
- Textbox1, Test: blank; Name: txtTest1
- Textbox2, Test: blank; Name: txtTest2
- Textbox3, Test: blank; Name: txtTest3
- Button1, Text: Calculate Average; Name: btnCalcAvg
- Button2, Text: Clear; Name: btnClear
- Write a Visual Basic program that: 1) accepts three scores, 2) computes the average and assigns the grade.
- You declare four variables as Integer data type. They are: Test1, Test2, Test3, and Average.
- You create an IFELSEIF structure to assign grades using this logic. Note:No need to create a loop:
- To assign Letter Grade use this criteria:Average 60,>70,>=100,>.
- To do this you write the code in Calculate Average button procedure. First declare the variables that will get test scores (intTest1, intTest2, intTest3) from textboxes and another one (intAverage) for calculating the tests average. Then assign textbox entries into the first three variables. Then calculate the Average and finally based on the Average assign a Letter Grade.
- Clear button clears the entries in Test1, Test2, Test3 textboxes and in Average and Grade labels. Then program is ready to take another set of test scores.Ready to enter another set of numbers.
- After creating the following form layout in VB (see assignment 8 on how to create a new project). Make sure to name the controls according to above steps 11 - 17.
- Double-click on Calculate Average, you will placed in Code window to write code:
- Declare 4 variables: intTest1, intTest2, intTest3, intAverage as Integer.
- Assign textbox entries for three scores into intTest1, intTest2, intTest3 variables, Example: intTest1 = txtTest1.Text
- Calculate Average, develop an expression to sum three tests values and divide by 3. Store Average into intAverage variable.
- Then develop nested IF THEN ELSEIF ELSEIF selection structure to evaluate Average and assign a Letter Grade.
- You display the average and assigned grade in Average and Grade label controls
- We have reviewed similar nested selection structure in Selection slides.
- You may want to start with a similar code below and make sure to make the necessary changes. Before starting to build IF statement, dont forget to declare the variables and assign Test1, Test2, Test3 to their corresponding variables. Also calculating the Average of three tests:
IfAverage
lblAvg.Text = Average
lblGrade.Text =\"F\"
ElseIfAverage
lblAvg.Text = Average
lblGrade.Text =\"D\"
ElseIfAverage
lblAvg.Text = Average
lblGrade.Text =\"C\"
ElseIfAverage
lblAvg.Text = Average
lblGrade.Text =\"B\"
ElseIfAverage
lblAvg.Text = Average
lblGrade.Text =\"A\"
EndIf
- To program Clear button, double-click on Clear button on the form.
- Type the code to clear the textboxes and label controls entries:
- You can use the following sample code:
txtTest1.Text =\"\"
lblAvg.Text =\"\"
lblGrade.Text =\"\"
Form layout with controls
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