introduction to programming - Pseudo code

profileShanEn
week_4_lab_4.1.pdf

PT1420: Decision Structures in Pseudocode and Visual Basic

Page 1

This lab requires you to think about the steps that take place in a program by writing

pseudocode. Read the following program prior to completing the lab.

Career Tech Placement is hiring employees for placement at technology firms across the

city. Prior to granting an interview, the company has a 100-point test that is used to

determine if the candidate should be interviewed. Depending on the candidate’s score,

he or she will be placed in 1 of 4 categories for possible employment and flagging for an

interview:

Score Employment Category Interview Possibility

85 or above Definite Yes

70 – 84 Likely Yes

60 – 69 Maybe Yes

59 or below No No

Career Tech Placement has asked you to write a program that will allow the company to

enter a test score and then set the employment category and the interview possibility

variables based on the chart above.

Given the major task involved in this program, you decide your program should have three

variables and three modules:

Variable Name Purpose

Declare Integer testScore = 0 Stores the test score of the candidate.

Declare String category = “ “ Stores Definite, Likely, Maybe, or No

Declare String interview = “ “ Stores Yes or No

PT1420: Decision Structures in Pseudocode and Visual Basic

Page 2

Module Name Purpose

Module getScore() Allows the user to enter the test score

Module employCat() Determines the employment category

Module interviewPoss() This module will determine if a day off should

be awarded.

Module displayInfo() Displays the testScore, category, and interview

variables.

Step 1: Complete the pseudocode by writing the missing lines. When writing your modules and

making calls, be sure to pass necessary variables as arguments and accept them as reference

parameters if they need to be modified in the module (Reference: Testing a Series of

Conditions, page 138 from your textbook, Starting Out with Programming Logic & Design.).

Main Module()

//Declare variables on the next 3 lines

//Make Module calls and pass necessary variables on the next 4 lines

End Main

Module getScore(Integer Ref testScore)

//Ask the user to enter a test score

End Module

Module employCat(Integer testScore, String Ref category)

//Determine what employment category they are in based on their test score

//Similar to if the score is less than 60, then category is “No”

PT1420: Decision Structures in Pseudocode and Visual Basic

Page 3

//Otherwise, if score is less than 70 then category is “Maybe”

//…and so on

End Module

Module interviewPoss(Integer testScore, String Ref interview)

//Determine if they qualify for an interview based on their test score

//Similar to if the score is less than 60, then interview is “No”

//Otherwise, interview is “Yes”

End Module

Module displayInfo(Integer testScore, String category, String interview)

//Display the three variables

End Module

This lab requires you to convert the pseudocode and flowchart into an actual program using

Visual Basic.

Step 1: Launch Visual Basic and create a new Console Application. Save it to the appropriate

location.

Step 2: We will be using modules in this program, so all variables and module calls will go

between of Sub Main() and End Sub. In VB, start by declaring and initializing your variables and

making module calls such as:

Sub Main()

'declare your 3 variables similar format such as

'Dim variableName As DataType = 0 (or “ “ if it’s a string)

PT1420: Decision Structures in Pseudocode and Visual Basic

Page 4

'call your 4 modules and pass necessary variables similar 'format such as

'moduleName(arguments)

'add this to cause a pause

Console.WriteLine("Press enter to continue...")

Console.ReadLine()

End Sub

Your module looks like this:

Step 3: Code the getScore() module so that the user enters a test score. Remember to use

ByRef so the value of testScore is retained. This module will look like:

Sub getScore(ByRef testScore As Integer)

'add the code to input testScore

End Sub

PT1420: Decision Structures in Pseudocode and Visual Basic

Page 5

Step 4: Code the employCat() module that will determine the category placement. Remember

to use ByRef so the value of category is retained. This module will look like:

Sub employCat(byVal testScore as Integer, byRef category as String)

'add the code to evaluate conditions

If testScore < 60 Then

category = "No"

ElseIf testScore < 70 Then

category = "Maybe"

ElseIf testScore < 85 Then

category = "Likely"

Else

category = "Definite"

End If

End Sub

PT1420: Decision Structures in Pseudocode and Visual Basic

Page 6

Your module may look like this:

Step 5: Code the interviewPoss() module that will determine the interview value. Use ByRef for

interview, and byVal for testScore. This will be a simple If Then Else that will set the interview

variable to either “Yes” or “No.

Step 6: Code the displayInfo() module and use Console.WriteLine() to display the values of the

three variables. All three variables can be passed as ByVal.

PT1420: Decision Structures in Pseudocode and Visual Basic

Page 7

Step 7: Save, build, and execute your program so that it works. Your output might look like this:

PT1420: Decision Structures in Pseudocode and Visual Basic

Page 8

Step 8: Submit the Visual Basic code as a compressed (zipped) folder using the following steps:

a. Open Windows Explorer --> Start --> All Programs --> Accessories --> Windows Explorer.

Your Windows Explorer might look as follows:

PT1420: Decision Structures in Pseudocode and Visual Basic

Page 9

b. In Windows Explorer, navigate to the folder that contains your project files. Your

Windows Explorer might look as follows:

(If you don't recall you can check in Visual Studio by opening your project, right click

module1.vb file and view the properties. Look at the full path ex.

C:\Users\instructor\Documents\Visual Studio

2010\Projects\myFirstProgram\myFirstProgram\Module1.vb; in this case navigate to

C:\Users\instructor\Documents\Visual Studio 2010\Projects). Your module properties

might look as follows:

c. Right click on your project folder and choose send to --> compressed folder. This creates

a zip file of all your code. Your Windows Explorer might look as follows:

PT1420: Decision Structures in Pseudocode and Visual Basic

Page 10

d. Attach the compressed folder you created to your submission. Your Windows Explorer

might look as follows: