Programming QP 1

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 28

FunTech Programming-1 Max.

marks: 174

1. Refer to the prelim material for the following questions:

(a) (i) Give the line number where a global variable is defined.

_____________________________________________________________
__
(1)

(ii) Give the line number where a local variable is defined.

_____________________________________________________________
__
(1)

(b) (i) Give the line number where a function is declared.

_____________________________________________________________
__
(1)

(ii) Explain how a function differs from a procedure.

_____________________________________________________________
__
(1)
(Total 4 marks)

2. (a) Give the name of one ‘call by reference’ parameter.

_______________________________________________________________
(1)

(b) Give the name of one ‘call by value’ parameter.

_______________________________________________________________
(1)

(c) Explain how a ‘call by reference’ parameter differs from a ‘call by value’
parameter.

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

FunTech 1
FunTech Programming-1 Max. marks: 174

_______________________________________________________________
(3)
(Total 5 marks)

3. Cars over three years old have to pass a roadworthy test called the MOT. Various
categories are tested and for this question they have been simplified to:

 Brakes
 Steering
 Tyres
 Bodywork.

A car passes the MOT test – in this simplified scenario – if it passes all four categories.

Data for a single car is stored as a string consisting of the digit characters ‘0’ and ‘1’
e.g. ‘1110’.

 ‘1’ denotes a category pass

 ‘0’ denotes a category fail.

The order of the categories is as shown above. For example, the data ‘1110’ describes a
car which passed on brakes, steering and tyres, but failed on bodywork.

The built-in function SingleCharacter is to be used in the algorithm which follows,


and is described in the help files as follows:

SingleCharacter(ThisString : String; ThisPosition : Integer) : Char ;

Returns the single character at position ThisPosition in the string ThisString.


E.g. Result := SingleCharacter(‘1110’, 4) would return and assign ‘0’ to
Result

The following incomplete algorithm is designed to calculate whether a single car has
passed or failed.

The identifier list for variables used by the algorithm is shown in Table 1.

(a) Complete A, B and C in the algorithm.

CarFailed  False
Input NextCar
For Position  1 To 4

Do NextCategory  SingleCharacter ( A …...........… , B ….......….... )


If C …......…..........................................
Then CarFailed  True

End If

FunTech 2
FunTech Programming-1 Max. marks: 174

End For

If CarFailed = False

Then Output ’Car passed MOT’

Else Output ’Car failed MOT’


End If
(3)

(b) Complete the data types and comment – D, E and F – in Table 1.

The data types should be selected from those shown in Table 2.

FunTech 3
FunTech Programming-1 Max. marks: 174

Table 1
Variable Data Type Comment

Position D ……..........................................................…… E ……...........................................................……

NextCar String Data for a single car

NextCategory F ……...........................................................…… Data for a single category

CarFailed Boolean Result indicator

(3)

Table 2

Data type Explanation


Integer Whole number
Real Number with a fractional part
String Zero or more characters
Char Single character
Boolean True/False values only
(Total 6 marks)

4. A programmer has been asked to write a routine which will calculate a person’s age in
years from the date of birth supplied as a parameter to the routine and today’s date,
taken from the system.
The date of birth is supplied in the format dd/mm/yyyy and has already been checked by
the system to be a valid date before it is passed to the routine.
No person is expected to be over 120 years old.

Suggest suitable values for each of the types of test data, normal, boundary and
erroneous, and explain why you have chosen these values.

(a) two values of normal data:

(i) .....................................................      (ii) .......................................................

reason for choice:

....................................................................................................................................

....................................................................................................................................
(3)

(b) three values to check a boundary:

(i) ...............................    (ii) ..................................   


(iii) ..................................

FunTech 4
FunTech Programming-1 Max. marks: 174

reason for choice:

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................
(4)

(c) one value of erroneous data: ....................................................................

reason for choice:

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................
(2)
(Total 9 marks)

5. (a) Well constructed programs use a structured approach for the design and coding
stages.

One practical way in which the programmer will use a structured approach to
programming is the use of subroutines (procedures/functions). Give three other
ways.

1 .................................................................................................................................

2 .................................................................................................................................

3 .................................................................................................................................
(3)

