8 Subroutines, File Handling and Design Flashcards
What is a structure diagram?
- A modelling tool used to show the hierarchy of a system/program
- A graphical representation of top down design to show how a system is broken into subsystems
- They are used at the design stage of the software development lifecycle
What are library routines?
A collection of standard programs/subroutines available for immediate use
What is a subroutine?
- A self-contained piece of code that that is given a name and can called from within a program
- 2 types of subroutines
- A function - always returns a value
- A procedure - may or may not return a value
What is a procedure?
A subroutine that does not have to return a value
What is a function?
A subroutine that always returns a value
Describe the use of a subroutine in a program
- It is a block of code within a program that can be called when needed
- It breaks up the program to make it easier to read and understand
- It can be reused by another program
What is a library routine?
- A standard subroutine that is available for immediate use
- It can be called from many programs
- It is used often and makes programs easier/faster to write as the code is already written
- They make testing easier as they have already been used and debugged
What is top down design?
Breaks down a system into successively smaller pieces/sub systems
What are the benefits of top down design?
- allows several programmers to work at the same time on the software
- Development time is faster
- can test each subsystem independently
- Easier to debug
What are the advantages of using library routines?
- Makes writing programs faster as we are reusing code
- Makes testing easier as the code has already been tested.
The library routine DIV is used for integer division. What would the code below output?
i ← DIV(11, 4)
OUTPUT i
i ← DIV(3, 2)
OUTPUT i
i ← DIV(2, 4)
OUTPUT i
2
1
0
The library routine MOD is used to find the remainder. What would the code below output?
i ← MOD(11, 4)
OUTPUT i
i ← MOD(3, 2)
OUTPUT i
i ← MOD(2, 4)
OUTPUT i
3
1
2
The library routine ROUND is used to round a decimal number to a certain number of places. What would the code below output?
r ← ROUND(2.6789, 3)
OUTPUT r
r ← ROUND(3.142, 0)
OUTPUT r
r ← ROUND(1.111111, 4)
OUTPUT r
r ← ROUND(1.227, 2)
OUTPUT r
2.679
3
1.1111
1.23
The library routine RANDOM returns a random number between 0 and 1 inclusive. What is the smallest and largest random number that could be generated by the pseudocode statement below.
value ← ROUND(RANDOM() * 100, 0)
Smallest = 0
Largest = 100
The string handling library routine LENGTH returns the number of characters in a string. What would the call below return?
length = LENGTH(“Happy Days”)
10