SAMPLE EXAM

FIT100 University of Washington
Midterm #2
Friday, March 1, 2002

Closed book, closed notes, closed neighbor, no calculators
2 points per part except as noted

 

1.

 

An algoirithm must be explicit about how to work the computation. 

Which property of an algorithm addresses this? 

 

 



Definiteness

 

 Cf. lecture slide PTopics-19, almost letter-for-letter.  Answer: 3

  

2.

 

In a book about VB, you see this function:

Right(x, n)   

Given this information, what would be displayed in the caption by the statements shown

Dim course as String

course = "CSE100/INFO100"

lblMyLabel.Caption = Right(course, 5)

“FO100”

_____________________________

Dim course as String

course = "CSE100/INFO100"

lblMyLabel.Caption = Right(course, 8)

“/INFO100”


Cf. lecture slide PTopics-26

   


 

3.

 

What is the value of y after the form has been loaded?

 

 

 

The answers were 60 or 42, depending on the exam you had.


Cf. lecture slide PTopics-20.  Save until final exam

   

4.

 

If you saw this in a VB program:

Private Sub cmdBlue_Click()
 
   frmFirst.BackColor = vbBlue
 
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.

___ vbBlue is a pre-defined Visual Basic constant

 

 

   

 

 

 

5.

 

Which of these makes a label show on a form?  Circle exactly one.

 

lblALabel.Visible = True

 

   

6.

 

The reason for putting Option Explicit at the top of your code is (circle one):

It alerts you with an error if you use an undeclared variable.

 

   

7.

 

If x and y are Integer variables, which of the following are possible VB statements?  Circle all that apply.

x = y

y = x + 2

 

   

 

8.

 

    Dim phrase1 as String
    Dim phrase2 as String    
    Dim count as Integer    
    phrase2 = "USA"
    phrase1 = "Team:   "    
    count = 5    
    phrase2 = phrase1 & count    
    Msgbox(phrase2)

What shows up in the message box? Choose one.

Team:   5

    Dim phrase1 as String
    Dim phrase2 as String    
    Dim count as Integer    
    phrase2 = "Team"    
    phrase1 = "USA:  " 
    count = 5    
    phrase2 = phrase1 & count    
    Msgbox(phrase2)

What shows up in the message box? Choose one.

USA:   5

 

   

9.

 

Using Do-While, create a loop that will print from 900 to 0 by 3. 

Dim x as Integer

x=900

Do while x >-1

     Print x

     x = x-3

Loop

 

 

Using Do-While, create a loop that will print from 800 to 0 by 2. 

Dim x as Integer

x=800

Do while x >-1

     Print x

     x = x-2

Loop


No.  It's a step-step description of something that happened once.  It's not a set of instructions for how to do something.

   

10. 3pts.

 

What is the difference between a value and a variable?

 

 

Variables are locations in memory where values can be stored, accessed, changed (vary).  Values are the pieces of data that are stored in variables.

 

 

   

11.

 

Name two common event handlers and explain how they are triggered.

1. Click: calls the click event procedure for the control when it is clicked

2. Load: calls the load procedure when the application is loaded/opened.

Name two built in functions and explain what they do.

1. UCase: Converts contents/string to the uppercase equivalent (if there is one)

2. Len:  Counts and returns the number of characters in a given string

 

 

12.

 

Private Sub txtInput_KeyPress (KeyAscii as Integer)
lblOutput.Caption = txtInput.Text & “  COMMA”
txtInput.Text = “”
End Sub

From this example, give the name of something which illustrates each of the technical terms.

Concatenation operator: &

 

Parameter: KeyAscii or KeyAscii as Integer

Property: Caption or Text


save until final?

 

13.

 

In this VB statement:

 
    If code1=code2 Then
         newletter = "Z"
    End If
    

how is the part

  code1=code2  

best described?  Pick one.

___ A condition

 

 

   

14.

 

_______________ are a means of performing the actual computation in a program.  They are formulae made from variables and operators.

 

Expressions

A ____________________________ consists of three parts: name, definition and parameters

 

 

Procedure Declaration

See slide IProg17

   

15.

 

What is the difference between the Name of an object and its caption?

 

Name is the how you reference the object in code and then any properties.  Not seen by users

Caption is a property of some objects and is seen by users at runtime

 

   

16.

 

1000 students have signed up for ARCH200 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 0002323 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 1 is OK.]

Answer to a: 1000 or 999 accepted

 

Answer to b: 9 or 10 or 11 accepted

Space for calculations (show your work!)

 1000\2 = 500
 500\2 = 250
 250\2 = 125
 125\2 = 62
 62\2 = 31
 31\2 = 15
 15\2 = 7
 7\2 = 3
 3\2 = 1


a. about 500, if the student is last on the list, or not on the list

b. 500,150,125,63,32,16,8,4,2,1 -- 10 steps at most

      

17.

 

Assume the variables homeFinal and awayFinal have been declared as Integer and have values assigned to them (as the final scores for each team). 

Also, assume the variable win has been declared to be a String.  Based on the values in homeFinal and awayFinal, write the VB6 code to set the variable win to “Home” if the home team won the game, to “Away” if the away time won the game, and to “Tie” if the final scores are tied.

 

  If homeFinal > awayFinal Then
               win = “Home”

  Elseif homeFinal < awayFinal  Then
                win= “Away”

  Else
                  win = “Tie”

  End if