(b) A program is to be written which calculates the hourly pay rate for an employee.
The calculation is based on the number of complete years the employee has
worked for the firm (e.g. 3 years). All employees get a basic £7.88 per hour. For
each year worked, up to a maximum of 5 years only, an additional £0.65 is added
to the basic hourly rate.

The algorithm for this program is as follows:

1. Enter the surname


2. Enter the number of years of service
3. Calculate the employee’s pay rate
4. Output the surname and pay rate

(i) Complete the table showing three variable identifiers and their data types
you would use for this problem.

Variable Identifier Data Type

FunTech 5
FunTech Programming-1 Max. marks: 174

(3)

(ii) The detail for step 3 in the algorithm is broken down into more detail as
follows:

3.1 If the number of years of service value is over 5, then change


the
value stored to 5

3.2 Calculate the employee’s pay rate

Write pseudo-code for these two steps using the appropriate identifiers from
the table.

3.1.....................................................................................................................

…......................................................................................................................

3.2.....................................................................................................................

…......................................................................................................................
(3)
(Total 9 marks)

6. A company makes sofas and operates seven days a week. Each day a record is made of
the number of sofas that are rejected at the final quality control stage. An average of one
reject each day is considered acceptable. This is investigated using the program below at
the end of each week.
Program RejectReport;
Var
DayNo: Integer;
RejectTotal: Integer;
DailyRejects: Array [1..7] of Integer;

Begin
RejectTotal := 0;
For DayNo := 1 To 7
Do RejectTotal := RejectTotal + DailyRejects [DayNo];
WriteLn(RejectTotal);
End.

(a) What does this program do?

....................................................................................................................................
.

....................................................................................................................................
.

....................................................................................................................................
.
(2)

(b) (i) Write the assignment statement in the program which performs a
calculation.

FunTech 6
FunTech Programming-1 Max. marks: 174

..........................................................................................................................
(1)

(ii) Write a declaration statement that appears in the program.

..........................................................................................................................
(1)

(iii) What is the purpose of the variable DayNo?

..........................................................................................................................
(1)

(iv) What type of data structure is DailyRejects?

..........................................................................................................................
(1)

(c) The program is to be extended to report whether this was a satisfactory week for
the number of rejected sofas. An average of one reject each day is considered
acceptable.

Write additional programming statement(s), in the language you are familiar with,
to report one of the messages ‘Investigate’ or ‘Inside weekly tolerance’. Use the
same variable identifiers as used in the program given.

....................................................................................................................................
.

....................................................................................................................................
.

....................................................................................................................................
.

....................................................................................................................................
.

....................................................................................................................................
.

....................................................................................................................................
.
(2)

(d) “A programming team should make extensive use of program libraries.”

Explain this
statement ................................................................................................

....................................................................................................................................
.

FunTech 7
FunTech Programming-1 Max. marks: 174

....................................................................................................................................
.

....................................................................................................................................
.
(2)

(e) Another application is to be developed. The number of rejects per week is


recorded over a five-week period. This data is stored in array NoOfRejects. The
array WeeklySupervisor records who the supervisor was for week 1, week 2,
etc. A third array SupervisorTotal will record the total number of unsatisfactory
weeks for each of the three supervisors.

The pseudo-code which follows in Figure 1 makes clear which array position is
used for each supervisor.

Figure 1

NoOfRejects WeeklySupervisor

[5] 9 [5] ‘Jones’

[4] 8 [4] ‘Summers’ SupervisorTotal

[3] 1 [3] ‘Jones’ [3]

[2] 9 [2] ‘Summers’ [2]

[1] 8 [1] ‘Franks’ [1]

SupervisorTotal [1] 0
SupervisorTotal [2] 0
SupervisorTotal [3] 0

For WeekNo 1 to 5
ThisNumber NoOfRejects [WeekNo]
If ThisNumber > 7 Then
Output ‘Investigate’
Call AddToSupervisorTotal
End If
End For

Procedure AddToSupervisorTotal
If WeeklySupervisor [WeekNo] = ‘Franks’
Then SupervisorTotal [1] SupervisorTotal [1] + 1
End If
If WeeklySupervisor [WeekNo] = ‘Summers’
Then SupervisorTotal [2] SupervisorTotal [2] + 1
End If
If WeeklySupervisor [WeekNo] = ‘Jones’
Then SupervisorTotal [3] SupervisorTotal [3] + 1
End If
End Procedure

