Programming QP 1
Programming QP 1
Programming QP 1
marks: 174
(a) (i) Give the line number where a global variable is defined.
_____________________________________________________________
__
(1)
_____________________________________________________________
__
(1)
_____________________________________________________________
__
(1)
_____________________________________________________________
__
(1)
(Total 4 marks)
_______________________________________________________________
(1)
_______________________________________________________________
(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’.
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 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.
CarFailed False
Input NextCar
For Position 1 To 4
End If
FunTech 2
FunTech Programming-1 Max. marks: 174
End For
If CarFailed = False
FunTech 3
FunTech Programming-1 Max. marks: 174
Table 1
Variable Data Type Comment
(3)
Table 2
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.
....................................................................................................................................
....................................................................................................................................
(3)
FunTech 4
FunTech Programming-1 Max. marks: 174
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
(4)
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
(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.
(i) Complete the table showing three variable identifiers and their data types
you would use for this problem.
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:
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.
....................................................................................................................................
.
....................................................................................................................................
.
....................................................................................................................................
.
(2)
(b) (i) Write the assignment statement in the program which performs a
calculation.
FunTech 6
FunTech Programming-1 Max. marks: 174
..........................................................................................................................
(1)
..........................................................................................................................
(1)
..........................................................................................................................
(1)
..........................................................................................................................
(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)
Explain this
statement ................................................................................................
....................................................................................................................................
.
FunTech 7
FunTech Programming-1 Max. marks: 174
....................................................................................................................................
.
....................................................................................................................................
.
(2)
The pseudo-code which follows in Figure 1 makes clear which array position is
used for each supervisor.
Figure 1
NoOfRejects WeeklySupervisor
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
..........................................................................................................................
(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.
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)
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
Value of
Result ................................................................................................
(1)
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.
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.
(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.
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.
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
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
Figure 2
Figure 3 Figure 4
Location New Code
[1] [1]
[2] [2]
[3] [3]
[4] [4]
[5] [5]
(6)
(Total 15 marks)
..........................................................................................................................
..
..........................................................................................................................
..
..........................................................................................................................
..
(2)
(ii) Name and describe a built-in function you have used in your programming
work, or when using a generic software package.
..........................................................................................................................
..
..........................................................................................................................
..
(2)
FunTech 13
FunTech Programming-1 Max. marks: 174
What value is returned to the Result1, Result2 and Result3 variables from the
following function calls?
..........................................................................................................................
..
(1)
..........................................................................................................................
..
(1)
..........................................................................................................................
..
(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.
....................................................................................................................................
....................................................................................................................................
(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
(a) In the table the value 16 has been emboldened. Explain what this value
represents.
....................................................................................................................................
.
(2)
....................................................................................................................................
.
(2)
(c) Using the data given in the table abobe, write an assignment statement for the
January sales for salesperson 8.
....................................................................................................................................
.
(2)
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
....................................................................................................................................
.
....................................................................................................................................
.
....................................................................................................................................
.
....................................................................................................................................
.
(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.
..........................................................................................................................
.
(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:
Data
type: .................................................................................................................
...
Reason: ......................................................................................................................
.
(2)
Data
FunTech 16
FunTech Programming-1 Max. marks: 174
type: .................................................................................................................
...
Reason: ......................................................................................................................
..
(2)
Data
type: .................................................................................................................
..
Reason: ......................................................................................................................
(2)
Reason: ......................................................................................................................
(2)
(Total 8 marks)
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:
..........................................................................................................................
..
(1)
..........................................................................................................................
..
(1)
..........................................................................................................................
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.
(i) By ticking the correct boxes in the table below, indicate whether the
subroutines are functions or procedures.
..........................................................................................................................
..
..........................................................................................................................
..
..........................................................................................................................
..
(2)
(Total 8 marks)
13. The following code is part of a high level program
(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.
(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)
..........................................................................................................................
.
(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
..........................................................................................................................
.
(1)
..........................................................................................................................
.
(1)
(2)
(Total 4 marks)
FunTech 21
FunTech Programming-1 Max. marks: 174
Const MaxChars = 5;
Var
Message : Array[1..MaxChars] Of Char;
LastChar : Integer;
Position : Integer;
(a) In each case, identify the following by copying one relevant statement from the
code opposite:
..........................................................................................................................
.
(1)
..........................................................................................................................
.
(1)
..........................................................................................................................
.
(1)
FunTech 22
FunTech Programming-1 Max. marks: 174
..........................................................................................................................
.
(1)
(v) iteration.
..........................................................................................................................
.
(1)
..........................................................................................................................
.
(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:
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.
..........................................................................................................................
(1)
(b) Identify the following by copying one relevant part statement from the above
code.
....................................................................................................................................
.
....................................................................................................................................
.
(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
..........................................................................................................................
..........................................................................................................................
(1)
....................................................................................................................................
(1)
(Total 11 marks)
18. The following code is part of a high level program to manipulate text:
(a) By copying one relevant line from the above code, give an example of:
(iii) iteration.............................................................................................................
(1)
(b) The built-in subroutines Copy, Concat and Print have been used in the above
code.
Concat (S1, S2) concatenates the two strings S1 and S2 and returns a single
string example: Concat (“ABCD”,”EF”) returns the string
“ABCDEF”.
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
(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)
CONST Max = 5;
VAR Tptr : INTEGER;
VAR Store : ARRAY[1..Max] OF CHAR;
(a) Identify the following by copying one relevant statement from the above code.
FunTech 26
FunTech Programming-1 Max. marks: 174
(v) parameter..........................................................................................................
(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)
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
(2)
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
(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