CS 2620 Assignment #2 Summer 2004

How to handin.
Points : 30
Weight : 3%
Due : Monday May 17, 2004 @ 11:00 pmt
Note : Late assignments will be accepted only with the instructor's pre-approval.


Marks will be awarded for comments, style, readability, compiling and working correctly.
  1. [10] Structs
    Rewrite your point library from assignment 1 question 3 so that the point is implemented using a struct. Rewrite the test program so that is uses the new library.
  2. [10] Pointers
    Explain how each of the following statements affects the heap and/or stack in memory. For each statement You may assume that the statements follow each other in a program.
    1. int x = 5;
    2. int* xPtr = &x;
    3. float* iPtr = new float;
    4. float* jPtr = new float(10.0);
    5. float* kPtr = new float[10];
    6. int k[ ] = { 6, 3, 1, 5, 2 };
    7. int& y = x;
    8. x = *k+3;
    9. x = *(k+3);
    10. y = 16;

  3. [5] Constants and Pointers
    Given the following declarations and initializations : Which of the following assignments are legal? Explain why.
    1. pic = ⁣
    2. cpi = pic;
    3. pic = cpic;
    4. cpic = ⁣
    5. ic = *cpic;

  4. [5] Using the ctime library.
    1. Create a mytime library with the following functions:
      • printToday() - prints todays date as dd/mm/yyyy
      • printNow() - prints the current time as hh:mm:ss
      • delay(n) - waits n seconds before continuing with execution.
    2. Write a test program which prints the current date and time and then waits 10 seconds and then prints the current time.

Assignment List | Prev | Next | Computer Science 2620
Department of Mathematics & Computer Science
University of Lethbridge Home Page