(i) The number of unsatisfactory weeks when Jones was in charge is stored in

FunTech 8
FunTech Programming-1 Max. marks: 174

the array SupervisorTotal. At what position in the array is this number


stored?

..........................................................................................................................
(1)

(ii) Trace the algorithm by completing the trace table in Table 1.

Table 1
WeekNo ThisNumber Output SupervisorTotal
[1] [2] [3]
0 0 0
1

(6)
(Total 17 marks)

7. (a) Writing program code requires the programmer to use identifiers for variables and
procedures.

(i) State two other uses for identifiers.

1 .......................................................................................................................
..

2 .......................................................................................................................
..
(2)

(ii) Most programming languages impose restrictions or rules about what is and
is
not allowed for identifier names. State one such rule.

..........................................................................................................................
(1)

(b) Program code is often written with the use of procedures. Describe one reason
why a
programmer would decide to use procedures.

……............................................................................................................................

……............................................................................................................................
(1)

(c) A programmer-written function SearchThisArray is defined as follows.

SearchThisArray(ThisArray : Array[1..10] Of String;


ThisString : String) : Integer ;

The function searches the array ThisArray for the value ThisString.

FunTech 9
FunTech Programming-1 Max. marks: 174

If an exact match is found, the function returns the index position in ThisArray.
If not found, the function returns -1.
If the function’s arguments, ThisArray and ThisString are illegally formed, the
function returns -2

The function is used in a program with the statements shown below and uses the
data shown in the Customer array in the figure below.

Index
(Subscript) Customer
[1] Weeks
[2] Adamson
[3] Patel
[4] Berkovic
[5] Ince
[6] Neale
[7] Williamson
[8] Collins
[9] Davis
[10] Beckham

What is the value returned to variable Result in each case?

(i) Result := SearchThisArray(Customer, ’Beckham’)

Value of
Result ................................................................................................
(1)

(ii) Result := SearchThisArray(Customer, ’Williams’)

Value of
Result ................................................................................................
(1)
(Total 6 marks)

8. A county has a number of local libraries in various towns. Books currently belong to
each library and there is no system for the exchange of books between libraries.

New programs have to be written, as the decision has been made to have centralised
records of library books.

The software house commissioned to write the new programs has obtained a complete
list of titles held at each library. It found that a common system was used for the book
codes. Some older books will not be retained and this is to be indicated by the
ToBeRetained column in the table below.

BookTitle BookCode YearFirstInStock ToBeRetained


Hang-gliding made simple T05320 1993
Around the world in 80 days T76542 2001
My way M11981 1990
Starting with hypnotherapy M79080 2005
Kim Smith – the
M00876 1991
autobiography

FunTech 10
FunTech Programming-1 Max. marks: 174

XXX

(a) Study the sample data shown in the table. This data will be accessed by program
code. Name the most suitable data type which should be used for each data item.
Each data type must be different.

(i) BookCode ........................................................................................................


(1)

(ii)

YearFirstInStock .........................................................................................
.....
(1)

(iii)

ToBeRetained .................................................................................................
.
(1)

(b) The first application to be developed is a program to search the complete list of
books and to calculate the data values for the ToBeRetained column; any books
which were bought before 1992 will not be retained.

The incomplete pseudo-code which follows shows a first attempt at the algorithm.
Data for each of the four attributes BookTitle, BookCode, YearFirstInStock,
ToBeRetained are shown in the table above, and are to be stored in four arrays
BookTitle, BookCode, YearFirstInStock and ToBeRetained.

Complete the pseudo-code in the three places indicated.

For Book 1 To TotalNoOfBooks

If YearFirstInStock[ (i) .................................... ] < 1992

Then ToBeRetained[Book] (ii) ....................................................

Else ToBeRetained[Book] (iii) ....................................................

EndIf

EndFor
(3)

(c) A second program is to be developed to allocate each book a new code number.
The old book codes are to be abandoned. The first character of the old book code
indicates the book’s location.

• This book location is to be retained and stored in an array Location.


• Each new book code will be a unique integer number that will be
generated by the program. The first number will be 1.

