We have just seen some IPO problems—situations where the program accepts some data from a user, does some manipulation of that data, and reports the result. IPO is one kind of code that can make up a program. A closely related kind of problem element involves having the computer ask/answer a question, e.g., Am I obese? Is overtime pay needed for this person? Should the traffic light change color? Is this a leap year? Did I win my bet in the dice (craps) game? Obviously, there are lots of questions that can be asked. An essential part of programming requires the identification of data and relationships among the data that allows the computer to answer such questions.
Unit III mostly addresses problem representation that deals with being able to formulate questions of the data elements of the problem. This unit also addresses one of the competency/mastery demonstrations. That demonstration will require evaluation (Part I) and production (Part II) of conditional expressions to demonstrate your understanding.
I encourage you to work with a partner, either using pair programming (one person types and one person watches for mistakes and swap roles every 30 minutes or so) or working side by side on separate computers. This way each person interacts with the code on each item—the only way to learn the material.
Examine the items below and indicate the result of the conditional expression given the value or values indicated. Note that each conditional has several values or sets of value for which you are to determine the result (True or False). You may want to print that page out and compare your results to a classmates. You could also enter them into a VB project to check the results if you wished.
number > 0
Is the value positive?
number 0
T / F
number -1
T / Fnumber 1
T / F
number 0.000000001
T / F number < 0
Is the value negative?
number 0
T / F
number -1
T / Fnumber 1
T / F
number -0.000000001
T / F hours > 40
Is overtime pay called for?
hours 0
T / F
hours 40
T / Fhours 41
T / F
hours 50
T / F income > expenses
Did we make a profit this week?
income 12345
expenses 10000
T / F
income 10000
expenses 10000
T / F current > greatest
Is "this" value greater than others seen thus far?
current 99
greatest 80
T / F
current 99
greatest 100
T / Fcurrent 99
greatest 99
T / F
current 99
greatest 999
T / F current >= greatest
Is "this" value as big as any seen thus far?
current 99
greatest 80
T / F
current 99
greatest 98
T / Fcurrent 99
greatest 99
T / F
current 99
greatest 100
T / F current = target
Is this the value I am searching for?
current apple
target pear
T / F
current apple
target orange
T / F gender ="F"
Is this person female?
gender M
T / F
gender F
T / Fgender f
T / F
gender FEMALE
T / F isFemale
Is this person female?
isFemale True
T / F
isFemale False
T / F Not isMale
Is this person female?
isMale True
T / F
isMale False
T / F score >= 0 And score <= 100
Is the test score a valid percentage value?
score -1
T / F
score 0
T / Fscore 100
T / F
score 101
T / F score < 0 Or score > 100
Is the test score outside the range of valid percentage scores?
score -1
T / F
score 0
T / Fscore 100
T / F
score 101
T / F age >= 9 And age < 13
Is this person a "pre-teen"?
age 8
T / F
age 9
T / Fage 12.5
T / F
age 13
T / F hours >= 30 And hours < 60
Is this student a sophomore?
hours 29
T / F
hours 30
T / Fhours 59
T / F
hours 60
T / F hours > 120 And gpa >= 2.0 And lacDone
Can this student graduate?
hours 119
gpa 3.72
lacDone True
T / F
hours 120
gpa 2.0
lacDone False
T / Fhours 142
gpa 1.99
lacDone True
T / F
hours 142
gpa 1.99
lacDone True
T / F Not rain and temp >= 60 and temp <= 90
Is it a good day for golf?
rain True
temp 87
T / F
rain False
temp 60
T / Frain False
temp 59
T / F
rain False
temp 61
T / FCreate a new form in your practice project (or create a whole new practice project) that allows you to accept three or four values in text boxes, two or three radio button in a group box, two or three check boxes, and some buttons to use to test your code. Then determine/identify/formulate the problem elements (indicated below) that are required to answer the provided questions. The suggested activity is that you identify:
And then create an expression that answers a yes/no question, i.e., produces a value or True
or False
perhaps assigning the result to a variable. Finally, report the result using a message box. Any manipulations (calculations, function calls, etc.) needed should be included as part of your code. You may well need to look up information to identify the necessary data elements and their relationships with respect to the question. A couple examples are provided.
userScore
— a number (double)Dim result As Boolean = userScore >= 2 / 14
MessageBox.Show("Passing?: " & result)
weight
— a number (probably an integer representing weight in pounds)
height
— a number (probably an integer value representing the height in inches)
Dim result As Boolean = weight * 703 / height ^ 2 >= 30
MessageBox.Show("Obese?: " & result)
class="expression">Dim result As Boolean
result = txtInput1.Text.Length > 0
MessageBox.Show("Data entered?: " & result)
Choose which of the form elements/controls is most appropriate for the problem and use it/them for input from the user. Note: if there are not enough numeric or string text boxes, you can use the other kind—the only difference is the label and the name, all text boxes will accept either kind of data.
IsNumeric()
.)(Input values will be original cost, percent off, and available money. Tax rate can be hard coded (in a variable or as a literal value).
Is the first input number less than the second input number. (Test it with both integer and double values.)
Declare a variable and set its value to answer the question, "Does the blood pressure reading indicate a possible problem?" Blood pressure could indicate a problem if the systolic value is above 140 or the diastolic value is above 90.
Declare a variable and set its value to answer the question, "I'm an American male, is my height normal?" The normal range for height of American males is 69.5 inches ± 3 inches.
Assume you have a card value (0-51) and what to check to see if it is a ten. Numbers 0-12 represent spades (ace to king), 13-25 diamonds (ace to king), 26-38 clubs, (ace to king), and 39-51 hearts (ace to king).
The "point" value can be entered via one of the text boxes and be 4, 5, 6, 8, 9, or 10. Generate random values for the roll (two dice each with value 1-6) and check to see if the roll is equal to the point.
To draw IPERS (Iowa Public Employees Retirement System) retirement one must no longer work for an IPERS employer and meet one of three conditions for age and service: sum of age and years of service equals or exceeds 88; age is at least 62 and years of service is at least 20; age is 65 or more. Use an input box to ask the user if they s/he is still working for an IPERS employer.
Make up your own question involving numeric data?
Assume it can have up to 50 characters.
Assume it must have at least 75 character but no more than 200 characters.
Hangman is a game in which a blank for each letter in a word is shown and the user repeatedly guesses a letter that might be in the word. If it is, the program shows the letter, if not the user makes progress toward being hanged (losing). This item checks to see if the guessed letter is in the word.
Is the first input string less than the second input string. (Test it with upper and lower case and with digits or numbers.)
Assume two inputs.
Sentences end with a period, an exclamation point, or a question mark.
You can check both upper and lower case or use the .ToLower()
or .ToUpper()
method to check both simultaneously.
It would have a domain of .edu
>.
A valid e-mail address contains "something", an @ sign, "something", a period or dot, and "something".
Make up your own question involving string data?
You will need to decide how to to get input from the form (if needed) to complete the following items.
Decide what heads means and use Rnd()
to answer the question.)
Must be Native American, have a GPA of at least 3.2 GPA, and an ACT score of 21 or more.
There will be three possible values (1, 2, or 3). Use Rnd()
to generate a value in the range [0..1), then test the value for being in the middle third of the range.
(Me.BackColor.R
will return an indicator of the red value of the background color. It will be a number in the range 0 to 255. Zero indicates none of the color is included.)
(use Me.BackColor.R
, Me.BackColor.G
, Me.BackColor.B
)
Make up your own question involving something besides just numeric and string data?