Question

In: Computer Science

This Module is mainly to practice If ... Then ... ElseIf ... with creating a project...

This Module is mainly to practice If ... Then ... ElseIf ... with creating a project in Visual Basics

  1. 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.
  2. In this project user inputs three test scores, a button calculates the average and displays the average and grade. Another button clears the entries.
  3. Create a form with seven labels, three textboxes and two buttons, similar to below form layout with each control.
  4. Here are the properties of the form and each control:
  5. Form: change the title of the form to: <Your Name> - Grader
  6. Label1, Text: Test1; Name: leave as is, you don’t use labels in the program
  7. Label2, Text: Test2; Name: leave as is
  8. Label3, Text: Test3; Name: leave as is
  9. Label4, Text: Average; Name: leave as is
  10. Label5, Text: Grade; Name: leave as is
  11. Label6, Text: blank; Name: lblAverage ; BorderStyle: Fixed 3D; AutoSize: False
  12. Label7, Text: blank; Name: lblGrade ; BorderStyle: Fixed 3D; AutoSize: False
  13. Textbox1, Test: blank; Name: txtTest1
  14. Textbox2, Test: blank; Name: txtTest2
  15. Textbox3, Test: blank; Name: txtTest3
  16. Button1, Text: Calculate Average; Name: btnCalcAvg
  17. Button2, Text: Clear; Name: btnClear
  18. Write a Visual Basic program that: 1) accepts three scores, 2) computes the average and assigns the grade.
  19. You declare four variables as Integer data type. They are: Test1, Test2, Test3, and Average.
  20. You create an IF…ELSEIF… structure to assign grades using this logic. Note: No need to create a loop:
  21. To assign Letter Grade use this criteria: Average <60, F; Average <70, D; Average < 80, C; Average < 90, B; Average <=100, A.
  22. 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.
  23. 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.
  24. After creating the following form layout in Visual Basics (see assignment 8 on how to create a new project). Make sure to name the controls according to above steps 11 - 17.
  25. Double-click on Calculate Average, you will placed in Code window to write code:
  26. Declare 4 variables: intTest1, intTest2, intTest3, intAverage as Integer.
  27. Assign textbox entries for three scores into intTest1, intTest2, intTest3 variables, Example: intTest1 = txtTest1.Text
  28. Calculate Average, develop an expression to sum three tests values and divide by 3. Store Average into intAverage variable.
  29. Then develop nested IF … THEN … ELSEIF … ELSEIF selection structure to evaluate Average and assign a Letter Grade.
  30. You display the average and assigned grade in Average and Grade label controls
  31. We have reviewed similar nested selection structure in Selection slides.
  32. You may want to start with a similar code below and make sure to make the necessary changes. Before starting to build IF statement, don’t forget to declare the variables and assign Test1, Test2, Test3 to their corresponding variables. Also calculating the Average of three tests:

     If Average < 60 Then

            lblAvg.Text = Average

            lblGrade.Text = "F"

        ElseIf Average < 70 Then

            lblAvg.Text = Average

            lblGrade.Text = "D"

        ElseIf Average < 80 Then

            lblAvg.Text = Average

            lblGrade.Text = "C"

        ElseIf Average < 90 Then

            lblAvg.Text = Average

            lblGrade.Text = "B"

        ElseIf Average < 100 Then

            lblAvg.Text = Average

            lblGrade.Text = "A"

        End If

  1. To program Clear button, double-click on Clear button on the form.
  2. Type the code to clear the textboxes and label controls entries:
  3. You can use the following sample code:

txtTest1.Text = ""

  lblAvg.Text = ""

lblGrade.Text = ""

                         

Form layout with controls

Solutions

Expert Solution

User Interface frmMain.vb[Design]:

Screen showing controls :

************************************

'This is the VB from
Public Class frmMain
'This is click event for click button
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'When clear button is clicked clear the textbox and labels
lblAverage.Text = "" 'clear average label
lblGrade.Text = "" 'Clear grade label
txtTest1.Text = "" 'Clear Test1 textbox
txtTest2.Text = "" 'Clear Test2 textbox
txtTest3.Text = "" 'Clear Test3 textbox
End Sub
'This is click event for calculate average button
Private Sub btnCalcAvg_Click(sender As Object, e As EventArgs) Handles btnCalcAvg.Click
Dim intTest1 As Integer 'This variable will store score for Test1
Dim intTest2 As Integer 'This variable will store score for Test2
Dim intTest3 As Integer 'This variable will store score for Test3
Dim intAverage As Integer 'This variable will store average for test scores
intTest1 = Integer.Parse(txtTest1.Text) 'Take score for Test1 and convert it into integer
intTest2 = Integer.Parse(txtTest2.Text) 'Take score for Test2 and convert it into integer
intTest3 = Integer.Parse(txtTest3.Text) 'Take score for Test3 and convert it into integer
'This line will calculate average and store this average in the variable intAverage
intAverage = (intTest1 + intTest2 + intTest3) / 3
'Using if else statement in VB to check average of the test scores
If intAverage < 60 Then
'when average of test scores is less than 60 then
lblAverage.Text = intAverage 'print intAverage
lblGrade.Text = "F" 'print grade for avergae less than 60 which is F
ElseIf intAverage < 70 Then
'when average of test scores is less than 70 then
lblAverage.Text = intAverage 'print intAverage
lblGrade.Text = "D" 'print grade for avergae less than 70 which is D
ElseIf intAverage < 80 Then
'when average of test scores is less than 80 then
lblAverage.Text = intAverage 'print intAverage
lblGrade.Text = "C" 'print grade for avergae less than 80 which is C
ElseIf intAverage < 90 Then
'when average of test scores is less than 90 then
lblAverage.Text = intAverage 'print intAverage
lblGrade.Text = "B" 'print grade for avergae less than 90 which is B
ElseIf intAverage < 100 Then
'when average of test scores is less than 100 then
lblAverage.Text = intAverage 'print intAverage
lblGrade.Text = "A" 'print grade for avergae less than 100 which is A
End If
End Sub