Use will be made of a ‘built-in’ function StartString. It is defined in the help files as
follows:

FunTech 11
FunTech Programming-1 Max. marks: 174

Function StartString(ThisString : String; NoOfCharactersToRetain : Integer) :


String ;

The function is given the string ThisString and returns the number of characters specified by
NoOfCharactersToRetain starting from the first character of ThisString.

(i) What are the values of the parameters used in the following code?

NewString : = StartString(‘T76542’, 1)

1 .......................................................................................................................
.

2 .......................................................................................................................
.
(2)
(ii) What value is assigned to NewString when this code is executed?

..........................................................................................................................
.
(1)

(iii) The pseudo-code for the algorithm to calculate the new book codes and the
locations is shown below.
NextAvailableCode 1
Book 1
Repeat
If YearFirstInStock[Book] >=1992
Then
Begin
LocationLetter StartString(BookCode[Book], 1)
If LocationLetter = ’T’
Then Location[Book] ‘Torrington’
If LocationLetter = ‘M’
Then Location[Book] ‘Morristown’

NewCode[Book] NextAvailableCode
NextAvailableCode NextAvailableCode + 1
End
Book Book + 1
Until BookTitle[Book] = ’XXX’

Trace the execution of this algorithm by completing the trace table Figure 2; use the
data shown in the table Figure 1.

Show also the final contents of the Location and NewCode arrays in Figure 3 and Figure
4.

Figure 1
BookTitle BookCode YearFirstInStock
[1] Hang-gliding made simple [1] T05320 [1] 1993
[2] Around the world in 80 days [2] T76542 [2] 2001
[3] My way [3] M11981 [3] 1990
[4] Starting with hypnotherapy [4] M79080 [4] 2005

FunTech 12
FunTech Programming-1 Max. marks: 174

[5] Kim Smith – the autobiography [5] M00876 [5] 1991


[6] XXX [6] [6]

Figure 2

NextAvailableCode Book LocationLetter


1 1 ‘T’

Figure 3 Figure 4
Location New Code
[1] [1]
[2] [2]
[3] [3]
[4] [4]
[5] [5]
(6)
(Total 15 marks)

9. (a) (i) Explain one difference between a procedure and a function.

..........................................................................................................................
..

..........................................................................................................................
..

..........................................................................................................................
..
(2)

(ii) Name and describe a built-in function you have used in your programming
work, or when using a generic software package.

..........................................................................................................................
..

..........................................................................................................................
..
(2)

(b) A particular built-in function is described in a programming language’s help files


as follows:

Function MatchString(ThisString , StringSearchedFor : String) :Boolean


The function MatchString returns a Boolean value indicating whether or not
the string StringSearchedFor appears within the string ThisString.
An error is returned when a function call is incorrectly formed.

FunTech 13
FunTech Programming-1 Max. marks: 174

What value is returned to the Result1, Result2 and Result3 variables from the
following function calls?

(i) Result1 := MatchString (‘Harry Potter’, ‘Pot’)

..........................................................................................................................
..
(1)

(ii) Result2 := MatchString (‘Potter’, ‘Harry Potter’)

..........................................................................................................................
..
(1)

(iii) Result3 := MatchString (‘Harry Potter’, 59)

..........................................................................................................................
..
(1)

(c) In part (b) (i) Result1 is an identifier used for a variable. Name two other uses for
identifiers in a high level language.

1 .................................................................................................................................
..

2 .................................................................................................................................
..
(2)

(d) The programming language being used has both compiler and interpreter software
for program development.

Give one advantage of the use of each.

Interpreter advantage .................................................................................................

....................................................................................................................................

....................................................................................................................................
(1)

Compiler
advantage ...................................................................................................

....................................................................................................................................

....................................................................................................................................
(1)
(Total 11 marks)

10. A retail store employs ten sales staff. Staff try to persuade customers to take out a store
card with the company when they make a purchase. The store keeps a record of the
FunTech 14
FunTech Programming-1 Max. marks: 174

number of new store cards issued by its sales staff over the first six months of the year.

Table 1

