Quiz 2                                                                                                                    Name: _____________________

 

CPSC 110                                                                                                             ID: ________________________

 

(c)opyright 2002 Brent M. Dingle                                                                   Section: ____________________

 

                                                                                                                                TA: ________________________

 

INSTRUCTIONS:

All answers should be PRINTED. If I am not able to easily read the answer, you will NOT receive any credit for it. Please use a PENCIL and an eraser (if/when needed).

 

Part I  - True or False, Circle your answer  ( 20 points, 2 points per question)

 

True or false questions are either right or wrong – no partial credit.

 

1.

True  or   False

A compiler can detect syntax and logical errors.

 

 

 

2.

True  or   False

In DOS, the character ‘?’ is a wild character.

 

 

 

3.

True  or   False

DOS directories are tree structured.

 

 

 

4.

True  or   False

Blaise Pascal is the original creator of the Pascal programming language.

 

 

 

5.

True  or   False

A variable name may have spaces in it.

 

 

 

6.

True  or   False

A variable of type integer has NO maximum value that it can contain.

 

 

 

7.

True  or   False

A floppy disk is one example of the main memory used in a computer.

 

 

 

8.

True  or   False

Every IF statement must have an ELSE following it.

 

 

 

9.

True  or   False

The result of  7 MOD 3 is 2. 

 

 

 

10.

True  or   False

The decimal equivalent of the binary number 1011 is 11.

 

 

 

 

 

 

 

 

 

 

Part II  - Multiple Choice, (20 points, 4 points per question)

    Select the best answer by circling A, B, C, D, or E in the boxes.

 

Multiple Choice questions are either right or wrong – no partial credit.

 

  1. Which of the following is NOT a legal Pascal Variable?
    1. 2_ABC13
    2. A_BC_321
    3. _ABC123
    4. A_BC123
    5. A_2BC13

 

Answer 11:

A

B

C

D

E

 

 

  1. If you were to give someone a hardcopy of your program, you would give them what?

a.       The hard disk on which the program was saved.

b.      A printout of the program.

c.       A CD-ROM with the source code burned on it.

d.      A 3 1/2 inch floppy disk with the program saved on it.

e.       A picture of the program's output.

 

Answer 12:

A

B

C

D

E

 

 

  1. In this class, a set of instructions that leads to a solution is called?

a.       an order set

b.      a solution set

c.       a procedure

d.      an algorithm

e.       an implementation

 

Answer 13:

A

B

C

D

E

 

 

  1. How many bits are in a byte?

a.       16

b.      8

c.       6

d.      4

e.       2

 

Answer 14:

A

B

C

D

E

 

 

  1. Which of the following can never be used as a variable name in Pascal?

a.       sum

b.      average

c.       next

d.      first

e.       program

 

Answer 15:

A

B

C

D

E

 

 

 

Part III  - Short Answer  ( 25 points, point values vary), Circle your answers.

 

  1. (5 points) Assuming no syntax errors, in one sentence, what is the (range of) output of the below program?

 

PROGRAM Shrug;

VAR

   num : integer;

 

BEGIN

   Randomize;

   num := Random(100);

   Writeln(num);

END.

 

Correct answer is:   0 to 99 (worded however they wanted)

Give one point if they said 1 to 100

Any other answer is no points.

 

  1. (6 points) What are six comparison operators in Pascal?

 

=, <>, >, >=, <=, <   2 points for each correct

Do NOT deduct for any incorrect, such as != (unless they also have <>)

 

  1. (4 points) Name FOUR built in data types in Pascal?

 

char, integer, real, boolean   2 points for each correct

Do NOT deduct for any incorrect, such as int (unless they also have integer)

 

  1. (1 point) What is the assignment operator in Pascal?

 

:=   (or colon equals)

 

 

  1. (1 point) The function trunc(53.69) will return what?

 

53

 

  1. (8 points) What is the output of the below code (assume it is embedded in a working program)? – Be advised there is no partial credit on this.

 

count := 0;

A := 1;

B := 1;

while (count <= 4) do

BEGIN

            count := count + 1;

            B := B + 1;

            A := A + B - count;

            write(A, '  ');    { there is a space between those single quotes }

END;

 

Run it and find out, be lenient on the spacing between numbers.

If they don’t have the correct result then they get ZERO points.

 

 

 

 

Part IV  - Programming  ( 35 points, point values vary)

     Be as ‘brief’ as you think possible. Use GOOD coding style!

(hint: excluding comments the first word of a Pascal program is PROGRAM)

(and if you make a minor syntax error don’t worry about it)

 

  1. (5 points) Write a Pascal program (using less than 10 lines/statements) that will print just the word: ‘Howdy,’ to the computer screen. There is no partial credit.

 

 

If it prints Howdy to the screen give them the 5 points.

If it prints other stuff or nothing give them zero points.

Don’t worry about semi-colons or periods.

 

 

 

 

 

 

 

 

  1. (8 points) Write the 4 lines/statements of code to open a text file named C:\out.txt., write the words ‘Why hello there’ to the file, and then close the file. Assume you want to completely overwrite the file (or create a new one if it does not already exist). Assume the variable named out_file is declared as type TEXT.

 

assign(out_file, ‘C:\out.txt’);              = 2 points

rewrite(out_file);                                 = 2 points

writeln(out_file, ‘Why hello there’);   = 2 points

close(out_file);                                     = 2 points

 

(don’t worry about capital letters or punctuation)

 

 

 

 

  1. (10 points) Write a Pascal program that uses a WHILE-LOOP (and less than 15 lines/statements) that will print the numbers 1 to 5, each on their own line, to the computer screen. There is no partial credit on this problem.

 

PROGRAM la;

VAR

count : integer;

BEGIN

count := 1;

while (count <= 5) do

BEGIN

         Writeln(count);

          count := count + 1;

END;

END.

 

If you type in what they write and it doesn’t produce the 1, 2, 3, 4, 5 on separate lines then ZERO points. NOTE: Missing semi-colons are ok, as is a semi-colon after the do – but circle where they should be. Variable names will vary.

 

 

 

 

 

 

 

 

  1. (12 points) Write a program that asks the user to input a number from 1 to 10. If the number is greater than 6 the computer should output the word: ‘Pass.’ Otherwise if the number is less than or equal to 6 the computer should output the word: ‘Fail’. After outputting the correct word, your program should end. This should not take more than 25 lines of code.

 

 

PROGRAM la;

VAR

          num : integer;              1 point for var declaration

BEGIN

          Writeln(‘Enter a number from 1 to 10’);        2 pts for prompt

          Readln(num);                                               2 pts for readln

 

          If (num > 6) then                       2 pts for this condition (or equiv)

                   Writeln(‘Pass’)               1 pt for the output of Pass

          Else                                          2 pts for this condition (or equiv)

                                                          (they may use an else if or just

another if)

                   Writeln(‘Fail’);                1 pt for output of Pass

END.

 

1 point for having anything that counts as a COMPLETE program (like a program name, a Begin and an End)

 

Do not be concerned with lack of semi-colons.

However if they put a semi-colon before an ELSE or after a THEN you should deduct one point from that ‘condition’ and circle the semi-colon.

 

If any of the programs are difficult/impossible to read or have way too much ‘extra/pointless’ lines of code you may deduct up to 2 points for every such problem, and make reference to the instructions at the beginning of the test and at the beginning of the section – consult with the other TA’s to establish consistency if you do this – it “shouldn’t” be necessary.

 

If they took the test using INK make a note that the directions requested the use of a pencil, but do NOT penalize them.