Cs All Scenario Questions (Solution)
Cs All Scenario Questions (Solution)
Cs All Scenario Questions (Solution)
You must use pseudocode or program code with local and global variables
and add comments to explain how your code works. All inputs and outputs
must contain suitable messages.
‘// Global variable to store the size of array
DECLARE ArraySize : INTEGER
ArraySize BabyName.Length
‘// Procedure to sort and display babies in alphabetic order of baby name
PROCEDURE SortBabies
REPEAT
Swap = FALSE
FOR Counter = 0 TO ArraySize – 1
IF BabyName[Counter + 1] < BabyName[Counter] THEN
TempBabyName = BabyName[Counter]
BabyName[Counter] = BabyName[Counter + 1]
BabyName[Counter + 1] = TempBabyName
TempPhone = ParentPhone[Counter]
ParentPhone[Counter] = ParentPhone[Counter + 1]
ParentPhone[Counter + 1] = TempPhone
Page - 1
TempAge = BabyAge[Counter]
BabyAge[Counter] = BabyAge[Counter + 1]
BabyAge[Counter + 1] = TempAge
Swap = TRUE
ENDIF
NEXT Counter
UNTIL Swap = FALSE
END PROCEDURE
‘// Procedure find and display all details of baby with name as parameter
PROCEDURE FindBaby(BName : String)
OUTPUT “Baby’s details.”
FOR Counter = 0 TO ArraySize
IF BabyName[Counter] = BName THEN
OUTPUT BabyName[Counter], BabyAge[Counter], ParentPhone[Counter]
ENDIF
NEXT Counter
END PROCEDURE
‘// Procedure find and update all details of baby with name as parameter
PROCEDURE UpdateBaby(BName : String)
OUTPUT “Update Baby’s details.”
FOR Counter = 0 TO ArraySize
IF BabyName[Counter] = BName THEN
INPUT “Update Baby’s Age = ”, BabyAge[Counter]
INPUT “Update Parent Phone = ”, ParentPhone[Counter]
ENDIF
NEXT Counter
END PROCEDURE
Page - 2
INPUT “To display details, enter the baby’s name = ”, NBaby
CALL FindBaby(NBaby)
The position of each member of staff’s data in the two array is the same,
for example, the member of staff in position 5 in StaffName[ ] and
StaffPhone[ ] is the same.
The arrays and variables have already been set up and data stored.
You must use program code with local and global variables and add
comments to explain how your code works.
.............................................................................................................................................................................
‘//Initialize global variable for number of staff (i.e. for rows of 1D and 2D array) and
‘//types of phone numbers (i.e. for columns of 2D array)
DECLARE StaffCount, TypesOfPhone : INTEGER
StaffCount = 500
TypesOfPhone = 2
REPEAT
‘// Call Procedure to display the available options
CALL DashBoard
‘//Ask the user to input their choice
INPUT "Enter your choice (1 to 3) = ", Choice
Page - 3
‘// Perform each task based on the user’s choice
CASE Choice OF
1:
CALL OrderedListByName
2:
INPUT "Enter the personal phone number = ", PersonalPhone
CALL EditMemberDetails(PersonalPhone)
3:
PRINT "Thanks, see you again."
OTHERWISE
PRINT "Invalid choice"
END CASE
UNTIL Choice = 3
‘// Define Procedure to sort and display staff phone numbers and names in
‘// alphabetic order of name using Bubble Sort method
PROCEDURE OrderedListByName
REPEAT
Swap = 0
FOR Count = 1 TO StaffCount – 1
‘// Sorting Names stored in 1D Array StaffName[ ]
IF StaffName(Count + 1) < StaffName(Count) THEN
TempName = StaffName(Count)
StaffName(Count) = StaffName(Count + 1)
StaffName(Count + 1) = TempName
END PROCEDURE
Page - 4
‘// Define Procedure to edit details of a member by receiving his name as parameter
PROCEDURE EditMemberDetails(StaffPhNo : INTEGER)
Found = "No"
FOR Count = 1 TO StaffCount
IF StaffPhone(Count, 1) = StaffPhNo THEN
PRINT “Staff name = ”, StaffName(Count)
PRINT “Personal phone number = ”, StaffPhone(Count, 1)
PRINT “Office phone number = ”, StaffPhone(Count, 2)
.............................................................................................................................................................................
................................................................................................................................................................... [15]
TEST DATA
StaffName[1:5] StaffPhone[1:5, 1:2]
1 2
1 David 1 9115936 7008005
2 Bastin 2 7504960 2000420
3 Alexis 3 7438985 7008005
4 Elsa 4 9963478 2000420
5 Charles 5 7247828 7008005
Page - 5
Q. An online Social media company stores the customer’s phone number in
1D array PhoneNo[ ]. The customer’s first name, last name and password
in a 2D array UserProfile[ ].
The position of each customer’s data in the two arrays is the same, for
example, the phone number in position 10 in PhoneNo[ ] and UserProfile[.]
is the same.
The variable CustomerNo contains the number of customers in the
company.
The arrays and variables have already been set up and data stored.
Write an algorithm that meets the following requirements:
• Display the options available to choose for the user –
4 Login to the account
5 Change the password.
6 Quit.
• Ask the user to input their choice.
• For choice of option 1 ask to input the phone number for verification
and password to authenticate.
If both matches with data stored in array, then output the customer’s
first and last name with welcome message (like, Welcome David
Anderson), if not then output an error message.
• Allow the user to change his password for the choice of option 2 only if
he is logged-in to the account.
• Stop the program if option 3 is selected with appropriate message.
Perform the task for each option by calling an appropriately named
procedure or function.
.............................................................................................................................................................................
‘// Initialize a tag variable with value “No” to check if customer is logged-in or not
LoginTag = “No”
REPEAT
‘// Call the PROCEDURE to display the options available to choose.
CALL DisplayChoice
Page - 6
‘// PROCEDURE to display the options available to choose.
PROCEDURE DisplayChoice
OUTPUT “1. Login to the account.”
OUTPUT “2. Change the password.”
OUTPUT “3. Quit.”
END PROCEDURE
‘// FUNCTION that gets choice of user as parameter and returns the result as string
FUNCTION LoginAndChangePwd(Option : INTEGER) RETURNS STRING
‘// Check if customer is not logged-in and option is either 1 or 2.
IF LoginTag = “No” AND (Option = 1 OR Option = 2) THEN
OUTPUT “Enter the phone number : ”
INPUT Phone
OUTPUT “Enter the password : ”
INPUT Pwd
FOR People = 1 TO CustomerNo
IF (PhoneNo[People] = Phone AND UserProfile[People, 3] = Pwd) THEN
‘// Returns welcome message with customer name
RETURN “Welcome ”, UserProfile[People, 1], “ ”, UserProfile[People, 2]
‘// Stores the index of the logged-in customer
CustomerIndex = People
LoginTag = “Yes”
EXIT FOR ‘// Exit the loop, once the record is found.
ELSE
LoginTag = “No”
END IF
NEXT People
‘// Returns error message, if login details don’t match stored data
IF LoginTag = “No” THEN RETURN “Error, invalid phone or password.”
END IF
‘// Check if customer is already logged-in and option is 1, and returns a message.
IF (LoginTag = “Yes” AND Option = 1) THEN
RETURN “You are already logged into the account”
END IF
‘// Check if customer is already logged-in and option is 2.
IF LoginTag = “Yes” AND Option = 2 THEN
OUTPUT “Enter the new password : ”
INPUT NewPwd
UserProfile[CustomerIndex, 3] = NewPwd
‘// Returns a message after changing password.
RETURN “Your password is changed successfully.”
END IF
END FUNCTION
................................................................................................................................................................... [15]
Page - 7
Q. Write a program in pseudocode that uses a two-dimensional array,
Game[ ] to store the moves in a noughts and crosses game. The program
should meet the following requirements:
• Start each game with an empty array.
• Allow two players to input their moves in turn; the contents of the
array are displayed before and after every move.
• One player can input ‘O’ and the other input ’X’; no other moves are
allowed, and no move can use a space in the array already occupied.
• After every move the program should check for a completed line of
three Os or three Xs, and if found, output the winner of the game.
................................................................................................................
‘// Declare and Initialise the Array with empty space.
DECLARE Game : ARRAY[1:3, 1:3] OF STRING
FOR Row=1 TO 3
FOR Col=1 TO 3
Game[Row, Col] = ""
NEXT Col
NEXT Row
‘// Input in turn to accept only “X” or “O”, and ensure that each player uses
different symbol.
REPEAT
INPUT "Put nought or cross in row-", XAxis, ", Col-", YAxis, " = ", Symbol
‘// Storing input in upper case letter
Play = UPPER[Symbol]
Page - 8
‘// Tag the input to ensure that consequent inputs are not same.
SymbolTag = Play
‘// Call the Procedure to output the current status of the board
Call DisplayBoard
'// FUNCTION to check who 'won' the game and return the parameter value back.
FUNCTION Result(ParameterMark : STRING) RETURNS STRING
‘// Check for same mark in straight row
FOR Row = 1 TO 3
FOR Col=1 TO 3
IF Game[Row, Col] = ParameterMark THEN
InRow = "True"
ELSE
InRow = "False"
END IF
‘//Exit the inner-loop if the symbols are not same.
IF InRow = "False" THEN EXIT FOR
NEXT Col
‘//Exit the outer-loop altogether if the symbols are same.
IF InRow = "True" THEN EXIT FOR
NEXT Row
Page - 9
NEXT Row
IF InColumn = "True" THEN EXIT FOR
NEXT Col
........................................................................................................ [15]
Page - 10
Q. A hospital need to record the temperature of 20 patients every day in their
intensive care unit. The temperature is measured after every 30 minutes
for a day.
................................................................................................................
DECLARE PName : ARRAY[1:20] OF STRING
DECLARE Temp : ARRAY[1:20, 1:48] OF REAL
FOR Patient = 1 TO 20
HighTemp = 0
LowTemp = 200
TotalTemp = 0
NoAbTemp = 0
NormTempPat = 0
FOR Read = 1 TO 48
INPUT “Enter temperature : ”, Temp[Patient, Read]
IF Temp[Patient, Read] > HighTemp THEN HighTemp = Temp[Patient, Read]
IF Temp[Patient, Read] < LowTemp THEN LowTemp = Temp[Patient, Read]
TotalTemp = TotalTemp + Temp[Patient, Read]
IF Temp[Patient, Read] < 97 OR Temp[Patient, Read] > 100 THEN
NoAbTemp = NoAbTemp + 1
ENDIF
NEXT Read
AvgTemp = TotalTemp/48
OUTPUT “Patient name : ”, PName[Patient]
OUTPUT “Highest temperature : ”, HighTemp
OUTPUT “Lowest temperature : ”, LowTemp
OUTPUT “Average temperature : ”, AvgTemp
OUTPUT NoAbTemp, “ times the temperature was out of range.”
Page - 11
NEXT Patient
................................................................................................................
........................................................................................................ [15]
The position of each patient’s data in the two arrays is the same, for
example, the patient’s data (name and temperature) in position 5 in
PatientName[ ] and PatientTemp[.] is the same.
The variable NumPatients stores the number of patients. The arrays and
variables have already been set up and the data stored.
Write a program for the hospital using pseudocode that meets the following
requirements :
→ Display the available options to produce details of patients :
1. Morning
2. Afternoon
3. Night
→ Ask to input any of the available option between 1 and 3 to show patient
details recorded during the time of their choice.
If invalid option is selected then produce an error message and ask to
re-enter the option.
→ Output each patient’s name, temperature and its status (whether
normal, below or above normal temperature)
→ Count and output the total number of patients whose temperatures
were normal, above and below normal range
→ Calculate and output the average temperature of the patients.
You must add comments to explain how your code works. You do not need
to initialize data in the array.
.....................................................................................................................
Page - 12
‘// Display the available options to select
OUTPUT “1. Morning”
OUTPUT “2. Afternoon”
OUTPUT “3. Evening”
‘// Ask to select and input the available option with validation
REPEAT
OUTPUT “Enter the option (between 1 and 3) to show patient details = ”
INPUT DayTime
‘// Declare the constants with lower limit of above and normal temperature
CONSTANT AboveNormal 100
CONSTANT NormalTemp 97
‘// Initialize the variables to count different temperature status at each interval
NoAboveTemp 0
NoNormalTemp 0
NoBelowTemp 0
TotalTemp 0
NEXT Patient
Page - 13
AverageTemp TotalTemp / NumPatients
.....................................................................................................................
Rewards for customers those who has completed all the tasks:
Reward Points earned
Gold more than or equal to 1000 points
Silver more than or equal to 500 points and less
than 1000 points
Bronze more than or equal to 100 points and less
than 500 points
Write a program using pseudocode that meets the following requirements:
• Calculates the total points earned by each customer for all the tasks
they have completed.
• Calculates the average points earned by each customer for all the tasks
they have completed, rounded to the nearest whole number.
• Outputs for each customer:
o name
o total points
o average points
o reward earned (if any)
• Calculates, stores, and outputs the number of customers who have
earned gold, silver, bronze, and no rewards.
Page - 14
You must add comments to explain how your code works. You do not need
to initialize the data in the arrays.
................................................................................................................
// Initialise constants with points (lower limit) for different rewards
CONSTANT Gold = 1000
CONSTANT Silver = 500
CONSTANT Bronze = 100
Page - 15
OUTPUT “Total points : ”, CTotal
OUTPUT “Average points : ”, AveragePoints
OUTPUT “Rewarded with : ”, Reward
NEXT Customer
‘// Output the overall number of customers with different rewards
OUTPUT “Number of customer reward with Gold is ”, NoGold
OUTPUT “Number of customer reward with Silver is ”, NoSilver
OUTPUT “Number of customer reward with Bronze is ”, NoBronze
OUTPUT “Number of customer without any reward is ”, NoReward
................................................................................................................
Q. The 1D array StudentName[ ] contains the names of students in a class. The 2D array
StudentMark[ ] contains the mark for each subject, for each student. The position of each
student’s data in the two arrays is the same, for example, the student in position 10 in
StudentName[ ] and StudentMark[ ] is the same.
The variable ClassSize contains the number of students in the class. The variable
SubjectNo contains the number of subjects studied. All students study the same number of
subjects.
The arrays and variables have already been set up and the data stored.
Students are awarded a grade based on their average mark.
Average mark Grade awarded
greater than or equal to 70 Distinction
greater than or equal to 55 and less than 70 Merit
greater than or equal to 40 and less than 55 Pass
less than 40 Fail
.............................................................................................................................................................................
// Initialise constants for different grade awarded
CONSTANT Distinction = 70
Page - 16
CONSTANT Merit = 55
CONSTANT Pass = 40
Page - 17
OUTPUT “Number of Merits = ”, NoMerit
OUTPUT “Number of Passes = ”, NoPass
OUTPUT “Number of Fails = ”, NoFail
................................................................................................................................................................... [15]
Page - 18