StoreCards
[1] [2] [3] [4] [5] [6]
[1] 12 12 6 8 3 2
[2] 12 17 7 4 5 6
[3] 2 12 0 12
[4] 4 10 7 4
[5] 5 0 0 0 0 0
[6] 6 1 4 6 7 8
[7] 12 19 12 16 17 6
[8] 13 9 7 3 4 5
[9] 12 8 4 4 5 4
[10] 14 11 12 4 5 6

The data is to be stored in a 2-dimensional array with identifier StoreCards as shown in


the table above The first subscript of the array represents the row number (the
salesperson number), and the second subscript the column number (the month).

(a) In the table the value 16 has been emboldened. Explain what this value
represents.

....................................................................................................................................
.
(2)

(b) Write a declaration statement for the array StoreCards.

....................................................................................................................................
.
(2)

(c) Using the data given in the table abobe, write an assignment statement for the
January sales for salesperson 8.

....................................................................................................................................
.
(2)

(d) Study the pseudo-code below.

Input SalesPersonNumber
PersonTotal ← 0
For Month ← 1 to 6 Do
PersonTotal ← PersonTotal + StoreCards[SalesPersonNumber, Month]
End For
Print PersonTotal

FunTech 15
FunTech Programming-1 Max. marks: 174

Explain what this algorithm is designed to do.

....................................................................................................................................
.

....................................................................................................................................
.

....................................................................................................................................
.

....................................................................................................................................
.
(2)
(e) A number of programs are to be written for the store card application, and the
following are some of the data values which will need to be stored and/or
calculated.

State what data type the programmer would use for each data item below.

(i) Average overtime hours worked by each member of staff.

..........................................................................................................................
.
(1)

(ii) Whether or not the staff are willing to work on Boxing Day.

..........................................................................................................................
.
(1)

(iii) The number of customer complaints made about each member of staff.

..........................................................................................................................
.
(1)
(Total 11 marks)

11. A program has been written to store data about a school in a large town. For each of the
following, name a suitable data type and give a reason for your choice:

(a) number of students in the school;

Data
type: .................................................................................................................
...

Reason: ......................................................................................................................
.
(2)

(b) the school’s telephone number such as 0122456789;

Data

FunTech 16
FunTech Programming-1 Max. marks: 174

type: .................................................................................................................
...

Reason: ......................................................................................................................
..
(2)

(c) whether the school offers ‘A’ levels or not;

Data
type: .................................................................................................................
..

Reason: ......................................................................................................................
(2)

(d) the average number of students per teacher.

Data type: ..................................................................................................................

Reason: ......................................................................................................................
(2)
(Total 8 marks)

12. The following code is part of a high level program

Var S: String
Var Count: Integer
Var Size: Integer
S := “fred”
Size := Length(S)
If Size > 0
Then
For Count := 1 To Size Do
ToUpper(S,Count)
EndFor
EndIf

(a) By copying one relevant line from the above code, give an example of:

(i) variable declaration

..........................................................................................................................
..
(1)

(ii) selection statement

..........................................................................................................................
..
(1)

(iii) assignment statement

..........................................................................................................................

FunTech 17
FunTech Programming-1 Max. marks: 174

..
(1)

(iv) iteration

..........................................................................................................................
..
(1)

(b) The built in subroutines Length and ToUpper have been used in the above code.

Length(S) returns the number of characters in string S

ToUpper(S,n) converts the nth character of S to upper case

Subroutines can be either functions or procedures.

(i) By ticking the correct boxes in the table below, indicate whether the
subroutines are functions or procedures.

Subroutine Procedure Function


Length
ToUpper
(2)
(ii) What are the differences between a function and a procedure?

..........................................................................................................................
..

..........................................................................................................................
..

..........................................................................................................................
..
(2)
(Total 8 marks)
13. The following code is part of a high level program

Var Name: String;


Var Hours: Integer;
Var RateOfPay: Real;


Function CalculatePay(InHours: Integer; InRateOfPay: Real): Real;


Var Total: Real;



(a) Procedures and functions are often self-contained. What is meant by the term self-
contained in this context?

FunTech 18
FunTech Programming-1 Max. marks: 174

....................................................................................................................................
......

....................................................................................................................................
......
(1)

(b) Give one reason why the use of global variables may introduce program bugs.

....................................................................................................................................
......

