Spring
2004 Test #1
CSE1320 Sections
501
Tuesday, March 2, 2004 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 cannot post your grade information if needed.
2. This is a OPEN 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 two {2} points each. Please circle the letter indicating your choice for the answer.
1) Which of the following would you use to help determine how many bits are in a long int?
A) INT_BIT
B) CHAR_BIT
C) ULONG_MAX
D) LONG_MAX
2) Which of the following refers specifically to functions?
A) double indirection
B) dereference
C) addressing operator
D) prototype
3) Which of the following is NOT a valid array initialization?
A) int Anka[5],i; for(i=0; i<5; i++) Anka[i]= i;
B) char Abner[4] = {L,i,l,\0};
C) float Ahmed[5] = {0};
D) int Alf[3]; Alf = {3, 6, 9};
4) Which of the following is NOT a characteristic of strings in C?
A) Strings can be contained in arrays of characters
B) Strings must end with the end-of-string marker \0
C) Strings are a data type and can be declared
D) Strings can be processed with library functions
5) Describe at least two uses of each the following symbols or operators in C. {6 points total ; 2 each}
(
)
&
*
6) Write a function prototype for a function that takes in three parameters - a long double, a string, and an array of ints and returns a pointer to int. {3}
7) Write a print statement that can print all of the following as specified in order with a single space between each item: {3}
an integer named Bo in 5 spaces
a float Buster in exponential form with a capital E
a long double Bee in floating point format with 10 places total and 4 to the right of the decimal
the string constant Bama
8) Convert the sum of 63510 and 1216 to binary. {6}
The sum in decimal is .
In binary,
|
|
|
|
|
|
|
|
|
|
|
210 |
29 |
28 |
27 |
26 |
25 |
24 |
23 |
22 |
21 |
20 |
9) Write code fragments to do the following:
A) Declare a variable that can hold the address of an integer. Use this variable to allocate enough space to hold 25 integers and initialize that space to all zeros. {3}
B) Use pointer arithmetic to access the 10th integer in the newly allocated space and put your age into that element. {3}
C) Use array notation to access the 3rd integer and store the year of your birth there. {2}
D) Add the 10th value and the 3rd value and store it in the last location you allocated. {3}
E) What value is stored in the last location? {2}
10) Given the code below, if the user enters the values 13 and 60, what will the value of result be in decimal? {6}
int val1, val2, result;
scanf( %o %o, &val1, &val2);
result = val1 | val2;
The value of result in decimal is:
11) Given the function prototype below,
int numodd (int n);
A) write the function numodd such that is sums up the first n odd numbers (starting with 1) and returns the sum. Your function should use a counted loop and should print the sums during each iteration. {7}
B) Show the all of the output of your function numodd if the input is 6; {6}
12) Given the following code fragment, fill in {9}
Hex 2-byte address |
Value |
Variable name |
AB08 |
|
|
AB0A |
|
|
AB0C |
|
|
AB0E |
|
|
AB10 |
|
|
AB12 |
|
|
AB14 |
|
|
AB16 |
|
|
AB18 |
|
|
AB1A |
|
|
AB1C |
|
|
AB1E |
|
|
AB20 |
|
|
AB22 |
|
|
AB24 |
|
|
AB26 |
|
|
AB28 |
|
|
AB2A |
|
|
AB2C |
|
|
the memory diagram on the right with the
appropriate values and variable names if
short takes 2 bytes, char takes 2 bytes, int
takes 4 bytes, float takes 6 bytes, double
takes 8 bytes, and addresses take 4 bytes.
float macys = 120;
short cakes;
int edgar[3] = {1};
char bear = O;
float *spq = macys;
char *sean = 007;
int *poe;
short stuff = 42;
poe = (edgar+2);
*(poe+1) = 100;
bear = sean[2];
cakes = (short) macys;
13) Given the declarations below, {7}
int zary[50];
int j, count, k;
/* assume that zary has been initialized with a random selection of integer values */
write a repetition control structure that prints each non- zero value of the array until it either finds a value that is negative or it has printed 25 non-zero values from the array. Access the elements of the array using pointer arithmetic.
14) Given the code below, answer the following questions (If you find typos, assume that the code is SUPPOSED to work and just indicate what assumption you made for your answer.)
float *paycheck( int empID, char paytype, float base, int numhours, float &temppay )
{
if (paytype == S) /* S for salaried */
*temppay = base / 12;
else if (paytype == H) /* hourly */
{
*temppay = ((numhours <= 40)? numhours : 40) * base;
if (numhours > 40)
*temppay += (numhours - 40) * 1.5 * base;
}
else return NULL;
return temppay;
}
A) Describe in your own words how the function calculates the paycheck for an hourly worker. {6}
B) What value will be printed for paycheck if called as below? {5}
printf(%8.2f, *(paycheck( 1492, H, 12.50, 42)));
C) What value will be printed for paycheck if called as below? {5}
printf(%8.2f, *(paycheck( 2002, S, 54000, 65)));
D) What is returned for the call paycheck( 1863, T, 8.15, 20)? {3}
15) Write a C program to do the following: {7}
Declare an array large enough to hold one line of text. Ask the user to enter a sentence describing their current activity (before running this program J ) Use gets to read in a line of text from the keyboard and store it in the array. Use the string functions to concatenate the phrase in bed to the end of the users input and store the new string. Output the message Did you say then print the new concatenated string followed by a question mark.
Extra Credit questions - Worth two {2} points each unless stated otherwise.
XC1) Which of the following is a textbook page Dr. T has referred to repeatedly?.
A) Index
B) I-14
C) D-4
D) A-1
XC2) Which of the following would NOT be considered cheating in CSE at UTA?
A) Using existing source code as the basis of a program (when the instructor has not told you to do so).
B) Working with a classmate to figure out why there are errors in your programs
C) Handing your completed lab assignment code to a classmate who has not started yet.
D) Discussing the lab assignment and talking about how to write the specific statements to perform a function.
XC3) How many minutes does Dr. T suggest as a limit for trying to find any one error before asking someone for assistance?
A) 2
B) 20
C) 200
D) Never ask a classmate for assistance in debugging
XC4) Which of the following is NOT a good example of safe initialization?.
A) int iptr = NULL;
B) short sary = {0};
C) float fsum = 0.0;
D) char *cstr = cat;
XC5) What fruit does the C language remind you of and why?
{ANY answer will receive 2 (two) points}