Programming in C autumn 2008


Exercise 5

To the exam you may take one A4 paper, where you have make your own notes. You can use both sides of the paper.

Oct. 6 2008

  1. Make a implementation of an event queue. The event queue contains all the events (customer arrives in queue, customer leaves checkout etc.) in chronological order. The queue has a header node and it is an ordered (by time) singly linked list. Think what kind of operations you will need and implement them.
  2. Write a main program, which you can use to test the functions of the first assignment.
  3. Write a function minmax, which has variable-length argument list. The first parameter tells how many double values will follow. The function will reserve space for struct where is returned the maximum value and the minimum value among given doubles. The function will return a pointer to this struct.
  4. (8-8) Write a function maxi, which takes three parameters, two double values x and y and a double function f(double), and returns the largest of the two values: f(x) ja f(y). Then, write a function max1, that has four parameters. This function is similar to maxi except it returns the value (the larger of the two values: f(x) ja f(y) ) through the fourth parameter. Test your functions carefully.

  5. (8-10) Write a function
    void PrintGen(const void *block, size_t elemSize, size_t blockSize,
                  void (*printIt) (const void*));
    
    which prints all elements in the block using the "callback" function printIt. Use the "Traversing a Block of Objects" idiom. Test your program using a block of doubles, and a block of pointers to doubles.

  6. (8-12) Implement a generic module Sets, that represents an ordered collection (a set, duplicates are not allowed). There should be operations to add an element to the set, and remove it from the set. Add enumerations over the collection. Test your module with a collection of double objects, and a collection of integer objects.