....................................................................................................................................
......
(1)
(Total 2 marks)

14. (a) Name two different coding systems used to represent characters in a computer
system.

1 .................................................................................................................................

2 .................................................................................................................................
.
(2)

(b) In one coding system the character digits are assigned the decimal number codes
48 to 57.

The operators DIV and MOD perform integer arithmetic.


x DIV y calculates how many times y divides into x,
for example 7 DIV 3 = 2.
x MOD y calculates the remainder that results after the division,
for example 7 MOD 3 = 1.

(i) The following algorithm uses an array Result. Dry run this algorithm by
completing the trace table below.

x  835
Index  0
Repeat
Index  Index + 1
Result[Index]  x MOD 10 + 48
x  x DIV 10
UNTIL x = 0

x Index Result
[3] [2] [1]
835 0 – – –
83 1 – – 53

FunTech 19
FunTech Programming-1 Max. marks: 174

(6)

(ii) Explain the purpose of the algorithm.

..........................................................................................................................
.
(1)
(Total 9 marks)

FunTech 20
FunTech Programming-1 Max. marks: 174

15. The following pseudo code represents a program that reads 10 integer numbers entered
by a user and outputs the average.

Program CalculateStatistics

Table[10] : Array of Integers


Result : Real Number

Call Procedure ReadTenIntegers(Table)


Call Procedure CalculateAverage(Table, Result)
Call procedure DisplayAverage(Result)

(a) (i) Name a parameter used in the above program.

..........................................................................................................................
.
(1)

(ii) Explain how this parameter is used.

..........................................................................................................................
.
(1)

(b) Draw a structure chart to represent the above program.

(2)
(Total 4 marks)

16. The following code is part of a high level language program:

FunTech 21
FunTech Programming-1 Max. marks: 174

Const MaxChars = 5;
Var
Message : Array[1..MaxChars] Of Char;
LastChar : Integer;
Position : Integer;

Procedure Insert (c: Char);


Begin
If LastChar < MaxChars
Then
Begin
Position := Position + 1;
Message[Position] := c;
End;
End

Function Find (c: Char) : Integer;


Var
Found: Boolean;
Begin
Position := 0;
Found := False;
While (Position<LastChar) And Not Found
Do
Begin
Position := Position + 1;
If Message[Position] = c
Then Found := True;
End;
If Found
Then Find := Position
Else Find    := 0;
End;

(a) In each case, identify the following by copying one relevant statement from the
code opposite:

(i) constant definition;

..........................................................................................................................
.
(1)

(ii) variable declaration;

..........................................................................................................................
.
(1)

(iii) assignment statement;

..........................................................................................................................
.
(1)

FunTech 22
FunTech Programming-1 Max. marks: 174

(iv) selection statement;

..........................................................................................................................
.
(1)

(v) iteration.

..........................................................................................................................
.
(1)

(b) In each case, from the code opposite, identify a:

(i) global variable;

..........................................................................................................................
.
(1)

(ii) parameter.

..........................................................................................................................
.
(1)

(c) Functions and procedures are both subroutines. Give one difference between a
function and a procedure.

....................................................................................................................................
.

....................................................................................................................................
.
(1)
(Total 8 marks)

17. The following code is part of a high level language program to manage a telephone
contact list:

Const Max = 200

Type TMember = Record


Name: String
TelNo: String
Age: Integer
EndRecord

Var Member: Array [1..Max] Of TMember

Procedure FindTelNo (WantedName: String)


Var EndOfList: Boolean
Begin

FunTech 23
FunTech Programming-1 Max. marks: 174

EndOfList := False
Ptr:= 1
While WantedName < > Member[Ptr].Name And Not EndOfList Do
Ptr := Ptr + 1
If Ptr > Max Then EndOEList : = True
EndWhile
If EndOfList
Then Print (‘Name not in list’)
Else Print (Member[Ptr-1].Name, ‘tel: ’, Member[Ptr-1].TelNo)
Endlf
End

(a) Identify the following by copying one relevant statement from the above code.

(i) constant definition: ..........................................................................................


(1)

(ii) assignment statement: ......................................................................................


(1)

(iii) selection statement: .........................................................................................


(1)

(iv) iteration: ..........................................................................................................

