NAME:___________________ SECTION #: ________ TA:____________________

 

CLOSED BOOK - CLOSED NOTES

WRITE ONLY ON THESE PAGES - USE NO OTHER PAPER

 

NOTE: Several versions of this test have been handed out. They look similar but have different questions and answers. Please keep your eyes on your own quiz.

 

Provide short answers, or true (T) or false (F) answers, as directed for 1 through 3:

 

1. (1pt) What does "DO FORMAT" do in True BASIC?

It puts the program into proper format, capitalizes commands, etc.

2. (1 pt) The default width of a print zone in True BASIC is 1 (T or F)

F

3. (1 pt) Variable names can contain spaces (T or F)

F

4. (4 pts) Find all the errors in the following program. Circle all errors, including any omissions of required items, and explain below what the problem is.

REM "This is a simple greeting...

REM "It does some string concatenation

IMPUT PROMPT "Enter your name"; name$

INPUT PROMPT "Enter your graduation year": year$

IF year < 1998

PRINT "Congrats on graduating " & name$ & "!"

ELSE IF

PRINT "Best of luck in your studies " & name$ & "!"

END

 

Pretend that you are the computer and that you are running each of the following programs (5 through 8). Write what the output would be, one character per box:

 

5. (3 pts)

 

PRINT 2^2*3-1+2

LET u = 4 + 1 / 2 + 3

LET v = 3 - 4 + 8 * 2 / 2

LET w = 3 * 3 + 2

PRINT u

PRINT v

PRINT w

END

13

7.5

7

11

 

6. (3 pts)

 

LET a$ = "Happy"

LET b$ = "Birth"

LET c$ = "Day"

LET d = 1999

LET e$ = "."

LET f$ = a$ & " " & b$ & " " & c$

PRINT f$;d;e$

END

Happy Birth Day 1999 .

7. (3 pts)

 

LET x = 2

DO WHILE x < 6

SELECT CASE x

CASE 1

LET x = x^2*3

CASE 2

LET x = x*2

CASE 3

LET x = x - 1

CASE 4

LET x = x + 1

CASE ELSE

PRINT "I'm lost!"

EXIT DO

END SELECT

PRINT "x =";x

LOOP

PRINT "Stopped"

END

x = 4

x = 5

I'm lost!

Stopped

8. (3 pts)

 

SET ZONEWIDTH 6

LET n = 0

PRINT "n =","n doubled ="

DO

LET n = n + 2

LET y = n*2

PRINT n, y

IF n > 4 THEN EXIT DO

LOOP

PRINT "Stopped"

END

n = n doubled =

2 4

4 8

6 12

Stopped

9. (6 pts) Write a short program to repeat the following until the user indicates that they want to quit by entering a negative number: ask the user to input a number then print the square of that number.

LET number=0

DO while number >= 0

INPUT prompt "Please enter a number (-# to stop)":number

PRINT "the squared number...";number;" is...";number*number

LOOP

END


Please enter a number (-# to stop)9

the squared number... 9 is... 81

Please enter a number (-# to stop)8

the squared number... 8 is... 64

Please enter a number (-# to stop)-7

the squared number...-7 is... 49