CSCI251/851 Advanced Programming Exercise 2

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (4 votes)

Pointers
Instructions: ex2.cpp contains a partially completed implementation of a linked list of phone
records including a main() function for testing the linked list. For this exercise you are to complete
the code and test it using the main() provided. The output should look like the contents of output.txt.
After you complete the exercise you should demo your program in your week-4 lab class to receive
the 2 marks and submit via unix submit by 11.59pm Friday week-4 (see below and the “Resource”
section on moodle on how to submit your file via banshee). If you need more time, ask your tutor
for an extension. (Failure to comply with these instructions may result in zero marks for this
exercise.) Information on linked lists can be found in the week 3 & 4 lecture notes.
Step 1: Complete the ReadFile(), AddRecord() and DeleteList() functions according to the pseudo
code provided. ReadFile() reads records from the file and calls AddRecord(). AddRecord() adds a
record to the tail of the list (see week-3 lecture notes). DeleteList() deletes all the dynamic memory
(records) in the list. Test your code with the main() provided to see that the records are being read and
displayed on the screen via the DisplayAllRecs() function.
Step 2: Implement the FindRecord() function according to the pseudo code provided. FindRecord()
should ask the user for a phone number and display the found record on the screen. Test your code
again using the main provided.
Step 3: Implement the RemoveRecord() function according to the pseudo code provided.
RemoveRecord() should display the record at the head of the list on the screen and delete it. Again,
test your code using the main() provided.
Step 4: Replace the fixed size Name and Address arrays in the PhoneRecord struct with dynamic
memory that is the same size as the strings. To do this replace the Name and Address arrays in the
struct with char* pointers and modify the AddRecord() function so that it reads the name and address
into a temp array and then allocates the right amount of memory to the struct pointers and copies the
strings into that memory. Also, modify DeleteList() so that it also deletes the memory allocated to the
dynamic arrays. Test your program again and make sure the output looks like “output.txt”.
Submit:
You are required to BOTH demo your work in the lab to your lab supervisor and submit your files via UNIX submit
command by the due date. i.e.:
$ submit -u login -c CSC251 -a ex2 ex2.cpp
where ‘login’ is your UNIX login ID.
Note: Both CSCI251 and CSCI815 should submit to “-c CSCI251”. Check your submit receipt for errors. Marks will
be deducted for untidy work or for failing to comply with the submission/demo instructions. Requests for alternative
submission or demonstration arrangements will only be considered before the due date. An extension of time for
submission or demonstration may be granted in certain circumstances. Any request for an extension of the
submission deadline must be made to the Subject Coordinator or your Lab Supervisor before the deadline. Late
undemonstrated work without cause will receive zero marks.