..........................................................................................................................
(1)

(b) Identify the following by copying one relevant part statement from the above
code.

(i) user-defined type: ............................................................................................


(1)

(ii) parameter: .......................................................................................................


(1)

(iii) local variable: .................................................................................................


(1)

(c) Why is it considered to be good programming practice to use named constants


such as Max?

....................................................................................................................................
.

....................................................................................................................................
.
(1)

(d) (i) Why is it not good design to use a field Age when storing personal details?

..........................................................................................................................

..........................................................................................................................
(1)

FunTech 24
FunTech Programming-1 Max. marks: 174

(ii) What could the programmer have done instead?

..........................................................................................................................

..........................................................................................................................
(1)

(e) What values can a Boolean expression take?

....................................................................................................................................
(1)
(Total 11 marks)

18. The following code is part of a high level program to manipulate text:

Var SI: String


Var S2: String
Var Ptr: Integer
Var L: String
S1 := “PAT”
S2 := ““ {“” denotes an empty string}
For Ptr := 1 To 3 Do
L := Copy (S1, Ptr)
S2 := Concat (L, S2)
EndFor
If S1 = S2
Then Print (‘True’)
Else Print (‘False’)
EndIf

(a) By copying one relevant line from the above code, give an example of:

(i) variable declaration...........................................................................................


(1)

(ii) selection statement............................................................................................


(1)

(iii) iteration.............................................................................................................
(1)

(b) The built-in subroutines Copy, Concat and Print have been used in the above
code.

Copy (S, n) returns the nth character of string S


example: Copy (“ABCDE”,2) returns the character “B”.

Concat (S1, S2) concatenates the two strings S1 and S2 and returns a single
string example: Concat (“ABCD”,”EF”) returns the string
“ABCDEF”.

Print (S) prints the string S as output.

Subroutines are either functions or procedures. Indicate, by ticking the correct boxes,
what each of the above subroutines is.

FunTech 25
FunTech Programming-1 Max. marks: 174

subroutine procedure function


copy
concat
print
(3)

(c) Dry run the above code by completing the table below.

S1 Ptr L S2
“PAT” “”
1 “P” “P”

Printed Output:
(8)
(Total 14 marks)

19. The following code is part of a high level language program:

CONST Max = 5;
VAR Tptr : INTEGER;
VAR Store : ARRAY[1..Max] OF CHAR;

PROCEDURE add (a: CHAR);


BEGIN
IF Tptr < Max THEN
BEGIN
Tptr := Tptr + 1;
Store[Tptr] :=a;
END;
END;

FUNCTION Take : CHAR;


VAR Ptr: INTEGER;
BEGIN
IF Tptr>0 THEN
BEGIN
Take := Store[1];
Tptr := Tptr–1;
FOR Ptr := 1 TO Tptr DO store[Ptr] := store[Ptr+1]
END;
END;

(a) Identify the following by copying one relevant statement from the above code.

(i) constant definition............................................................................................


(1)

(ii) variable declaration .........................................................................................


(1)

FunTech 26
FunTech Programming-1 Max. marks: 174

(iii) local variable ...................................................................................................


(1)

(iv) global variable .................................................................................................


(1)

(v) parameter..........................................................................................................
(1)

(vi) assignment statement .......................................................................................


(1)

(vii) selection statement ...........................................................................................


(1)

(viii) iteration.............................................................................................................
(1)

(b) Functions and procedures are both subroutines. What is a difference between a
function and a procedure?

....................................................................................................................................

....................................................................................................................................
(1)
(Total 9 marks)

20. (i) What is meant by data integrity?

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................
(2)

(ii) Describe a method of ensuring the integrity of data.

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................

....................................................................................................................................
(2)
(Total 4 marks)
21. A program which is used over a long period will probably have to be up-dated or
amended.

(a) State two features of a modern block structured language which a good
programmer will use to produce a program which is easy to understand and
modify.

FunTech 27
FunTech Programming-1 Max. marks: 174

1 ..............................................................................................................................

2 ..............................................................................................................................
(2)

(b) Give two items which should be included in separate program documentation for
ease of modification.

1 ..............................................................................................................................

2 ..............................................................................................................................
(2)
(Total 4 marks)

FunTech 28

You might also like