Skip to document

CSC1016S 2018 TEST3 Memo

notes on unit 9 of core economics textbook for week 1 second semester
Course

Java programming (CSC1016S)

174 Documents
Students shared 174 documents in this course
Academic year: 2018/2019
Uploaded by:
Anonymous Student
This document has been uploaded by a student, just like you, who decided to remain anonymous.
University of Cape Town

Comments

Please sign in or register to post comments.

Related Studylists

Odetola Study List

Preview text

University of Cape Town ~~ Department of Computer Science

Computer Science 1016S ~~ 2018

Class Test 3

** Solutions **

Enter the following details AND shade in the corresponding blocks to the right with your Student Number.

Faculty (please tick one):

Science Engineering Commerce Humanities Other:

Student Number :

__________________________________

Name (optional) :

__________________________________

Marks : 35 Time : 40 minutes Instructions: a) Answer all questions. b) Write your answers in PEN in the spaces provided. c) Show all calculations where applicable.

A         0
B          1
C          2
D         3
E          4
F          5
G         6
H         7
I          8
J          9
K     
L      
M     
N     
O     
P      
Q     
R      
S      
T      
U     
V     
W     
X     
Y     
Z      

Question 1 2 3 4 5 6 7 8 Max 13 2 6 Marks 0                 1                 2                 3                 4                 5                 6                 7                 8                 9                 Marker

FOR
OFFICIAL
USE
ONLY:

Question 1 – Linked Data Structures [13]

(a) Linked Lists are known as dynamic data structures. Explain what is mean by this and compare it to an example of a data structure that would not be considered dynamic. [2] ________________________________________________________________________ ________________________________________________________________________ ________________________________________________________________________ ________________________________________________________________________ ________________________________________________________________________ ________________________________________________________________________ ________________________________________________________________________ ________________________________________________________________________

Linked lists are considered dynamic because the can grow and shrink, allocating and deallocating memory as needed while the program is running [1] compared to an array where the amount of memory is fixed and can only change by creating a new larger/smaller instance [1].

The following questions refer to Appendix A.

For all questions, you may not modify the Node class or the Linked List class and you may not change the signature of the methods. You may only add code to the function bodies in question.

(b) The clear() function in Appendix A, when called has the effect of removing all nodes from the linked list.

i. Write the code that would complete this method so that it will function correctly. [1]







void clear(){ head = null ; [1] }

ii. Explain how the clear() method works. [1]



{

Node<T> tempHead = null ; [1] Node<T> position = head ; [1] while (position != null ) [1] { tempHead = new Node<>(position. data , tempHead); [1] position = position. link ; [1] } head = tempHead; [1] }

*There could be other valid solutions to this question, but it needs to have some sort of loop and a position variable which together makes an iterator. They cannot use any built in Java methods. They might use a temporary value to store data, and in doing so, swap the data etc.

(d) Refer to the main method in Appendix A and draw a visual representation of the linked list as it looks at the execution point labelled //3 in the code. [1]

[1 mark for having the correct order 1,2,3] (e) The main method in Appendix A contains an error in it's body and the program won't compile. Identify what the error is and explain how it can be resolved. [2]






The type argument cannot be of primitive type int [1] use wrapper class Integer [1]

1 2 3

Question 2 – Stacks and Queues [2]

  1. Stack stack = new Stack(); 2**. while** (!queue())
  2. stack(queue()); 4**. while** (!stack())
  3. queue(stack());

Explanation of queue methods used in the code above. public void enqueue(T data); //Adds data to the back of the queue public T dequeue(); //Returns the item in the front of the queue and removes it from the queue

(a) Given some queue pre-populated with data, explain what the code in lines 1-5 above does. [2]






Reverses the order of the items in the queue [2]

(c) Refer to the code in Appendix B and draw a diagram to show the GUI that will be displayed when this program runs. [3]

Frame with correct title etc. [0] One button with text Button1 on it [0] Label with text “Label” [0] JscrollPane with “Text Area” inside it [0] and only the vertical scrollbar is visible [0] Layout should have 2 rows with 2 columns and blank cell in bottom right corner. Should look similar to the image below [0]

_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

Take traditional moral norm and principles, then apply it to a new situation [1]. examples, e.: comparing email with sending postcards, ownership laws of physical objects to software objects, lending of books to lending of apps [1]

(e) Consider the following scenario. Assume it is true and this is all the information there is to base the judgement on. Khadisha works at Groote Schuur hospital as a system administrator for the hospital's intranet. In an idle moment at her desk, she clicks around in the shared drives of the network and finds all the electronic health records of the hospital's patients, unencrypted. As she's signed up for a course in data mining, she runs her newly developed algorithm over the files and detects there are 4 doctors whose patients die much more often than the average deaths/doctor. She raises this with her boss. Eventually, the doctors are found incompetent but not culpable of murder. She receives a bonus of R15000 from her boss. The 4 doctors are fired.

Which one of the following statements is correct, taking into account the moral theory indicated? [4]

A. Ubuntu: individual privacy is the highest good, so Khadisha was morally wrong to use the electronic health records for data analysis, because it is in breach of personal privacy B. Deontology: the violation of the patients' privacy due Khadisha's data mining is acceptable, because it is good for all current and future patients that incompetent doctors are removed from their position. C. Ethical egoism: to Khadisha, the violation of the patients' privacy due to the data mining is acceptable, because she got the bonus, which is beneficial to her. D. Divine command theory: God's command is “thou shalt not kill” and Khadisha prevented more killings.


C (not D, as the killing is not applicable, for the doctors were not found guilty of murder. Not B, the 'justification' is that of utilitarianism, not deontology. Not A, for with ubuntu there's the lack of privacy (as currently analysed)

Appendix A

public class CustomLinkedList<T> { private class Node<T> { T data ; Node<T> link ; public Node(T data, Node<T> link) { this. data = data; this. link = link; } }

Node<T> head ;

void addToStart(T data) { head = new Node<>(data, head ); }

void clear() { //1 - To be implemented }

void reverse() { //2 - To be implemented }

public static void main(String[] args) { CustomLinkedList< int > list = new CustomLinkedList<>(); list( 1 ); list( 2 ); list( 3 );

list();

//3 - Draw the linked list as it looks at this point } }

Was this document helpful?

CSC1016S 2018 TEST3 Memo

Course: Java programming (CSC1016S)

174 Documents
Students shared 174 documents in this course
Was this document helpful?
University of Cape Town ~~ Department of Computer Science
Computer Science 1016S ~~ 2018
Class Test 3
** Solutions **
Enter the following details AND shade in the corresponding
blocks to the right with your Student Number.
Faculty (please tick one):
Science Engineering Commerce Humanities Other:
Student Number :
__________________________________
Name (optional) :
__________________________________
Marks : 35
Time : 40 minutes
Instructions:
a) Answer all questions.
b) Write your answers in PEN in the
spaces provided.
c) Show all calculations where
applicable.
A0
B1
C2
D3
E4
F5
G6
H7
I8
J9
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
Question 12345678
Max 13 2 6
Marks 0
1
2
3
4
5
6
7
8
9
Marker
FOR
OFFICIAL
USE
ONLY: