Starting from:

$29

Exercise 3 – Virtual Initialization

Exercise 3 – Virtual Initialization
Due by the end of your Week-5 laboratory class. (2 marks)
This exercise is to be completed and demonstrated during your week 5 laboratory class. When you
complete the exercise show your work to your lab tutor to have your work marked. The marking is
based mainly on correct implementation and code readability. You should implement your code in
one file (e.g. ex3.cpp, ex3.c, ex3.java). Make sure your program has a header comment block
containing the name of the exercise, your name and your student login (e.g. jfk01).
For this exercise you are to implement a virtually initialized array and test it for correctness.
Your program should prompt for the name of an input file and then read and process the data
in the file.
You will use three integer arrays, data[], forward[] and backward[] each containing 100 elements.
Your test data will consist of a file containing two parts:
1. A sequence of pairs: what, where. You are to store the value what in location where of the
data array using virtual initialization. I.e. data[where] = what.
2. This sequence is terminated by the pair -1 -1
3. This is followed by a sequence of single integer values, probe. For each such value you are to
test whether data[probe] has been initialized and print one of the following two messages:
 Position probe has not been initialized.
 Position probe has been initialized to value data[probe].
4. This sequence is terminated by the value -1
A sample input file might contain:
42 7
93 9
11 4
-1 -1
7
8
9
-1
For which the output would be:
Position 7 has been initialized to value 42.
Position 8 has not been initialized.
Position 9 has been initialized to value 93.
As usual, do not use classes or STL.
When you are finished, test your program using the provided text file named “Ex3.txt” and show
your code and the output to your lab tutor to receive your mark. Also, submit your file via unix
(banshee) using the submit command below.
$ submit -u login -c CSCI203 –a ex3 filename
where ‘login' is your UNIX login ID and ‘filename’ is the name of your file.
If you are unable to attend your lab class and demonstrate your work on time due to circumstances
beyond your control (e.g. sickness), contact your lecturer to request an extension. 

More products