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

70.2K

Verified Solution

Question

Programming

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 FormNew Project window. You will save this project in your CS 3 folderand name it as:yourlastname-firstname-Grader.
  2. In this project user inputs three test scores, a buttoncalculates the average and displays the average and grade. Anotherbutton 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: - Grader
  6. Label1, Text: Test1; Name: leave as is, you don’t use labels inthe 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 thislogic. 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 buttonprocedure. 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 textboxentries into the first three variables. Then calculate the Averageand finally based on the Average assign a Letter Grade.
  23. Clear button clears the entries in Test1, Test2, Test3textboxes and in Average and Grade labels. Then program is ready totake another set of test scores.Ready to enter another set ofnumbers.
  24. After creating the following form layout in Visual Basics (seeassignment 8 on how to create a new project). Make sure to name thecontrols according to above steps 11 - 17.
  25. Double-click on Calculate Average, you will placed in Codewindow to write code:
  26. Declare 4 variables: intTest1, intTest2, intTest3, intAverageas 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 testsvalues and divide by 3. Store Average into intAveragevariable.
  29. Then develop nested IF … THEN … ELSEIF … ELSEIF selectionstructure to evaluate Average and assign a Letter Grade.
  30. You display the average and assigned grade in Average and Gradelabel controls
  31. We have reviewed similar nested selection structure inSelection slides.
  32. You may want to start with a similar code below and make sureto make the necessary changes. Before starting to build IFstatement, don’t forget to declare the variables and assign Test1,Test2, Test3 to their corresponding variables. Also calculating theAverage of three tests:

     If Average < 60Then

           lblAvg.Text = Average

           lblGrade.Text = \"F\"

        ElseIfAverage < 70 Then

           lblAvg.Text = Average

           lblGrade.Text = \"D\"

        ElseIfAverage < 80 Then

           lblAvg.Text = Average

           lblGrade.Text = \"C\"

        ElseIfAverage < 90 Then

           lblAvg.Text = Average

           lblGrade.Text = \"B\"

        ElseIfAverage < 100 Then

           lblAvg.Text = Average

           lblGrade.Text = \"A\"

        EndIf

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

txtTest1.Text = \"\"

  lblAvg.Text = \"\"

lblGrade.Text = \"\"

                         

Form layout with controls

Answer & Explanation Solved by verified expert
4.3 Ratings (769 Votes)
User InterfacefrmMainvbDesignScreen showing controls This is the VB fromPublic Class frmMainThis is click event for click buttonPrivate Sub btnClearClicksender As Object e As EventArgsHandles btnClearClickWhen clear button is clicked clear the textbox and labelslblAverageText clear average labellblGradeText Clear grade labeltxtTest1Text Clear Test1 textboxtxtTest2Text Clear Test2 textboxtxtTest3Text Clear Test3 textboxEnd SubThis is    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students