Professional Documents
Culture Documents
Ece 190 Final Exam Hochiminh University of Technology: Friday 17 July 2009
Ece 190 Final Exam Hochiminh University of Technology: Friday 17 July 2009
Name:
Student ID # :
Problem 1
20 points
_______________________________
Problem 2
20 points
_______________________________
Problem 3
20 points
_______________________________
Problem 4
20 points
_______________________________
Problem 5
20 points
_______________________________
Total
100 points
_______________________________
Page 2
Name: ____________________________________________
Part B (4 points): The following code has one error. Identify the error, state whether or
not it will be caught by the compiler, and indicate how to fix the error.
void increment_value (int value)
{
value++;
}
Part C (8 points): The following code has two errors. Identify both errors, state whether
or not each will be caught by the compiler, and indicate how to fix each error.
int sum_of_squares (int N)
{
/* return sum of squares from 1 to N */
int sum = 0
int i;
for (i = N; i-- > 0; ) {
sum += i * i;
}
return sum;
}
Page 3
Name: ____________________________________________
Problem 1, continued:
Part D (4 points): A given call to a C function named mystery generated the stack
frame shown and memory below. Based on the information shown in the stack frame, fill
in the declaration for the function mystery.
x6178
x6179
x617A
'H' (x0048)
'i' (x0069)
NUL (x0000)
xDEF0
xDEF1
xDEF2
xDEF3
xDEF4
xDEF5
xDEF6
xDEF7
i = 42
j = x6179
previous frame pointer
return address
_____________ mystery (
);
Page 4
Name: ____________________________________________
--*
-**
***
----*
---**
--*-*
-*--*
*****
}
}
-----*
----**
---*-*
--*--*
-*---*
******
Page 5
Name: ____________________________________________
NOTE: The second and fourth pointers point to empty strings (#characters = 0)
Fill in the blanks in the function on the next page to complete the tokenizer function.
You may or may not need all the lines provided to you. Assume that the original string
is not an empty string.
Page 6
Name: ____________________________________________
Problem 3, continued:
char** tokenize (char* str, char separator)
{
int
= 0;
Call it token_array. */
____________________________________________________
Page 7
Name: ____________________________________________
prev=NULL
next
id
prev
next
id
prev
next
id
prev
next=NULL
id
start
void remove (node_t* start, char rmID)
{
node_t* current;
node_t* temp;
while (1) {
temp = current->next;
if (rmID == current->id) {
if (NULL != current->prev) {
current->prev->next = temp;
}
if (NULL != temp) {
temp->prev = current->prev;
}
free (current);
return;
}
current = temp->next;
}
}
Part A (10 points): The function remove takes a node_t pointer start and a character
rmID. The parameter start points to the first node in a doubly-linked list. The function
is supposed to remove every node with id field equal to rmID from the list, but the
function given does not behave as intended. Changing at at most three lines, correct
the code above. To modify a line, cross the line out and write a new version to the right
(or write /* blank line */ if the line is simply unnecessary).
Page 8
Name: ____________________________________________
Problem 4, continued:
Part B (10 points): Implement the function list_length using the node structure from
the previous page. You must not modify the list!
/* Return the number of nodes in the list pointed to by start. */
int list_length (node_t* start)
{
Page 9
Name: ____________________________________________
Part B (12 points): Given the input file in the table below, and assuming that the program
is fixed to read/write the output file, write the contents of the output file.
Input File
Line Contents
4 m
0
6 r
1
5 e
2
0 S
3
2 m
4
1 u
5
-1 !
6
Output File
Line
0
1
2
Contents