Free Web Site - Free Web Space and Site Hosting - Web Hosting - Internet Store and Ecommerce Solution Provider - High Speed Internet
Search the Web

December 1999
CP103: COMPUTER PROGRAMMING

SECTION B [60 Marks]

Click here to access other sections
Section A
Front Cover

SUGGESTED SOLUTIONS
Solutions and allocated marks are indicated in green.
Return to
Section B (Questions)

Answer any TWO questions in this section

 

1. a) A program is to be developed to read in a collection of exam scores ranging in value from 0 to 100. Range validation is to be carried out on the exam scores entered. If a score is not within the permissible range, an error message is to be displayed and the user should be allowed to re-enter the score.

Your program should count the number of outstanding scores (90-100), the number of satisfactory scores (60-89), the number of unsatisfactory scores (1-59), and the number of zero scores.

At the end of the run, your program should display the number of students in each category (i.e. outstanding, satisfactory, unsatisfactory, and zero) and the average exam score.

An outline of a program flowchart is given on the next page, with some conditions and actions omitted. The program variables names to be used are:

score, outstd, sat, unsat, zero, count, sum and average

Your task is to 'fill in' the gaps:

     i) Draw the boxes and actions for initialisation, to replace dotted      box (i).      [2]

     ii) State the condition for selection box (ii). Note carefully which      way round the 'yes' and 'no' branches are. [1]

more exams scores to enter?

     iii) State the action for box (iii). [1]

ave = sum/count

     iv) Draw the box for the final output, to replace dotted box (iv). [2]

[1 mark for display shape, 1 mark for all necessary outputs; max 2 marks]

     v) State the condition for selection box (v). [1]

(score < 0) or (score > 100)

     vi) State the condition for selection box (vi) [1]

score = 0

     vii) State the condition for selection box (vii) [1]

score <= 59

     viii) State the condition for selection box (viii). [1]

score <= 89

     ix) State the action for box (ix). [1]

outstd = outstd + 1

     x) Draw the boxes and actions, to replace dotted box (x). [2]

[boxes can appear in either order, or combined]


b) Consider the following diagram of the stages of the System Life Cycle. For each point (i) to (x), identify one document that you would expect to find at this point of the cycle. [10]

i) User request / User requirement / Statement of problem [any one] [1]
ii) Feasibility report [1]
iii) Requirement Analysis / Requirement Specification [any one] [1]
iv) System Specification [1]
v) Program Specification /Test schedule [any one] [1]
vi) Program /Workable solution /Detailed documentation [any one] [1]
vii) Test log /Test plan /Test data /Test results [any one] [1]
viii) Output results from implementation [1]
ix) Changes report /Maintenance report [any one] [1]
x) Review report /Audit report [any one] [1] 

c)  i) Briefly explain what is meant by structured programming. [2]

A program is broken down into smaller components(modules) [1]
Each component(module) is performing a specific task [1]

     ii) State five advantages of using structured programming. [5]

Modules can be reused [to save development time] [1]
Easy to trace error [1]
Amendments are localized [to one module] [1]
Promote teamwork [different modules can be done by different programmers] [1]
Modules can be given a meaningful name [to make identification of module easier in the documentation] [1]

 

[30]
2.

a) A sample screen design for the main menu of a program is as follows:

The main menu will be displayed again after selection of each choice if users do not select choice 4.

In choice 1, the user is prompted for a collection of records and the records will then be stored in a file.

In choice 2, all the records from the file will be retrieved and displayed on the screen.

In choice 3, the user is prompted to enter a target key field. All of the records which match the target will be displayed as the program will retrieve one record from the file at a time, and compare it with the target key field. If it matches, the record is displayed. If it does not match, the next record is retrieved and so on until the end of file.

In choice 4, the user is able to end the program.

Using a CASE_ENDCASE construct, express the program logic using Pseudocode.

(Note: Do not use IF_THEN_ELSE_ENDIF construct to process the menu choices) [13]


1. For using "REPEAT_UNTIL choice=4" to express the whole program logic [Accept also "DO_WHILE choice<>4" , "WHILE choice<>4
DO_ENDDO] [1]

2. For having at least one DO_ENDDO as the starting statement inside either one of the choices [1]

3. For getting input of choice before CASE choice [1]

4. For putting CASE_ENDCASE in the correct place [1]

5. For at least one choice stated inside CASE_ENDCASE [1]

6. For expressing the correct logic using a loop in choice 1
[Ignore pseudocode syntax error] [1]

7. For expressing the correct logic using a loop in choice 2
[Ignore pseudocode syntax error] [1]

8. For getting input of target key field before starting the loop in choice 3 [1]

9. For using IF construct for comparison with target key field in choice 3 [1]

