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.
- [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.
- [10] Pointers
Explain how each of the following statements affects the heap and/or stack in
memory. For each statement
- if memory is allocated, you should tell whether it is allocated on
the heap or the stack, what type of data may be stored there, and
the value stored if known.
- if memory is changed, you should indicate which memory is changed
and its new value.
You may assume that the statements follow each other in a program.
- int x = 5;
- int* xPtr = &x;
- float* iPtr = new float;
- float* jPtr = new float(10.0);
- float* kPtr = new float[10];
- int k[ ] = { 6, 3, 1, 5, 2 };
- int& y = x;
- x = *k+3;
- x = *(k+3);
- y = 16;
- [5] Constants and Pointers
Given the following declarations and initializations :
- int i = -1;
- const int ic = i;
- const int* pic = ⁣
- int* const cpi = &i;
- const int* const cpic = ⁣
Which of the following assignments are legal? Explain why.
- pic = ⁣
- cpi = pic;
- pic = cpic;
- cpic = ⁣
- ic = *cpic;
- [5] Using the ctime library.
- 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.
- 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