Docsity

CPSC 206 Fall '07 Exam 1 Sample: Structured Programming in C, Exams of Computer Science

Toggle sidebar
bg1
CPSC 206 Structured Programming in C, Fall ’07 EXAM 1 SAMPLE September 28, 2007
Ronnie Ward 2 9/26/2007 1
*************************************************************
* READ THE INSTRUCTIONS BELOW NOW *
* DO NOT LOOK AT THE EXAM UNTIL INSTRUCTED TO DO SO *
*************************************************************
Last name, First Name ______KEY___________________________________________
Last 4 digits of UIN ______________ Write your section number: _________________
The value of individual problems (eg. 10) is shown as [10] next to the problem number.
Do not look at your neighbor’s answers, or share your answers with your neighbor!
If you have a question about a problem, write your question, the answer you are
assuming, and continue. Do NOT ask a question aloud in class during the Exam!
Do NOT remove the staple or tear the EXAM packet apart! Thanks!
Verbosity is discouraged. Written answers should in good English. Neatness counts and
we reserve the right to assign lower grades for sloppiness, much lower!
This is a closed book EXAM. Also, calculators, PDAs, CD players, radios, and
headphones are NOT allowed!
You have 10 minutes to take this SAMPLE exam.
Remember:
Aggies do not lie, cheat, or steal and do not tolerate those who do!
I have obeyed the Aggie code of honor in my answers on this quiz.
Signature: ___________________________________
Date: ___________________________________
pf2

Partial preview of the text

Download CPSC 206 Fall '07 Exam 1 Sample: Structured Programming in C and more Exams Computer Science in PDF only on Docsity!

CPSC 206 Structured Programming in C, Fall ’07 EXAM 1 SAMPLE September 28, 2007

Ronnie Ward 21 9/26/

* READ THE INSTRUCTIONS BELOW NOW *

* DO NOT LOOK AT THE EXAM UNTIL INSTRUCTED TO DO SO *

Last name, First Name ______KEY___________________________________________

Last 4 digits of UIN ______________ Write your section number: _________________

The value of individual problems (eg. 10) is shown as [10] next to the problem number.

Do not look at your neighbor’s answers, or share your answers with your neighbor!

If you have a question about a problem, write your question, the answer you are

assuming, and continue. Do NOT ask a question aloud in class during the Exam!

Do NOT remove the staple or tear the EXAM packet apart! Thanks!

Verbosity is discouraged. Written answers should in good English. Neatness counts and

we reserve the right to assign lower grades for sloppiness, much lower!

This is a closed book EXAM. Also, calculators, PDAs, CD players, radios, and

headphones are NOT allowed!

You have 10 minutes to take this SAMPLE exam.

Remember:

Aggies do not lie, cheat, or steal and do not tolerate those who do!

I have obeyed the Aggie code of honor in my answers on this quiz.

Signature: ___________________________________

Date: ___________________________________

CPSC 206 Structured Programming in C, Fall ’07 EXAM 1 SAMPLE September 28, 2007

Ronnie Ward 22 9/26/

I.[18] Circle True, or False.

Assume: int k, j = 0, a = 1, b = 2, c = 3; double x, y = 1.0;

k = a > b && c < b;

j = a – y || b * c && !b / a;

1. True/False After execution of these statements, k is set to 0

2. True/False After execution of these statements, j is set to 0

3. True/False An error occurs since y is a double and a is an int

Assume: float u, v;

assert(.. .); /* assume v >= 1 */

for (u = 1; u < v; ++u) {.. .}

4. True/False a better “style” is to write 1 as 1.0 above

5. True/False !(v < 1) is a correct condition for the assert statement

6. True/False v > 0 is a correct condition for the assert statement

Assume: int x = 1, y = 2;

int i, k = 5;

for (i = 1; i <= k; ++i) x *= y;

7. True/False the for loop computes 32 as the final value of x

8. True/False the final value of x in binary is 100000

9. True/False the final value of x in hex is 0x

1. [12] Correct the common errors in the following code. Mark only what’s necessary to

correct C syntax errors and insert required C code to avoid compiler errors/warnings.

#include <stdio.h> int sum (int a, int b) { int final; int result = a + b; return result; } int main(void) { int previous, current, max; int i,next; printf("Input max number: \n" ); scanf("%d", &max); printf("The first %d Fibonacci numbers:\n", max); previous = 0; /* calculate Fibonacci numbers */ current = 1; for (i = 0; i < max; ++i) { printf ("F(%2d) = %d\n", i, previous); next = sum(previous, current); previous = current; current = next; } return 0; }