10. For expressing the correct logic using a loop in choice 3
[Ignore pseudocode syntax error] [1]

11. For good indentation [1]

12. Show key words in capital letters [1]

13. For expressing the correct logic for the entire program [Ignore pseudocode syntax error] [1]

[If candidates use IF_THEN_ELSE_ENDIF, award mark based on points 1,6,7,8, 9,10,11 ie. maximum 7 marks to be awarded]


b) i) Explain briefly what a recursive module is. [2]

Recursive module is a module that calls itself [1] Each time it calls itself, it operates on different parameters [1]

    ii) State three essential components of a recursive module. [3]

[Terminating] condition/stopping case [1]
Body [1]
Recursive call [1]

    iii) State one advantage and one disadvantage of using recursion as     compared to iteration. [2]

Advantage: Specify a natural, simpler solution to solve an iterative problem [1]
Disadvantage: Less efficient, in terms of computer time, than iteration [because of the overhead for the extra procedure calls] [1]

c) Name and briefly describe five types of data processing files. (Do not give examples) [10]

Master file [1]
      Consists of permanent or semi permanent data [1]
Transaction file [1]
      Contains source or transaction data to update the master file [1]
Work file [1]
      A temporary file used for storing of intermediate data for further       processing [No mark for just stating "temporary file"] [1]
Transition file [1]
      A temporary file created during processing for a specific use [1]
      [No mark for just stating "temporary file"]
Security or backup file [1]
      An extra copy of a file to safeguard against damage of loss [1]
Audit file [1]
      A particular type of transaction file enable auditor to check the       correct functioning of computer based procedures [1]

[Any five of the above types, one mark for name, one mark for description, maximum 10 marks]

 

[30]
3. a) Consider the following program:

Step no.
1.            FOR i = 1 TO 2
               DO
2.                      k = 10
3.                      FOR j = 1 TO 3
                         DO
4.                               IF i mod j = 0 THEN
                                            DO
5.                                                 DISPLAY i
6.                                                 DISPLAY j
                                            ENDDO
                                  ELSE
7.                                         k = k - 2
                                  ENDIF
                          ENDDO
                ENDDO

Dry run the above code showing, at each step, the content of the variables i, j, k and the other expressions involving i, j and k. Take care to show the execution of each numbered statement. [13]

Step no. i j k i mod j=0 Display i Display j
1 1          
2     10      
3   1        
4       true    
5         1  
6           1
3   2        
4       false    
7     8      
3   3        
4       false    
7     6      
1 2          
2     10      
3   1        
4       false    
7     8      
3   2        
4       true    
5         2  
6           2
3   3        
4       false    
7     6      


For column headings: step number, all variable names, conditional expression and screen display [1]

Award one mark for every two correct row entries [12]

[NB: care need with marking: if an error is made, it should be penalised only once. Subsequent rows should be marked, based on the error row. Thus an answer which has just the first row above wrong, and then all subsequent rows 'correct' based on the erroneous row, would get 1 (for headings) + 11 (for rows) marks, even though all the rows might be different from the totally correct solution above.]

b) There are three kinds of loop-control statements often found in programming languages: for, while and repeat-until.

    i) When would you use the for loop construct? [1]

When you know the number of iterations [before loop execution] [1]

    ii) State the differences between a repeat-until loop and a while loop, in     terms of :

·       execution of the loop body [2

The loop body of repeat-until loop will always execute at least once [1]
A while loop body may be skipped entirely [1]


·       the loop condition and execution of the loop body [2]

Loop body in repeat-until is repeated until its loop-termination condition becomes true [1]
Loop body in while is repeated as long as its loop-repetition condition is true [1]

c) i) Give short descriptions of the following types of decision table :

·      Limited entry decision table [2]

Limited entry:
Condition entries are limited to either a 'Y' or 'N' [1]
Action entries are limited to either a 'X' or '-' [1]

·      Extended entry decision table [3]

Extended entry:
DT can be of extended condition entries or extended action entries [1]
Extended action entries: action not limited to X/-, but extended to value entry [1]
Extended condition entries: condition not limited to Y/N, but extended to entries using relational operator [>,<,>=,<=,=,<>] [1]

·      Mixed entry decision table [2]

Mixed entry:
Consists of both limited and extended entries [2]

    ii) Write brief notes to explain the purpose of a decision table preprocessor.     [3]

It is a software design tool (program development aid) [1]
It translates a decision table into a program [1]
It lists all the contingencies to be considered in the description of a problem, together with the corresponding actions to be taken [1]
It is used to check the validity of logic expressed in decision table form to limit possibility of errors [1]
[any 3 points, max 3 marks]

d) State the two types of high level language translator. [2]

Interpreter [1]
Compiler [1]

[30]