“Computer Science 230 – Fall 2004

09/30/04                      Mid Term Test # 1                 Test Form A

 

Name:

 

Instructions:

            Answer ALL questions on the answer sheet provided.

            Hand in TEST, Answer Sheet, and Help Sheet, each with your name on it.

            Remember to put the letter of your test form on your answer sheet.

            Please ask any clarifying questions you have (come up).

 

Completion (3 points each)

 

  1. _________ are a tool used to plan a procedure. In these, diagrams are used to illustrate the steps needed to accomplish a goal.

 

  1. A type of error that is caught while the program is running, ________ errors cannot be caught by the compiler, but result in the program stopping (“crashing”).

 

  1. If the statements inside an if statement, include another if statement, we refer to the second if statement as ________ inside the outer if statement.

 

4.      A(n) __________ is a piece of information passed to a method.

 

 

True/False (2 points each)

 

  1. The string “985” and the integer 985 are stored the same way inside computer memory.

 

6.      The computer will not print an error message when a logic error occurs.

 

7.      A variable can appear on both sides of the assignment operator in the same assignment statement.

 

 

Multiple Choice (3 points each)

 

  1. Which of the following is true about designing an interface?

A)     It is desirable to put the most important information at the bottom of the form

B)     Controls should NOT be aligned, due to the excess space needed for that approach

C)     The flow of the form should be top to bottom and/or left to right

D)    Use as many colors as possible to aid in distinguishing one control from another

E)     None of the above

 

  1. Which of the following is true?

A)    Specifying Option Explicit On and Option Strict On will result in having to write extra code to accomplish the same thing

B)     Option Explicit On and Option Strict On, if specified, are specified near the top of the module (code file)

C)     Specifying Option Explicit On and Option Strict On will help you by causing the IDE to catch some of your silly mistakes for you

D)    All of the above

E)     None of the above

Valid/Invalid – Variables (5 points total)

 

  1. For each of the following, tell if it is a LEGAL variable name (follows syntax rules), and if it is illegal, tell why.

A)    2ndPlace

B)     FirstPlace

C)     third   place

D)    winnerGame3

E)     Cost$

 

 

Valid/Invalid (4 points each)

For each, tell whether valid or invalid. If invalid, tell why!

Generally they are taken out of context, we assume that valid context surrounds them (e.g. inside a program, variables declared, given values if necessary,  etc)

 

  1.  

if hours <= 40 Xor salary > 100000 then

     pay = basePay

else

     pay = basePay + overtime

end if

 

  1.  

Select case stdNum

               Case 1 to 1000

                              Msgbox(“freshman”)

               Case 1000 to 1999

                              Msgbox(“sophomore”)

               Case 2000 to 2999

                              Msgbox(“junior”)

               Case else

               Msgbox(“senior”)

end select

 

  1.  

  const wet as integer = 5;

  wet = wet + 1;

 

  1.  

Dim z as integer

Dim x as integer

z = 5

x = 6

z + 4 = x

 

Short Answer (points as shown)

 

 (4 points)

  1. The default tab indexes for controls in a form are determined based on what?

 

 (6 points)

  1. Why is it a good idea to use named constants when you need a specific value in your program? (two good reasons)

 

 

Doing and Understanding: (5 points each)

 

  1. Show what is displayed in message boxes

 

Dim wacky as integer

Dim weird as integer

                              Dim psycho as integer

                              Dim worriesome as integer

 

                              wacky = 12

                              weird = 34

                              psycho = 45

                              worriesome = 33

                              if (wacky >weird) then

msgbox(“wacky”)

elseif (psycho > worrisome) then

msgbox(“psycho”)

elseif (weird > worrisome) then

msgbox(“weird”)

elseif (wacky > psycho) then

                                             msgbox(“help!”)

                              else

                                             msgbox(“talk”)

                              end if

                              msgbox(“last”)

 

 

  1. Show what is displayed in message boxes by the following code fragment:

 

  Dim a as integer

  a = 8;

  if (a > 5) || (a < 0) then

     msgbox("ifthen");

else

     msgbox("else")

end if

 

 

  1. Show what is displayed in message boxes by the following code fragment:

 

Dim x as integer

x = 5

if (x > 3) then

     if (x < 10) then

          x = x + 1

     else

          x = x + 2

      end if

else

     x = x + 3

end if

msgbox( x.toString(“n0”)

 

 

  1. Show what is displayed in message boxes by the following code fragment:

Dim color as integer

color = 3;

select case color

case 1

        msgbox ("red ")

case 2

        msgbox ("red ")

case 3

        msgbox ("blue")

case 4:  

        msgbox ("purple")

Case else

        msgbox ("gray")

End select

 

 

Writing Code (points as shown)

 

(10 points)

  1. Assuming that a user has entered a value for the txtbox “txtPrice”, write Visual Basic statements to make sure that price will be valid (numeric, between 0 and 50, inclusive). In the place in your code where you have detemined that the price is valid and normal processing can happen, you can put “…” for whatever the program is supposed to do.

 

 

(15 points)

  1. Assuming that a user has entered VALID values in text boxes “txtPayRate” (pay per hour, regular time), and “txtHrsWorked” (hours a person has worked in a week), and that the company pays the pay rate for up to 40 hours, and “time-and-a-half” (1 ½ times normal pay rate) for any hours worked above 40, write a sequence of Visual Basic statements to calculate and display the gross earnings (“txtEarnings”) for the week.