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)

 

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.

 

  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.

 

 

 

 

 

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

 

 

 

 

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

 

 

 

 

 

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

 

 

 

 

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

 

 

 

  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;

 

 

 

 

 

 

 

 

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.

 

 

 

 

 

 

 

 

 

 

 

 

  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.

 

 

 

 

 

 

 

 

 

 

  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.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  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.