Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSC107 F06 Midterm #1 – Exam Questions - Prof. Matthew A. Hertz, Exams of Computer Science

A midterm exam for a c programming course, consisting of multiple-choice questions and programming tasks. The questions cover topics such as variable naming, data types, arithmetic operations, symbolic constants, loops, and conditional statements.

Typology: Exams

Pre 2010

Uploaded on 08/19/2009

koofers-user-twg
koofers-user-twg 🇺🇸

5

(1)

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name: CSC107 F06 Midterm #1 Page 1
Problems:
1. [10 * 1 points] State whether each of the following names is a:
GO OD VARIABL E NAM E -or-
GOOD SYMBOLIC CONSTANT NAME -or-
STYLISTICALLY POOR VARIABLE NAME -or-
RE SE RVED WO RD -or-
OTH ER I LL EG AL VAR IA BL E NAM E
(a) [1 points] counter good variable name
(b) [1 points] 3141519 stylistically poor variable name
(c) [1 points] sigma2nd good variable name
(d) [1 points] voidableCost good variable name
(e) [1 points] 2ndInput other illegal variable name
(f) [1 points] GRAV CONSTANT good symbolic constant name
(g) [1 points] powerOf2 good variable name
(h) [1 points] UNION good symbolic constant name
(i) [1 points] floor good variable name
(j) [1 points] costIn$ other illegal variable name
pf3
pf4
pf5

Partial preview of the text

Download CSC107 F06 Midterm #1 – Exam Questions - Prof. Matthew A. Hertz and more Exams Computer Science in PDF only on Docsity!

Problems:

  1. [10 * 1 points] State whether each of the following names is a:
    • GOOD VARIABLE NAME -or-
    • GOOD SYMBOLIC CONSTANT NAME -or-
    • STYLISTICALLY POOR VARIABLE NAME -or-
    • RESERVED WORD -or-
    • OTHER ILLEGAL VARIABLE NAME

(a) [1 points] counter good variable name

(b) [1 points] 3141519 stylistically poor variable name

(c) [1 points] sigma2nd good variable name

(d) [1 points] voidableCost good variable name

(e) [1 points] 2ndInput other illegal variable name

(f) [1 points] GRAV CONSTANT good symbolic constant name

(g) [1 points] powerOf2 good variable name

(h) [1 points] UNION good symbolic constant name

(i) [1 points] floor good variable name

(j) [1 points] costIn$ other illegal variable name

  1. [5 * 4 points] Compute the value and datatype of each of the following expressions. If an expression is “boolean”, write down the result as “zero” or “non-zero”. You must show your work to earn partial credit.

(a) [4 points] toupper(‘b’ + 3) ⇒ toupper(‘e’) ⇒ Value is ‘E’ which is a char

(b) [4 points] 3 / ceil(3.0 + 0.1) ⇒ 3 / ceil(3.1) ⇒ 3 / 4 ⇒ Value is 0 which is an int

(c) [4 points] 7 + (^6) * sqrt(9) ⇒ 7 + 6 * 3.0 ⇒ 7 + 18.0 ⇒ Result is 25.0, a double

(d) [4 points] fabs(-3) / 2 ⇒ 3.0/2 ⇒ Value is 1.5 which is a double

(e) [4 points] !isupper(‘a’) || isalnum(toupper(‘.’))⇒ !”false” || isalnum(‘.’) ⇒ “true” || “false” ⇒ Result is “true” (non-zero), a “boolean”

  1. [25 total points] For this problem, write the C statements (not full programs) that perform the actions desired. You should assume that all variables have been declared and are appropriately defined.

(a) [15 points] Uses a loop to compute and print out the first 15 powers-of-two (e.g., 2^0 , 2^1 , 2^2 , · · ·, 2^14 )

for (power = 0; power < 15; power++) { printf(‘‘%.0lf\n’’, pow(2, power)); }

(b) [10 points] If the variable counter is greater than 5 and less than 10, assign the variable inRange the value 1. Otherwise, inRange should be set to 0.

if ((counter > 5) && (counter < 10)) { inRange = 1; } else { inRange = 0; }

  1. [2 * 10 points] Generate a trace and show the output for the following snippets of C code. If a loop will not terminate, show the first 3 iterations of the loop and state that the loop is infinite.

(a) [10 points] for (i = 0, j = 1; i < j; i++) { switch(i) { case 2: printf(‘‘Two’’); case 1: printf(‘‘Two’’); case 0: printf(‘‘One’’); case 3: printf(‘‘Three\n’’); break; case 4: printf(‘‘Four’’); break; default: printf(‘‘Something else\n’’); break; } } line# i j Output 0 0 1 1 4 One 5 (on same line as above) Three 6 12 1 0

(b) [10 points] int i = -1, k = 20; do { printf(‘‘%d\n’’, k); i += 1; } while(i = 0); line# i k Output 0 -1 20 1 2 20 3 0 4 0