ECE 199 Final Exam Fall 2003, Exams of Electrical and Electronics Engineering

The final exam for the ece 199 course at the university of waterloo, fall 2003. The exam covers various topics in computer engineering, including programming, logic structures, recursion, i/o, and c language. It consists of five problems, each worth 20 points, and includes instructions for the exam takers.

Typology: Exams

Pre 2010

Uploaded on 03/16/2009

koofers-user-5ob-1
koofers-user-5ob-1 🇺🇸

10 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 199 Final Exam Fall 2003
Tuesday, December 16th, 2003
Name:
Be sure your exam booklet has 11 pages.
Write your name at the top of each page.
This is a closed book exam.
You are allowed three 8.5 x 11 sheets of notes.
Absolutely no interaction between students is allowed.
Show all of your work.
Challenge questions are marked with ***
Don’t panic, and good luck!
Problem 1 20 points
Problem 2 20 points
Problem 3 20 points
Problem 4 20 points
Problem 5 20 points
Total 100 points
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download ECE 199 Final Exam Fall 2003 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

ECE 199 Final Exam Fall 2003

Tuesday, December 16th^ , 2003

Name:

  • Be sure your exam booklet has 11 pages.

• Write your name at the top of each page.

• This is a closed book exam.

• You are allowed three 8.5 x 11 sheets of notes.

• Absolutely no interaction between students is allowed.

• Show all of your work.

• Challenge questions are marked with ***

• Don’t panic, and good luck!

Problem 1 20 points

Problem 2 20 points

Problem 3 20 points

Problem 4 20 points

Problem 5 20 points

Total 100 points

Problem 1 (20 points): Short Answer

Part A (8 points): Briefly describe the error that this program makes. The comment reflects what the program is supposed to do. Note that there are no syntax errors.

/* Copy array a to array b. Each has 25 elements. */ i = 0; while( i++ < 25 ) b[ i ] = a[ i ];

Part B (12 points): Using the basic logic structures discussed in lecture, design a circuit to convert an 8-bit 2's complement number to its absolute value (also an 8-bit 2’s complement number).

Problem 3 (20 Points): Recursion and I/O

Part A (12 points): Write a function to evaluate a parse tree that contains only integer operands and the multiplication and addition operators. Your function must return the result of the expression. For example, the following parse tree should produce the result: (6 + 2) * 3 = 24

typedef struct node Node; struct node { Node *left, right; int type; / 0 = Operator, 1 = Operand / int value; / If type is 0, then 0 = Addition, 1 = Multiplication If type is 1, then value is just the operand's value */ };

int Evaluate( Node* root ) {

}

Problem 3, continued:

Part B (8 points): The function below reads an expression from a file and builds a tree structure for the expression. The function takes a file and a pointer to a place in which the root node of the resulting expression can be stored. The function returns 0 on success and -1 on failure. For simplicity, the function does not properly free dynamically allocated memory; ignore this problem. Read the function, then write the contents of a file representing the expression: ( 2 * (4 * 3) ) + 18.

typedef struct node Node; struct node { Node *left, right; int type; / 0 = Operator, 1 = Operand / int value; / If type is 0, then 0 = Addition, 1 = Multiplication If type is 1, then value is just the operand's value */ };

int parse_expression_file( FILE *file_in, Node **n ) { char buf[200]; int num;

(n) = (Node ) calloc( 1, sizeof( Node ) ); if( n == NULL || fgets( buf, 200, file_in ) == NULL ) { return -1; } if( sscanf( buf, "%d", &num ) == 1 ) { (n)->type = 1; (n)->value = num; return 0; } (n)->type = 0; if( buf[0] == '+' ) { (n)->value = 0; } else if( buf[0] == '' ) { (n)->value = 1; } else { return -1; } if( parse_expression_file( file_in, &(n)->left ) == -1 || parse_expression_file( file_in, &(*n)->right ) == -1 ) { return -1; } return 0; }

Problem 4, continued:

*****Part B** (10 points):

typedef struct node Node; struct node { int value; Node *next; };

void FunctionB( Node *head, Node **headA ) { Node *temp = head; Node **tempA = headA; int num;

tempA = NULL; if( head != NULL ) { num = temp->value; tempA = (Node ) malloc( sizeof( Node ) ); (tempA)->value = num; (tempA)->next = NULL; tempA = &((tempA)->next);

while ( temp != NULL ) { if ( temp->value > num ) { num = temp->value; tempA = (Node ) malloc( sizeof( Node ) ); (tempA)->value = num; (tempA)->next = NULL; tempA = &((*tempA)->next); } temp = temp->next; } } }

Problem 5 (20 Points): Writing C

Part A (12 points): Write a function that takes two lists of numbers, each of which is sorted in increasing order, and determines if the first list is a subset of the second list, returning 1 if this relationship holds, and 0 otherwise. (Recall that a list is a subset of a second list if the second list contains all elements in the first list.) You may use either a recursive or iterative style, but your function must take advantage of the fact that the lists are sorted for full credit.

typedef struct node Node; struct node { int value; Node *next; };

int sorted_list_is_subset( Node *sub, Node *super ) {

}

Scratch Paper for Calculations