Here are some further problems for you to solve:
10 The one-dimensional array StaffName[] contains the names of the staff
in a department. Another one-dimensional array StaffPhone[] contains
the phone numbers for the members of staff. A final one-dimensional array
StaffOffice[] contains the office location for the members of staff.
The position of each member of staff’s data in the three arrays is the same,
for example, the member of staff in position 5 in StaffPhone[] and
StaffOffice[] is the same.
Write a program that meets the following requirements:
» uses procedures to display these lists:
– staff phone numbers and names in alphabetic order of staff name
– members of staff grouped by office number
» uses a procedure to display all the details for a member of staff, with the
name used as a parameter
» uses a procedure to update the details for a member of staff, with the
name used as a parameter.
You must use program code with local and global variables and add
comments to explain how your code works. [15]
START
DECLARE StaffName : ARRAY[1:5] OF STRING ={“Friend”, “Dennis”,
“Christopher”,”Khona”, “Mali”}
DECLARE StaffPhone : ARRAY[1:5] OF STRING = {“0112”,”0776”,”0989”,”0666”, “0555”}
DECLARE StaffOffice : ARRAY[1:5] OF STRING={“C14”, “C13”, “C12”, “C11”, “W2”}
DECLARE Count : INTEGER
Count0
PROCEDURE BubbleSort(ByVal StaffName() : STRING, ByVal StaffPhone() : STRING,
ByVal StaffOffice() : STRING)
DECLARE Temp1,Temp2,Temp3 : STRING
DECLARE Swap : BOOLEAN
SwapFalse
REPEAT
FOR Count1 TO 4
IF StaffName(Count)>StaffName(Count+1) THEN
Temp1StaffName(Count)
Temp2StaffPhone(Count)
Temp3StaffOffice(Count)
StaffName(Count) StaffName (Count+1)
StaffPhone(Count) StaffPhone (Count+1)
StaffOffice(Count) StaffOffice (Count+1)
StaffName(Count+1)Temp1
StaffPhone(Count+1)Temp2
StaffOffice(Count+1)Temp3
ENDIF
SwapTrue
NEXT Count
UNTIL Swap=False OR Upperbound>Lowerbound
FOR Count 1 TO 5
OUTPUT “Name: “, StaffName(Count)
OUTPUT “Phone: “, StaffPhone(Count)
OUTPUT “Office: “, StaffOffice(Count)
NEXT Count
END PROCEDURE
PROCEDURE LinearSearch(ByVal StaffName() : STRING, ByVal SearchName : STRING)
DECLARE FoundFlag : Boolean
DECLARE FoundIndex : INTEGER
FoundFlagFalse
FOR Count1 TO 5
IF StaffName(Count)=SearchName THEN
FoundFlagTrue
FoundIndexCount
Next Count
IF FoundFlag=True THEN
OUTPUT “The name is in the array”
OUTPUT “Name: “, StaffName(FoundIndex)
OUTPUT “Phone: “, StaffPhone(FoundIndex)
OUTPUT “Office: “, StaffOffice(FoundIndex)
ELSE
OUTPUT “The name was not found in the arrays”
ENDIF
END PROCEDURE
12 You can become a member of the town guild if you meet all the following
requirements:
» aged between 18 and 65
» you have lived in the town for 20 years
or you have lived in the town for 5 years and both your parents still live in
the town
or one parent has died and the other parent still lives in the town
or you and a brother or a sister have lived in the town for 10 years
» you have half a million dollars in your bank account
» you have never been to prison
» at least two guild members support your application
» if five guild members support your application then you could be excused
one of the above requirements, apart from age
Write a program that allows you to input answers to questions to ensure that
you meet the requirements, issues a unique membership number if you do or
explains all the reasons for failure if you don’t meet the requirements. [15]