8 Subroutines, File Handling and Design Flashcards

1
Q

What is a structure diagram?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are library routines?

A

A collection of standard programs/subroutines available for immediate use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a subroutine?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a procedure?

A

A subroutine that does not have to return a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a function?

A

A subroutine that always returns a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the use of a subroutine in a program

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a library routine?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is top down design?

A

Breaks down a system into successively smaller pieces/sub systems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the benefits of top down design?

A
  • allows several programmers to work at the same time on the software
  • Development time is faster
  • can test each subsystem independently
  • Easier to debug
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the advantages of using library routines?

A
  • Makes writing programs faster as we are reusing code
  • Makes testing easier as the code has already been tested.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

2

1

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

3

1

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

2.679
3
1.1111
1.23

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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)

A

Smallest = 0

Largest = 100

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The string handling library routine LENGTH returns the number of characters in a string. What would the call below return?

length = LENGTH(“Happy Days”)

A

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The string handling library routine LCASE returns the string with all characters in lower case.. What would the call below return?

word = LCASE(“LovEly”)

A

lovely

17
Q

The string handling library routine UCASE returns the string with all characters in upper case.. What would the call below return?

word = UCASE(“LovEly”)

A

LOVELY

18
Q

2The string handling library routine SUBSTRING returns a substring of a specified length starting at the position specified.

What would the calls below return?

s1 = SUBSTRING(“Happy Days”, 1, 5)

s2 = SUBSTRING(“Happy Days”, 2, 2)

A

s1 = “Happy”

s2 = “ap”

19
Q

What are the advantage of subroutines?

A
  • Can sometimes be reused in other programs
  • Breaks down code and makes it easier to read and debug
  • Can be called many times, so code is not repeated
20
Q

What are parameters in a subroutine?

A

The variables in a procedure or function declaration that store the values passed from the main program to a procedure or function

21
Q

Write a procedure that accepts an integer as a parameter and a string. It should then output that string that number of times

A
PROCEDURE OutputSentence(numTimes: INTEGER, sentence: STRING)
    FOR int i ← 1 TO numTimes STEP 1
        OUTPUT sentence
    ENDFOR
ENDPROCEDURE
22
Q

Write a function that when given a radius (REAL) calculates and returns the area of a circle.

A
FUNCTION CalcCircleArea(radius: REAL) RETURNS REAL 
    REAL area \<- 0 
    area \<- 3.14159 \* radius \* radius 
    RETURN area 
ENDFUNCTION
23
Q

What are the 4 main stages of the Software Development Lifecycle

A

Analysis

Design

Coding

Testing

24
Q

Describe analysis in terms of the software development lifecycle

A
  • Identification of the problem and the requirements specification (what a program is required to do)
  • Involves abstraction and decomposition of the problem to identify exactly what is required.
25
Q

Describe design in terms of the software development lifecycle

A
  • Uses the requirements specification from the analysis stage to show to how the program should be developed.
  • This can be formally documented using structure charts, flowcharts and pseudocode.
26
Q

Describe coding in terms of the software development lifecycle

A
  • The program or set of programs are developed.
  • Each module of the program is written using a suitable programming language and then tested.
  • Iterative testing is conducted on modules and and code amended until the module performs as expected,
27
Q

Describe testing in terms of the software development lifecycle

A
  • Systematic checks are done on a program to make sure that it works under all conditions.
  • The completed program is run many times with different sets of test data.
28
Q

What is abstraction?

A

The key elements required for a solution to the problem are kept and any unnecessary details and information that are not required are discarded

29
Q

What is decomposition?

A

A complex problem is broken down into smaller parts, which can then be sub divided into even smaller parts that can be solved more easily

30
Q

What is top down design?

A
  • The breaking down of a computer system into a set of sub-systems.
  • Then breaking each sub-system down into a set of smaller sub-systems, until each sub-system just performs a single action
  • This hierarchy can then be represented using a structure diagram
31
Q

What are the 4 major components of a computer system?

A
  • inputs -the data used by the system that needs to be entered while the system is active.
  • processes - the tasks that need to be performed using the input data and any stored data
  • outputs - information that needs to be displayed or printed for the users of the system
  • storage - data that needs to be stored in files on an appropriate medium for use in the future
32
Q

When writing computer programs why do we store data in a file?

A
  • Any data stored in RAM will be lost when the computer is switched off
  • When data is saved to a file it is stored permanently
  • The data can then be accessed by the same program at a later date or accessed by another program
33
Q

Write some pseudocode that asks the user to enter their firstname and surname and then writes these to a text file called “UserDetails.txt” on separate line.

A
DECLARE surname : STRING
DECLARE firstName: STRING
DECLARE fileName : STRING 

filename <- "UserDetails.txt"

OUTPUT "Please enter first name" 
INPUT firstName 

OUTPUT "Please enter surname" 
INPUT surname 

OPEN fileName FOR WRITE
    WRITEFILE fileName, firstName
    WRITEFILE fileName, surname
CLOSEFILE (filename)  
34
Q

A text file contains a username on the first line and a password on the second line. Write some pseudocode that reads the username and password from a text file called “UserDetails.txt” and then displays them on the screen

A
DECLARE username : STRING
DECLARE password: STRING
DECLARE fileName : STRING 

filename <- "UserDetails.txt"

OPEN fileName FOR READ
    READFILE  fileName, userName
    READFILE fileName, password
CLOSEFILE (filename)  

OUTPUT username
OUTPUT password
35
Q

Write some pseudcode to read the first line of a text file called “info.txt”

A
DECLARE fileName : STRING
DECLARE line : STRING 

filename <- "info.txt"

OPEN filename FOR READ
    READFILE  fileName, line
CLOSEFILE (filename)
36
Q

Write an algorithm to write the numbers 1 to 1000 to a text file named Numbers.txt

A
DECLARE fileName : STRING 

fileName <- "Numbers.txt"

OPENFILE fileName FOR WRITE 
    FOR i <- 1 TO 1000 STEP 1
            WRITEFILE fileName, i
    NEXT i
CLOSEFILE fileName 
37
Q

Write an algorithm to read the first 100 student names from a text file named Names.txt. The data read in should be stored in an array of a suitable size

A
DECLARE studentNames : ARRAY[1:100] OF STRING
DECLARE fileName : STRING 

fileName <-  "Names.txt"

OPENFILE fileName FOR READ

    FOR i <- 1 TO 100 STEP 1
            READFILE fileName, studentNames[i]
    NEXT i

CLOSEFILE fileName