CS 202 Fall 2019, Exam 1 sample exam


** Computer Exam **
There will be an "assignment" to checkout with handin with 5 programming problems
to complete.  The programming problems will be setup like homework problems where
you'll be able to use hwcheck to check your programs.  Depending on the difficulty
of the problems the score will be computed based on 4 or 5 correct problems being
100% credit.

Here are some example questions, one of each kind.  You can try these out in a
one hour slot to see how you are doing in terms of speed.

1. Create a C program that reads two square matrices and computes their product.  The
first line of input contains an integer n that is the dimension of the matrices.  The
next n*n numbers are the values of matrix A (in row-major order - first n numbers are the
first row, etc.), followed by n*n numbers being the values of matrix B.  Your program
should output the matrix product A*B.  Note that the r'th row and c'th column of the
product is the r'th row of A multiplied by the c'th column of B.

Sample input:
2
1 2
3 4
5 6
7 8

Sample output:
19 22
43 50


2. Write a C program that reads from stdin and prints every 10'th line - it should
print the first line, the eleventh, etc.


3. Complete the code for the following function.

typedef struct node {
  char * data;
  struct node *next; 
} node_t;

node_t *empty_string(node_t * head) {
  // Function should find the first node in the list that has
  // empty string for its data, and return the node previous
  // to that node.  If there are no nodes that are empty, or if
  // the first empty string node is the head, then return NULL
}


4. Complete the code for the following function.

typedef struct tree {
  char *word; 
  int num;    
  struct tree *left, *right;
} tree_t;

tree_t * first_max(tree_t *root) {
  // Return a pointer to the lexicographically first node that has
  // the highest num.  
}


5. Complete the code for the following function.

unsigned int pal(unsigned short x) {
  // return the unsigned int that consists of the least significant
  // bits being x, and the most significant bits being x's bits reversed.
  // note that the bits of the result will be a palindrome.
}



** On Paper Exam **

1. C keywords - there will be a short description of each keyword, and
you will need to write which one it is.  For example,

1.1 C keyword for a loop with initialization, condition, and increment.

1.2 C keyword for a floating point data type (single precision).

1.3 C keyword for making an integer data type for only non-negative values.


2. C data types - you need to know how many bytes each data type is using
gcc on CS, the formula for max/min values for all integer data types, and
the powers of 2 up to 1024, and rules of exponents, and know that
2**10 is roughly 1000 to do estimates.

Which of the following would fit within a 16 bit signed integer:
40000, 64000, 128000, 1000000, 255, ...


3. C expressions - you need to be able to evaluate C expressions using
all of the C operators, and know which operators are left-right, which
are right-left, and which are higher precedence than the others.

Some obvious and some tricks.


4. Functions every citizen should know - you need to know the one sentence
description of each, what the parameters are, and what the return value is
(and means).


5. Data structures chart - you need to know the basic description of how
insert, lookup, delete works for each of the basic data structures (sorted
and unsorted arrow, linked list, stack, queue, hash table, binary search
tree [balanced and not-necessarily-balanced]), the worst-case and
best-case running time, and examples of what kinds of data causes best and
worst-case running time.


6. Memory - be able to identify where in memory variables/C-expressions
would be (heap, stack, code, data).  Be able to give examples of C
code that uses each of the four types of memory.