Assume the variables homeScore and awayScore have been declared as Integer and have values assigned to them. 

Also, assume the variable win has been declared to be a String.  Based on the values in homeScore and awayScore, write the VB6 code to set the variable win to “Home” if the home team won the game, to “Away” if the away time won the game, and to “Tie” if the final scores are tied.

 

  If homeScore > awayScore Then
               win = “Home”

  Elseif homeScore < awayScore  Then
                win= “Away”

  Else
                  win = “Tie”

  End if

 

 

18.

 

The function Asc is used (mark all that apply):

 

_____to convert from ASCII String to Integer

 

The function Chr is used (mark all that apply):

 _____to convert from Integer to ASCII String


ASCII String to Integer

 

  

19.

 

The following two statements are legal in VB:

Dim Z as Integer

Z = 1

In a math textbook, you might also see an equation like

Z = 1

Is there any essential difference?  Explain briefly.

In programming, the = symbol means that going from right to left the expression or value on the right is assigned to the location in memory with the name Z on the left.  This assignment occurs at that moment in the code and can change later on.

 

In math, = means “equal to”, a fact that does not change in the problem to be solved.


suggested by Rachel Frodham

   

20.

 

In modern programming languages variables must be declared (e.g., in VB6 we write DIM num As Integer).  Why are variables declared?

-any 2 received credit

-to set aside a space in memory

-to determine the size needed for the space (type)

-to alert program to scope of variable

-to help debug by knowing what values are accepted to a memory location


lets the programmers stop execution at a breakpoint, and inspect values of variables at that point.

1 point if at least one answer is marked, and there is no more than one incorrect mark.

  

21.

 

What does this print out?

 

Dim x As Integer

x=20

If x > 10 Then

     Print “Hola”

ElseIf x > 18 Then

     Print “Amigo!”

Else

     Print “Como estas?”

End If

Print “Hasta!”

 

  Hola

  Hasta!

 

What does this print out?

 

Dim x As Integer

x=20

If x > 20 Then

     Print “Hola ”

ElseIf x < 18 Then

     Print “Amigo!”

Else

     Print “Como estas?”

End If

Print “  Hasta!”

 

Como estas?

  Hasta!


incomplete.-a collection of structured data organized in tables. Follows certain rules
that govern how it should be structured.
save until final

  

22.

 

Mark all that apply about procedure parameters

______ actuals must match formals in
            number and type

______ output parameters must be 
            variables

 

 

 

   

23.  

 

  A ____________________ is a specialization of an algorithm to a particular situation

 

Program OR Application OR Executable OR Procedure

 A ____________________ is a precise, systematic method for deterministically producing a specified result

Algorithm


a. tests conditional and on error flow.

b. tests iteration and collection access.

 

24.

 

Whenever the same operations are performed in different places in a program, there is and opportunity for what?

 Procedural abstraction /  OR

Creation of a procedure


a. tests conditional and on error flow.

b. tests iteration and collection access.

 

25.

 

True

Every program is an algorithm, but not all algorithms are programs.

 

Explain your answer:

Algorithms are abstractions and are not precise enough, or in the correct notation, to be programs.  Programs have taken the instructions of an algorithm and made them specific to the notation of the language.

 False

All algorithms are programs, but not all programs are algorithms.

Explain your answer:
Every program is a specialization of an algorithm to a particular situation, in a particular language, but algorithms themselves are too general to be a program without some manipulation in a particular notation.

 

 


a. tests conditional and on error flow.

b. tests iteration and collection access.

 

26.

 

Name the 2 components required in an iteration statement.

Loop body and a stop condition

 

 


a. tests conditional and on error flow.

b. tests iteration and collection access.

27.

 

It is common in programming to test 2 or more relational expressions together.  What is used to combine these expressions?

logical operators

 


a. tests conditional and on error flow.

b. tests iteration and collection access.

28.

 

Assume you have a Collection with the name myBooks.  The author last names are considered the keys.  Write the code to do the following three things:

 

 

Remove the title “Lord of the Rings”
where “Tolkein” is the key

mybooks.Remove “Tolkein”

Add the title “Fellowship of the Ring”
where “Tolkein” is the key

mybooks.Add “Fellowship of the Ring”, “Tolkein”

Display the title for a book by “Clancy”

mybooks.item (“Clancy”)


a. tests conditional and on error flow.

b. tests iteration and collection access.

 

29.

 

What does the following code print out?

Dim x as integer

x=4
For x = 4 to 6
     Print x & “ o’clock”
Next x
Print “rock!”

 

4 o’clock

5 o’clock

6 o’clock

rock!

What does the following code print out?

Dim x as integer

x=1
For x = 1 to 3
     Print x & “ o’clock”
Next x
Print “rock!”

1 o’clock

2 o’clock

3 o’clock

rock!


a. tests conditional and on error flow.

b. tests iteration and collection access.

 

30.

 

What is the Substitution Rule?

 

When calling a procedure, the substitution rule is the idea that one can substitute, at the call site, the body of the procedure from the declaration. 

The formal parameters are replaced by the actual parameters and the code is executed as if no call had been made.


a. tests conditional and on error flow.

b. tests iteration and collection access.

EC answer:  Enigma!