Several of the questions below will refer to this dataclass:
Consider the code below. Write a line of code code to add 'Leo' to the end of the list of students in the first course in c.
Consider the code below (same as above). How many memory locations would be needed store the information in 'c'?
5
We want to consider all the lists and Courses that are created: 1 for the list of courses, 1 for each of the courses, and 1 for each of the courses' lists.
Consider the code below:
Fill in the blanks in the program directory and memory:
Program directory:
name | value |
---|---|
course1 | loc 1002 |
course2 | BLANK1 |
course3 | BLANK2 |
Memory:
name | data |
---|---|
loc 1001 | BLANK3 |
loc 1002 | Course('csci0111', loc 1001) |
loc 1003 | ['Giselle', 'Colton'] |
loc 1004 | Course('csci0112', BLANK4) |
BLANK1: loc 1004
BLANK2: loc 1002
BLANK3: ['Monica', 'Julia']
BLANK4: loc 1003
Is there any program that will produce this program directory and memory?
Program directory:
name | value |
---|---|
course1 | loc 1002 |
course2 | loc 1002 |
Memory:
name | data |
---|---|
loc 1001 | ['Monica', 'Julia'] |
loc 1002 | Course('csci0111', loc 1003) |
loc 1003 | ['Giselle', 'Colton'] |
loc 1004 | course1 |
( ) Yes
( ) No, two values cannot point at the same location in memory
( ) No, data in memory cannot refer to names
( ) No, loc 1002 cannot refer to loc 1003
No, data in memory cannot refer to names
Two values can point at the same location in memoryโfor instance, if we run course1 = course2
. Data can refer to later memory locationsโfor instance, if we run course1.students = ['Giselle', 'Colton']
.
Imagine running the following program:
Which of these would be the resulting program directory and memory?
Program directory:
name | value |
---|---|
course1 | loc 1002 |
course2 | loc 1002 |
Memory:
name | data |
---|---|
loc 1001 | ['Julia', 'Colton'] |
loc 1002 | Course('csci0111', loc 1001) |
Program directory:
name | value |
---|---|
course1 | loc 1002 |
course2 | loc 1003 |
Memory:
name | data |
---|---|
loc 1001 | ['Julia', 'Colton'] |
loc 1002 | Course('csci0111', loc 1001) |
loc 1003 | Course('csci0111', loc 1001) |
Program directory:
name | value |
---|---|
course1 | loc 1002 |
course2 | loc 1003 |
Memory:
name | data |
---|---|
loc 1001 | ['Julia', 'Colton'] |
loc 1002 | Course('csci0111', loc 1001) |
loc 1003 | loc 1002 |
Program directory:
name | value |
---|---|
course1 | loc 1002 |
course2 | loc 1004 |
Memory:
name | data |
---|---|
loc 1001 | ['Julia', 'Colton'] |
loc 1002 | Course('csci0111', loc 1001) |
loc 1003 | ['Julia', 'Colton'] |
loc 1004 | Course('csci0111', loc 1001) |
( ) OPTION 1
( ) OPTION 2
( ) OPTION 3
( ) OPTION 4
OPTION 2