Spring 2002 Comprehensive Final
CSE1320 Sections 003 (2:30) and 501 (5:30)
Tuesday, May 7, 2002 Dr. Carter Tiernan
Name: Section:
Student ID:
Instructions:
1. Fill in your name, student ID, and section above.
2. This is a closed book, closed notes 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 15 points total.
4. If you feel stuck on a question, go on to the next questions and come back later to the challenging one. Try to go all the way through the test before spending a lot of time on a single queston.
5. Read the entire question before answering. Every part of the question is important.
6. Show any work or partial work on a question so that you may be able to receive partial credit. This includes drawings or tables of partial results or outlines of code fragments in English, etc.
7. NO CHEATING!
Do NOT begin this test until Dr. Tiernan tells you to.
Multiple choice questions are worth three {3} points each. Please circle the letter indicating your choice for the answer.
1. Which of the following is a valid macro for returning the integer distance (must be greater than or equal to zero) between any two input values?
A) #define DIST(x,y) ((int) abs(x) - (y))
B) #if define DIST(x,y,type) ((type) abs(x) - (y))
C) #define DIST(x,y) ((int) abs((x) - (y)))
D) #define DIST(x,y,type) ((type) abs((x) - (y)))
2. What does the following C++ code fragment do?
char *q[10];
for (int i = 0; i <= 9 ; i++) {
cin >> (q[i] = new char[80]); /*A*/
}
A) Reads in ten pointers to characters in an array
B) Reads in 10 characters into one array
C) Reads in ten strings to be addressed by 1 array of pointers
D) Reads in strings of length 10 into 1 array
3. How would the space allocation done in line /*A*/ in the previous question be done in C assuming the variable declarations are the same?
The variable q[i] would get assigned:
A) new char[80];
B) (char *) malloc (sizeof(80) * char);
C) (char *) calloc (sizeof(char));
D) (char *) malloc (80 * sizeof(char));
4. What does the C++ compiler do when a function is declared inline?
A) nothing
B) treats the function exactly like a preprocessor macro
C) treats the function similar to a macro but not until the function is executed
D) may treat the function similar to a macro but not until the function is executed
5. Which of the following is a function prototype for a function funproto which has no return value and one parameter which is an array of pointers returning float?
A) void function(float (*array)[100]);
B) void funproto(float *array[100]);
C) void funproto(float (*array)[100]);
D) funproto(float *array[100]);
6. Name and describe three phases of the software engineering process including the testing methods that are used for that phase. {12}
A.
B.
C.
7. List three C library functions (other than sqrt), the type of error information they return, and at least one error that can be indicated by the error information. {9}
Library function |
Error info type |
Example of an error that can be indicated |
sqrt |
errno |
errno = EDOM means a domain error (a negative input) |
|
|
|
|
|
|
|
|
|
8. In a C program that is contains in multiple files, describe where the following variable(s) must be declared and any storage class identifier it must have in order to have the scope as described in the questions below. {6}
A. A variable aleph which is available to all functions in the file misc.c but not to the other files in the program, must be declared:
B. A variable demo which is available only to the function sampledata, must be declared:
9. Name the other two categories of control structures in the C programming language, then, for the specific control structures listed, name which category they are in. (HINT: The categories of control structures apply to all sequential languages.) {9}
Control structure categories:
, , Sequential
If Assignment statement
For Do - while
Switch If - else
While Recursion
10. Give three different declarations for a variable test_str that will all create the variable and initialize it to the value “Hello!” (You do not have to use three different types.) {9}
A.
B.
C.
11. Use the C library function pow to define a function cube that takes one integer input and returns an integer value that is the input to the third power. {10}
12. Using the declarations below: (Assume this code is part of a larger valid (compilable) C program.)
FILE *invinput; //This file contains item names (one word each), the inventory number of
//each item, and the current quantity of each item with one item (name,
// inventory number, and quantity) per line
struct invnode {
char *item;
int itemnum;
int quantity;
struct invnode *next;
} *head, *curr, *new, *temp;
char itemname[40];
A. Write a fragment of C code to read five lines of data from the file using fscanf and create a sorted linked list with the smallest quantity of item at the head of the list. Do not declare any additional variables (except counters if needed.) Assume that invinput has been opened successfully (i.e. do not write the code to open the file.) {11}
B. Rewrite the declarations above (excluding the FILE declaration) to use a multi-dimensional array to hold the inventory data instead of a linked list. Write comments to explain any assumptions you make. {6}
13. A selection sort searches an array looking for the smallest element in the array. Then the smallest element is swapped with the first element of the array. The process is repeated for the subarray beginning with the second element of the array. Each pass of the array results in one element being placed in its proper location. When the subarray being processed contains one element, the array is sorted. Using the declarations below, write a recursive function selectionSort to perform this algorithm on an array of char. {13}
// function prototype for selectionSort
int selectionSort(char (*sortarray)[25]); //will pass address to sort the actual array
// in the main routine
char sorting[25];
… // assume some valid C code here
selectionSort(sorting); //a call to the function
sorting
b |
|
l |
|
n |
|
e |
|
r |
|
t |
|
s |
|
c |
|
o |
|
z |
|
s |
|
w |
|
d |
|
q |
|
a |
|
v |
|
x |
|
b |
|
u |
|
i |
|
p |
|
k |
|
j |
|
m |
|
h |
|
Extra Credit questions
XC1. Using more than one level of pointers is called: {2}
A) multi-dimensional
B) double indirection
C) scope resolution
D) unnecessarily complicated
XC2. Define an enumerated type that contains six constants of your choice and declare one variable called swenum of your enumerated type. {3}
XC3. Define, in your own words, one of the following C++ concepts: Data abstraction, Polymorphism, or Inheritance. {3}
XC4. What is on Dr Tiernan’s favorite page in the textbook? {3}
XC5. In four sentences or less, what would you say to a job interviewer who asked you, "What do you know about software engineering and good program design?" {4}