Fall 2002 Test #1
CSE1320 Sections 003 and 501
Thursday, September 12 2002 Dr. Tiernan
Name: Section:
Student ID: Keyword:
Instructions:
1. Fill in your name, student ID, and section above. Choose some keyword for yourself that I can use to anonymously post grade information. If you do not choose a keyword, I will use the last four digits of your student ID to post grade information if needed.
2. This is a closed book, closed notes, NO CALCULATOR test.
3. The test is worth a total of 100 points. The value for each question is given either at the top of that section of questions or in curly braces to the right hand side of the question. There are extra credit questions at the end of the test worth an additional 10 points total.
4. NO CHEATING!
Multiple choice questions are worth four {4} points each. Please circle the letter indicating your choice for the answer.
1. Which of the following is equivalent to the statement k *= b++ - pow(y,2);
A) k = k * b++ - (y*y);
B) k = k * (b – (y*y)); ++b;
C) b = b – pow(y,2); b++; k = k * b;
D) k = k * (b+1) – (y*y);
2. Which of the following is NOT equal to 34110?
A) 15516
B) 01010101012
C) 3110 * 1110
D) 30110 + 4110
3. Which of the following is NOT true about arrays in C?
A) Memory spaces are allocated in a contiguous block
B) The last array index is always one less than the total number of array elements
C) The first array index is always 1
D) Arrays are not automatically initialized at declaration.
4. Given the code fragment below, indicate whether the following expressions will be true (T) or false (F). {8 points total ; 2 each}
int check = 7;
float none = 10.0;
short ary[5] = {0};
int next = 1;
i) ~check && (none + ary[2])
ii) next || ary[0]
iii) check >> 3
iv) !none
5. Given the following code fragment, answer the questions below:
int testfunc(int k) {
if (k > 100)
printf(“The input k is %d\n”,k);
else {
int k = 12;
while (k % 5) {
for (int k = 25; k > 0; k -= 5)
printf(“The for loop k is %d\n”,k);
k--;
printf(“The while loop k is %d\n”,k);
}
return k;
}
return k;
}
A) If the above function is called by the main routine with the call testfunc(101); write the output that will be produced by testfunc. {6}
B) If the above function is called by the main routine with the call testfunc(19); how many lines of output will be produced by testfunc and what value will be returned? {8}
Total number of lines of output Returned value
C) If the above function is called by the main routine with the call testfunc(35); what values will k have during the execution of testfunc? Write all the unique values below. {8}
D) What would you change in the function testfunc to improve the understandability of the code? {4}
6. Convert the following numbers to binary, writing the bit patterns in the spaces provided, and then use the ^ operator to combine them and put the resulting pattern in the last set of spaces. {14}
|
|
210 |
29 |
28 |
27 |
26 |
25 |
24 |
23 |
22 |
21 |
20 |
|
87310 = |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29210 = |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87310 ^ 29210 |
|
|
|
|
|
|
|
|
|
|
|
7. A) Declare an array of twelve floating point numbers named expenses and intialize it with 12 unique values. {6}
B) Using the array that was just declared, write a for loop that prints each value in the array and sums the values in the array and then prints the sum after all the values have been added. {10}
8. Given the declarations below, give the resulting data type for each expression below:
{12 total; 2 each}
char a, b;
int j, k;
short l, m;
float g, h;
double c, d;
long double e, f;
A) a + c + e
B) j * k * m
C) f > h
D) m – b
E) d = l
F) k / g
9. Write a code fragment to read in two values from the keyboard, a floating point number and a single character. Save these values in two variables called flnum and onechr. Then if flnum is positive, multiply it by two and print the product in 10 spaces with two spaces for the fractional part. If not, add 100 to flnum and print the sum. Next if onechr is a character past ‘?’ in the ASCII chart, print “Second half”, else print “First half”. {12}
Extra Credit questions - Worth two {2} points each.
XC1. Which of the following is NOT in the ANSI C standard library?
A) studio.h
B) float.h
C) math.h
D) limits.h
XC2. An nested if statement is an example if what type of control structure?
A) sequential
B) repetition
C) serial
D) selection
XC3. The %G conversion specifier
A) allows longs to be printed in either exponential or decimal point notation
B) always outputs floats with a capital ‘E’
C) defines the exact width of the printed output
D) lets the computer choose how to format a printed double
XC4. In a sign bit representation the sign bit
A) represents whether the data type is signed or unsigned
B) is the low order bit
C) represents a negative or positive sign
D) holds the computer designer’s signature
XC5. Type casting in C is
A) allowing the computer to change types automatically during evaluation
B) explicitly forcing a temporary data type change
C) making an actor always play the same type
D) fishing for the correct type