Section (2 pts. off if you don't get it right!) ______
1. | |
What is the value of x after the form has been loaded? Answer: _________ | Dim x As Integer Private Sub squid() x=x+1+2 End Sub Private Sub Form_Load x=0 Call squid End Sub |
Cf. lecture slide PTopics-19, almost letter-for-letter. Answer: 3 |
2. | |
In a book about VB, you see this description:
Right(x, n) Returns the rightmost n characters of string x Given this information, predict what would be displayed in the caption by the statements shown |
Dim course as String
course = "CSE100/INFO100" lblMyLabel.Caption = Right(course, 6) |
Answer is NFO100 |
3. | |
What is the value of y after the form has been loaded? |
Option Explicit Dim y As Integer Private Sub squid() y=y+2 End Sub Private Sub clam() call squid call squid End Sub Private Sub Form_Load y=0 Call squid Call clam End Sub |
Cf. lecture slide PTopics-20. Answer is 6 |
4. | |
If you saw this in a VB program:Private Sub cmdYellow_Click() frmFirst.BackColor = vbYellow End Sub What are reasonable conclusions to draw from this, if the usual VB style and naming conventions have been followed? Check all that apply. |
___ There is a button object named Yellow
___ There is a form object named Form1 ___ vbYellow is a pre-defined Visual Basic constant ___ There is a procedure named Sub ___ BackColor is a procedure |
|
5. | |
Which of these makes a text box invisible? Circle exactly one. |
txtClearText =
Visible
txtClearText = "Visible" txtClearText.Visible = False txtClearText.Visible = "False" |
txtClearText.Visible = False |
6. | |
The reason for putting Option Explicit at the top of your code is (circle one): |
The program is not legal Visual Basic without it.
It allows you to declare variables. It causes an error if you use an undeclared variable. It enables making an .exe file |
Checks for undeclared variables |
7. | |
If x and y are Integer variables, which of the following are possible VB statements? Circle all that apply. |
x = y
x + y = 2 y = x + 2 2 = x x = "Tyler Durden" |
x = y and y = x+2 |
8. | |
Dim S1 as String Dim S2 as String Dim count and Integer S2 = "US" S1 = "Team: " count = 4 S2 = S1 & count Msgbox(S2) What shows up in the message box? Choose one. |
USTeam:4
US Team:4 US Team: 4 Team:4 Team: 4 |
[3rd line has an error corrected in class: should be "As" instead of "and" |
9. | |
Is the following an algorithm? Explain briefly why or why not:
First there was a thin plume of steam. Then several plumes were seen, followed by a series of tremors. Suddenly, a jet of ash rose upwards, and then a severe tremor sent snow and ice crashing down into Miner's Gulch.
|
|
"Not an algorithm because an algorithm is essentially a sequence of instructions given to produce a specific result. The paragraph is descriptive, not instructive." [from student J.L. -- thanks!] |
10. 3pts. | |
A variable has three essential characteristics. Complete the three words. |
n____________
v____________ t_____________ |
name, value, type. |
11. (1 pt. each) | |
Give two terms which roughly mean the same as "procedure" |
_______________
_______________ |
[Since the context of this test is programming, non-technical English equivalents for procedure did not count.] This was a miniquiz question (?) |
12. | |
Private Sub txtScoops_KeyPress (KeyAscii as Integer) lblScoops.Caption = txtScoops.text & “ scoops, please.” tstScoops.text = “” End Sub From this example, give the name of something which illustrates each of the technical terms. |
Parameter: ______________
Property: ________________ Concatenation operator: _______ |
[worth 3 points total] KeyAscii is the only parameter. Caption and text are properties & is the concatenation operator |
13. | |
In this VB statement:If code1=code2 Then newletter = "Z" End If how is the part code1=code2 best described? Pick one. |
___ A declaration
___ A condition ___ A function ___ An assignment ___ An equation |
condition |
14. | |
Dim dude as Integer dude = 0 dude = dude + 1 dude = 3 dude = dude + dudeWhat is the value of dude at the end of this? |
|
See slide IProg17. Answer: 6 |
15. | |
Suppose you have a label object named lblNow. The following statement will cause the current time to show up on the label:
lblNow.Caption = TIME |
a) Suppose you want the label to show the time that the program started, and remain fixed during the whole program execution. Where in the program would you put the statement?
b) Suppose you wanted the time to continuously "tick" (be updated) while the program ran. Where would you put the statement?
Note: the question does not ask you to change the statement in any way. The question is "where?". |
a. In the form load procedure. b. Create a Timer object, set it to run every millesecond. and put the statement in the Timer event handler. It doesn't work to answer "put it in every procedure". Without a Timer, a long time could go by with no procedure being executed, and the time would not be continuously updated. |
16. | |
500 students have signed up for CSE142 next quarter. The prof has a
list on the computer which is sorted by student ID. He wants to write
a program find out if the student with ID 0003891 is registered.
a) Using Linear Search, what is the most students the program will have to check? b) Using Binary Search, what is the most students the program will have to check? [In both cases, the answer can be approximate: off by as much as 2 is OK.] |
Answer to a: ______ Answer to b: _______
space for calculations
|
a. about 500, if the student is last on the list, or not on the list at all. b. Work this by dividing down from 500: 500,250,125,63,32,16,8,4,2,1 -- 9 steps to get from 500 to 1. No calculator needed! |
17. | |
Suppose it can be proved mathematically that Algorithm A requires fewer
steps, on average, than Algorithm B (at least for sufficiently large data
sets, which is the way such proofs are always done).
Give two reasons why a programmer or manager might still decide to use Algorithm B. |
|
Some good answers: B might be difficult to program B might be more expensive to purchase or license B might require much more memory than A The data sets might be so small that B would still be fast enough The data sets might have some special character which makes B run well on them The data sets might lack some property that B requires (for example, if B requires the data to be sorted, but the data is not sorted) B might have better features for error handling or recovery from failures [Common causes for points off: This was not a question about linear and binary seach. A and B might be totally unrelated to searching. "fewer steps" doesn't mean a smaller program, necessarily (because of loops). "B is cheaper" is not sufficient. You need to say cheaper "in terms of programmer time", "in memory use", "in cost to purchase", etc.] |
18. | |
The function Asc is used (mark all that apply): |
to convert from ASCII String to Unicode String
to convert from ASCII String to Integer to convert from Integer to ASCII String to convert from ASCII String to Integer |
Oops, that answer was listed twice by mistake. You didn't need to circle both. |
19. | |
The following two statements are legal in VB:
Dim A as Integer A = 1 In a math textbook, you might also see an equation like A = 1 Is there any essential difference? Explain briefly. |
|
Yes, there's a difference. In math, A = 1 states a FACT -- that A and 1 are the same. A = 1 causes nothing to change. In programming, A = 1 is an ACTION. It causes A to take the value 1, regardless of what value it might have had before. This is why programmers often read it aloud as "A gets 1" or "A becomes 1". |
20. | |
The VB Debugger is a tool which... (mark all that apply) |
___ locates program errors and informs the programmer about them.
___ automatically removes certain common errors from a program ___ lets the programmer stop execution at some desired point in the program ___ lets the programmer inspect values of variables at some desired point in the program |
Last two items only: lets the programmers stop execution at a breakpoint, and inspect values of variables at that point. |
21. | |
How is a "relational database" different from other things that
are informally called "databases"? |
|
See bboard post from Grace Whiteacre, 3/5/2002 |
22. | |
Which of the following is/are not a fundamental relational database
operation? |
___ Table
___ Union ___ Selection ___ Attribute |
Table and Attribute are not operations. |
23. 3 + 6 points | |
On a separate sheet, you have a copy of a sample solution to the basic requirements of Project 1, Part 1. |
a. Suppose the program is running. The user presses the key "3". Which instructions (if any) of the program execute as a result? Put a small checkmark to the left of each such instruction (leave other instructions blank). Write directly on the handout. b. In the ShowCodeBook procedure, there is a blank space where some lines have been omitted. Fill in that space with code that displays the whole code book. Note: A correct solution which uses iteration will get more credit than a correct one which doesn't. |
Most common mistake: thinking that "3" is an error. It's not an error from the VB point of view. The keypresserror handler is not invoked. Instead, the program uses an If statement to determine what to do. It will execute ONLY one branch of the If. Another common mistake: the instructions said to check EACH instruction executed -- some people checked only some. You still got some credit if if the intention was clear; full credit in a few cases if the omissions were inconsequential (didn't obscure the basic flow). lines with turquoise should have been checked -- red ones should not have been. Private Sub txtClearText_KeyPress(keyascii As Integer) 'a key has been pressed in the cleartext window. 'Convert it, add it to the output On Error GoTo keypresserror Dim sletter As String 'you can do without these local variables, Dim sCodedLetter As String '... but they make the program clearer sletter = UCase(Chr(keyascii)) If sletter >= "A" And sletter <= "Z" Then sCodedLetter = colCodeBook.Item(sletter) 'look up the sletter Else sCodedLetter = sletter 'This takes care of all other visible characters 'But there is a bug here -- ' non-displayable "control characters" aren't properly handled. End If txtEncrypted.Text = txtEncrypted.Text & sCodedLetter Exit Sub keypresserror: 'Should not be needed, but is a good idea MsgBox ("lookup error on " & Chr(34) & sletter & Chr(34) _ amp; ":" & Chr(34) & keyascii & Chr(34)) sCodedLetter = sletter Resume Next Exit Sub End Sub b. See solution posted from the Project 2 web page (also was a handout in class). Tons of people were on the right track, although few got it perfectly right. We got this interesting comment: "Do you really expect me to memorize your code?" I answered it seriously at the time, but in retrospect perhaps the person was just joking. |