End Class
================================================

Screen showing average of three test scores and grade :


Related Solutions

Module 02 Course Project - The Contract: (This project is a compilation of skills required to...
Module 02 Course Project - The Contract: (This project is a compilation of skills required to understand Internet Law in its many facets. The students will demonstrate their knowledge of the Internet, laws associated with the internet, cases associated with the laws of the internet, possible remedies or sanctions given a break in the law and the ability to be self-reliant in their research. They will do this through the usage of a "imaginary contract breach" in which they will...
What is the role of the Advanced Professional Nurse in creating an ethical practice environment in...
What is the role of the Advanced Professional Nurse in creating an ethical practice environment in Leadership?
Cat worksheet: use in combination with the cat photos provided in the module to practice your...
Cat worksheet: use in combination with the cat photos provided in the module to practice your dihybrid cross skills **refer to text sections 9.4 & 9.5 to help you during this exercise** Look at the photographs of domestic cats found in this module and take a look at the information on Mendelian traits that control the appearance of cats’ coats found below: Coat uniformity is controlled by genes at the P locus: genotype (P--) = white patches of fur &...
Project 3 Details The purpose of this project is to give you experience with creating and...
Project 3 Details The purpose of this project is to give you experience with creating and using custom objects. In it, you will make a couple custom classes that work in tandem with each other, and call them in your main function. For this project we'll be making something kind of like the Chatbot java file we made in class. You will create a Chatbot class that will contain a number of variables and functions. As you can imagine, a...
CREATING THE PROJECT SCHEDULE - PROJECT MANAGEMENT Your project sponsor is concerned about the duration of...
CREATING THE PROJECT SCHEDULE - PROJECT MANAGEMENT Your project sponsor is concerned about the duration of your project schedule and thinks that you need to cut some time out of the schedule. He thinks that all of the testing that you have included in the plan is not necessary. How would you respond to this? What are the risks of removing the testing with regard to the overall project?
Earned Value Management (EVM) is a project management technique for measuring project performance (schedule, cost mainly)...
Earned Value Management (EVM) is a project management technique for measuring project performance (schedule, cost mainly) and progress in an objective manner in terms of work achieved (Value): The data identified below was listed in a project’s status report. At time of status report: Planned Value of work (PV) = $70,000 Earned Value of work performed (EV) = $50,000 Actual Cost of work performed (AC) = $75,000 Original Planning: Budgeted cost At Completion (BAC) = $110,000 Original length of the...
Earned Value Management (EVM) is a project management technique for measuring project performance (schedule, cost mainly)...
Earned Value Management (EVM) is a project management technique for measuring project performance (schedule, cost mainly) and progress in an objective manner in terms of work achieved (Value): The data identified below was listed in a project’s status report. At time of status report: Planned Value of work (PV) = $70,000 Earned Value of work performed (EV) = $50,000 Actual Cost of work performed (AC) = $75,000 Original Planning: Budgeted cost At Completion (BAC) = $110,000 Original length of the...
Earned Value Management (EVM) is a project management technique for measuring project performance (schedule, cost mainly)...
Earned Value Management (EVM) is a project management technique for measuring project performance (schedule, cost mainly) and progress in an objective manner in terms of work achieved (Value): The data identified below was listed in a project’s status report. At time of status report: Planned Value of work (PV) = $70,000 Earned Value of work performed (EV) = $50,000 Actual Cost of work performed (AC) = $75,000 Original Planning: Budgeted cost At Completion (BAC) = $110,000 Original length of the...
The completion of the human genome project in 2003 took 13 years and was mainly achieved...
The completion of the human genome project in 2003 took 13 years and was mainly achieved using the sanger DNA sequencing technique.Discuss how the Next generation sequencing technique of "sequencing by synthesis"(sometimes called Massive-parallel sequencing ) has radically soeeded up the process of genome sequencing and comment on its clinical application
What is the role of the Advanced Professional Nurse in creating an ethical practice environment? Respond...
What is the role of the Advanced Professional Nurse in creating an ethical practice environment? Respond to this question, based on your selected APN role.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT