## CSC1071 Computer Science Diagnostic Quiz## Spring 2004 |

This web page is http://www.bernstein-plus-sons.com/.dowling/CSC1071S04/CS_Diagnostic_Quiz.html

Copyright © 2002 -- 2004 Herbert J. Bernstein and other parties. All
rights reserved.

This is a computer science diagnistic quiz to be taken on the first day of class. This exam is to help you and your instructor see if you are adequately prepared (or perhaps more than adequately prepared) to take the course for which you have registered.

This exam must be the results of your own efforts.

**The ONLY use you may make of a computer in doing this quiz is to
open one browser window to bring you to the online version
of the quiz. You may not use a calculator and you may not
search for the answers on the web**

To avoid disturbing other students, you must remain seated until the end of the examination period.

- Rewrite the following fragment of code as an equivalent while loop:
j = 4; for ( i = 3; i > 0; i--) { j *= i; }

- Assuming appropriate declarations, after execution of the code fragment in question 1, what will be the final value of j?
- Briefly explain the relationship between the terms "class" and "object".
- Write a java method (or C function) that returns the integer average of
two integer
arguments.
- Write a java method (or C function) that returns the double ratio of two double
arguments, and which is protected against dividing by zero.
- Write a java method (or C function) that will sort an array of small
integers, all
known to be in the range 0-255, into ascending order. Do not eliminate
duplicates in the array.
- For each of the following problems you will be combining fractions by addition,
subtraction, multiplication, or division. Your answer must be a fraction reduced to lowest
terms. Fill in the answers after the equals sign.
Addition Subtraction Mutiplication Division 1 7 1 7 1 7 1 7 -- + -- = -------- -- - -- = -------- -- * -- = -------- -- / -- = -------- 2 16 2 16 2 16 2 16 3 5 3 5 3 5 3 5 -- + -- = -------- -- - -- = -------- -- * -- = -------- -- / -- = -------- 5 3 5 3 5 3 5 3 9 15 9 15 9 15 9 15 -- + -- = -------- -- - -- = -------- -- * -- = -------- -- / -- = -------- 11 17 11 17 11 17 11 17 11 27 11 27 11 27 11 27 -- + -- = -------- -- - -- = -------- -- * -- = -------- -- / -- = -------- 33 47 33 47 33 47 33 47 - Perform the indicated arithmetic operations. Give the answer as an integer or as a
fraction with the smallest possible denominator. Do not give your answer as a decimal
fraction. Write each answer on a single line in the indicated box.
- 4832197 + 6597875 =
- 368 - 427 =
- 468 * 827 =
- 865 / 35 =
- (43/87) + (29/137) =
- (11/12) - (23/24) =
- (19/21) * (7/8) =
- (11/13) / (18/19) =

- Perform the indicated set operations. Give the resulting set for the following
operations. Assume all sets are drawn from the universe of non-negative integers. Write
your answer after the equals sign.
- { 1, 3, 5, 7 } ∪ { 2, 4, 6, 8 } = { }
- { 1, 3, 5, 7 } ∩ { 2, 4, 6, 8 } = { }
- { 1, 3, 5, 7 } ∩ ¬ { 2, 4, 6, 8 } = { }

- The straight-line distance from city A to city B is 312 miles. The
straight-line
distance from city B to city C is 175 miles. What are the smallest and the largest possible
values of the straight-line distance from city A to city C.
Smallest:

Largest: - What is the sum of all the natural numbers from 17 to 1005?
- What is the sum of all the powers of 2 from 4 to 256?
- Consider the following code fragment. What will be the value of m at the end?
int n,m; n = 3; m = 5; switch(n){ case 1: m = 7; break; case 2: m = 8; break; case 3: m = 9; case 4: m = 10; break; default: m = 11; }

- Explain the meaning of a pointer.
- Explain the meaning of a cast.
- Explain the meaning of an array.
- Explain the meaning of a formal parameter.

<==== **Do this AFTER you've answered all the questions**

**You probably DON'T want to do this ===> **