Click into the document and scroll to see the other pages.
a) Define the following terms identifying at least two key features.
Use an example where appropriate:
i) Mutability
ii) Recursion
iii) Algorithm
a) Define terms w/ 2 key features
i) Mutability: it’s state can be altered or modified after creation, without creating a new object. Lists and dicts are mutable, but bools, ints, strings and floats are not. When a mutable object is passed to a function, it is passed by reference, meaning the original object itself can be mutated by that function. When an immutable object is passed to a function, it is passed by value, so a copy is sent to the function.
ii) Recursion: A function that calls itself is a recursive function. It should have a base case where the recursive calls stop. These functions can be easy to write, but when used carelessly can consume a lot of RAM, or may take too long to complete and run out of RAM.
iii) Algorithm: step-by step instructions to perform a task/achieve goal. Key characteristics include: definite input; definite output based on instructions; precise and unambiguous; finiteness- will complete after n steps; effective- solves the problem in a reasonable time; feasible- practical and achievable
b) Any Five milestones in computer h/w since 1940 such as
Vacuum tube- electronic computers
Transistor- faster small computers
Integrated circuits- leading to microcontrollers & microprocessors
Magnetic memory, leading to greater computer storage
Networking- TCP/IP, leading to the web
Modular general purpose computing (IBM System 360)
c) Interpreter vs Compiler- any five differences:
d) Any 3 distinct characteristics of each generation
1GL
Machine code is binary
Often expressed in hex format for readability
Tied specifically to the instruction set used by the CPU (family)
DIfferent CPUs often have a different language, just like humans :)
Processors came with books of instructions that programmers would go through, find the appropriate instruction, and then punch these binary sequences onto cards to be read by the computer.
For an X86 processor, to store a constant to a register;
10110 000 0110 0001
10110 > instruction binary code
000 > identifies the AL register
0110 0001 > the constant, in hex > B0 61
2GL
Assembly
More “English” like
Abbreviations, like POP, JMP, JZ, ADD, SUB, MUL, DIV etc.
Easier to develop, understand and modify
Less prone to errors
Machine dependant- different processors have different words and syntax
3GL
High Level languages
The third generation programming languages were designed to overcome the various limitations of the first and second generation programming languages.
The languages of the third and later generation are considered as a high-level language because they enable the programmer to concentrate only on the logic of the programs without considering the internal architecture of the computer system.
· It is easy to develop, learn and understand the program.
· As the program written in these languages are less prone to errors they are easy to maintain.
The program written in these languages can be developed in much less time compared to the first and second generation language
a) Describe the importance of top-down design and modularization and its importance when working on large-scale software. Define the terms and indicate at least four benefits to this approach. [10 marks]
Modularisation is the breaking apart of something into many different parts than can then be completed as "modules". These modules are then combined to build the "big thing". Top-down design isn’t a literal definition of the method. It merely describes the process of designing from a basic sketch—that sits at the top of the model tree—and then adding more complexity. Your sketch can include whatever base components are necessary to communicate design intent and provide a platform for additional geometry.
-Any 4 of the following or other relevant points.
• Reduces development time
• Improves reliability
• Increases standardisation of SW dev process
• Allows code portability
• Facilitates troubleshooting (debug/test)
• Simplifies modifications
• Enables teams to work on projects with millions of lines of code- manageable
• Enables enhancements and extensions
b) Describe with an example three attributes that characterise a variable. [3 marks]
Typically, the 3 characteristics are
• Type: class such as str, int, float
• Name: user, age- something that refers to the object itself
• Value: None, 3.99, -4, “Mary”
In python, a global variable is any variable declared outside of a function or class
c) These functions should include a complete docstring and all its elements.
Exception handling is not required for this question, but the function should handle all valid inputs.
i) Write a function cone_volume to calculate surface area, where the function takes the required arguments to make the necessary calculation, i.e. there are NO print or input statements in this function! Use the pi value from the math module as part of this calculation. Docstring (3 marks) computation (3 marks) and return value (1 mark).
[7 marks total]
ii) Write a helper function cone_helper (with docstring) that will use the function created in part i). Docstring (1 mark), user input (1 mark), converts type (1 mark), calls calculator function (1 mark), output string (1 mark). Prompt the user as shown here with sample data included:
Enter the radius: 2.2
Enter the height: 10
A cone with radius 2.2 and height 10.0 has a volume of 50.684366147791533
a) Describe at least two of the main characteristics of the following types of test:
i) White box testing
ii) Unit testing
iii) TDD [6 marks total, 2 marks each term]
i. White box testing is a form of application testing that provides the tester with complete knowledge of the application being tested, including access to source code and design documents.
This in-depth visibility makes it possible for white box testing to identify issues that are invisible to gray and black box testing. All inputs and outputs can be monitored.
ii. Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually scrutinized for proper operation.
We can think about functions as being one of the smallest components of a software system.
iii. Test-driven development (TDD) is a software development practice that emphasizes writing tests before writing the actual code.
It follows a cyclical process of writing a failing test, writing the minimum code to make the test pass, and then refactoring the code.
b) Write a function task_log that does the following:
Create an empty list (1)
Prompt the user to enter a task (str) (1)
Add the task to the list (1)
Use a loop to keep adding items to the list until the user enters an empty string. (2)
Return the list. (1)
[6 marks]
c) Write a function odd_even_check that takes a list of strings.
It processes each string and prints an indicator as to the number being odd or even, but it ignores spaces (include spaces for 2 marks less).
Finally, it returns a count of the total number of characters not including spaces.
[8 marks broken down as follows]
function definition correct: 1
initialise variables needed: 1
loop implemented correctly: 2
conditionally increment counter: 2
print indicators: 1
return count: 1
d) Write a function make_tri that takes a single int as an argument and produces a triangle using the ‘#’ character. [5 marks]
Sample runs are shown here:
>>> make_tri(3)
#
##
###
>>> make_tri(5)
#
##
###
####
#####
Partial marks will be awarded for a triangle that slopes from the other side.
Marks are awarded as follows:
function definition correct: 1
loop implemented correctly: 2
correct outputs: 2
a) Draw a flowchart for a ‘Lotto Quick Pick’ calculator:
Ask user for the highest number in the lottery (highest ball value)
Ask user for how many numbers they pick
Generate all of the numbers for the lottery draw from 1 to n
pick a random number- if not in the numbers picked, add to the list
stop when the desired number of numbers are picked
Show the numbers picked to the user
[8 marks broken down as follows]
terminators: 1
inputs/outputs: 1.5
type conversion: 1
process: 1
conditionals: 3
lines/annotations: 0.5
There are at least two solutions, both for the plannig (flowchart) and implementation if it were needed.
Start and Stop- 1 mark
Correct logic – 5 marks
Correct shapes – 2 marks
b) Create a dictionary called users for users of an IT system, where the key is a username (string), and the value is a list. These represent a password (string), age(int) and admin-permissions(bool). Sample data is shown here.
username: bkelly
attributes: dog@fish, 32, False
username: pbaelish
attributes: smallfinger, 46, True
i) Write code to create the dictionary and set the initial key-value pairs as shown with the correct data types. [5 marks]
ii) Write a function show_user_type that takes a dict such as users and prints out only the username and admin-permissions as shown, where the user is an admin if the last value in the list is True, otherwise they are just ‘user’: [4 marks]
Sample run:
>>> show_user_type(users)
bkelly: user
pbaelish: admin
ekenny: user
gbyrne: user
Marking scheme:
loop: 1
conditional use: 2
print info as shown: 1
iii) Write a function add_user that takes a dict, two strings, an int and a bool. The dict is one such as users, the first str is the username which will be the key, the second is the password, the int is the age of the user and the bool is their admin status, which are stored in a list.
You do not have to check if the user is already present or not! [3 marks]
Sample run:
>>> add_user(users, "mogreen", "d@nG3r", 27, True)
'mogreen': [ "d@nG3r", 27, True]
Marking scheme:
function definition: 1
add in correct format: 2
iv) Write a function del_user that takes a dict and a single arg which is the key of a user. If the user does not exist, print a message to say “User xxxx not found”, otherwise, remove the user and print a message “User xxxx deleted!” An example run is shown for reference. [5 marks]
Sample run:
>>> del_user(users, "mogreen")
User mogreen deleted!
>>> del_user(users, "paddy")
User paddy not found!
Marking scheme:
function definition: 1
loop implemented correctly: 1
check if present and delete: 1
handle not found correctly: 1
print statements correct: 1