EEN511 Test, 8th April 2003

E-mail solutions to me (stephen@rabbit.eng.miami.edu) in HTML format. That way I can add comments in a way that stands out, and send back the response to you electronically, and you can even add pictures if you want. Do not use bright colours in your answers.

Include your NAME and STUDENT NUMBER at the beginning.

Question Weights: Q1: 40%, Q2: 20%, Q3: 40%

1
With reference to a working implementation of Merge-Sort, show clearly and unarguably that its running time really is O(n×log2n) and that its additional memory requirement is O(n).

Showing something "unarguably" does not require a formal mathematical proof. It requires a well-reasoned argument that would leave an intelligent person with no doubt of the truth of the assertion. You should not leave this intelligent person to realise or discover anything for him/her/itself, but you do not need to demonstrate that 2+2 is 4.


2
Consider this partial class definition:
class thing
{ protected:
    char name[100];
    int age;
  public:
    ...
    int get_age(void) { return age; }
    char * get_name(void) { return name; }
    ... };
One of the two methods is perfectly safe and sensible. The other is not. Explain exactly what the problem is, and suggest at least one good solution.


3
Consider the program that follows. There is plenty wrong with it. Identify and Explain all the errors: tell me what I have to do, and why I have to do it, in order to make the program run and produce the obviously desired results.
#include 


class resource
{ protected:
    int value;
  public:
    resource(int v) { value=v; }
    virtual void print(void) { cout << "Resource[value=" << value << "]\n"; } };


class stockitem: public resource
{ protected:
    string description, number;
  public:
    stockitem(string d, string n, int v) { description=d; number=n; value=v; }
    void print(void) { cout << "StockItem[" << description << 
                               ", number=" << number << 
                               ", value=" << value << "]\n"; } };


class personnel: public resource
{ protected:
    string name;
  public:
    personnel(string n, int v) { name=n; value=v; }
    void print(void) { cout << "Personnel[name=" << name << 
                               ", value=" << value << "]\n"; } };


class manager: public resource
{ public:
    manager(string n) { name=n; value=250000; }
    void print(void) { cout << "Manager[name=" << name << 
                               ", value=" << value << "]\n"; } };


class worker: public resource
{ protected:
    int salary;
  public:
    worker(string n, int s) { name=n; value=3000; salary=s; }
    void print(void) { cout << "Worker[name=" << name << 
                               ", salary=" << salary << "]\n"; } };


resource Resources[10000];

void main(void)
{ Resources[0] = new manager("Arthur Weasel");
  Resources[1] = new worker("Joe Glob", 25000);
  Resources[2] = new worker("Brandeen Whelp", 26500);
  Resources[3] = new stockitem("Stapler", "A03-3652-2B", 15);
  Resources[4] = new stockitem("Photocopier", "B12-3478-7A", 12000);
  Resources[5] = new stockitem("Office Cat", "A22-4838-1C", 120);
  for (int i=0; i<=5; i+=1)
    Resources[i].print(); }