Cs All Scenario Questions (Solution)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Paper -2 : Problem solving Grade : 10 ( A / B )

Writing Algorithm for different Scenarios


(Scenario based Questions) Name : Masha

Q. The one-dimensional array BabyName[ ] contains the names of the babies


in a nursery.
Another one-dimensional array ParentPhone[ ] contains the phone
numbers for the parents of the baby.
A final one-dimensional array BabyAge[ ] contains the baby’s age in
months.
The position of each baby’s data in the three arrays is the same; for
example, the baby in position 3 in BabyName[ ], ParentPhone[ ] and
BabyAge[ ] is the same.
Write a program that meets the following requirements:
• uses procedures to display these lists:
→ parent phone numbers and baby names in alphabetic order of baby
name
→ baby names for babies aged under three months
• uses a procedure to display all the details for a baby, with the name
used as a parameter
• uses a procedure to update the details for a baby, with the name used
as a parameter.

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

‘// Display babies sorted list


OUTPUT “List of Babies in alphabetic order of their name.”
FOR Counter = 0 TO ArraySize
OUTPUT BabyName[Counter], ParentPhone[Counter]
NEXT Counter

END PROCEDURE

‘// Procedure find and display babies under 3 months


PROCEDURE UnderAgeBabies
OUTPUT “List of Babies under 3 months.”
FOR Counter = 0 TO ArraySize
IF BabyAge[Counter] < 3 THEN
OUTPUT BabyName[Counter]
ENDIF
NEXT Counter
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

‘// CALLING the Procedures


CALL SortBabies
CALL UnderAgeBabies

Page - 2
INPUT “To display details, enter the baby’s name = ”, NBaby
CALL FindBaby(NBaby)

INPUT “To update details, enter the baby’s name = ”, NBaby


CALL UpdateBaby(NBaby)

Q. A company stores the names of their 500 staff members in one-


dimensional array StaffName[ ]. The staff’s personal phone number and
office phone number in another two-dimensional array StaffPhone[ ].

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.

Write an algorithm that meets the following requirements:


• Define and call a procedure to display the options available to choose
for the user –
1 Display staff phone numbers and names in alphabetic order
2 Ask to enter the staff’s personal phone number to display and
update their details.
3 Quit.
• Ask the user to input their choice.
• Perform the task for option 1 and 2 by calling an appropriately named
procedure.
• Stop the program for choice of option 3.
• Output an appropriate error message on entry of invalid option and ask
to re-enter their choice.

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 display the available options


PROCEDUCE DashBoard
PRINT "Choose any option from 1 to 5 to perform its task."
PRINT "1. Display phone number and name in alphabetic order of staff name."
PRINT "2. Enter the personal phone number to display and update staff details"
PRINT "3. Quit."
END PROCEDURE

‘// 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

‘// Swapping rows of 2D Array when 1D Array rows are swapped


FOR PhoneType = 1 TO TypesOfPhone
PhoneNum = StaffPhone(Count, PhoneType)
StaffPhone(Count, PhoneType) = StaffPhone(Count + 1, PhoneType)
StaffPhone(Count + 1, PhoneType) = PhoneNum
NEXT PhoneType
Swap = 1
END IF
NEXT Count
LOOP UNTIL Swap = 0
‘// Output the sorted list of phone numbers and names of staff members
FOR Count = 1 TO StaffCount
PRINT StaffPhone(Count, 1), StaffName(Count)
NEXT Count

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)

INPUT "Update Name : ", StaffName(Count)


INPUT "Update personal phone number : ", StaffPhone(Count, 1)
INPUT "Update office phone number : ", StaffPhone(Count, 2)
PRINT "Member details updated."
Found = "Yes"
EXIT FOR
END IF
NEXT Count
IF Found = "No" THEN PRINT "Sorry, record not found"
END PROCEDURE

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

................................................................................................................................................................... [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

OUTPUT “Enter your choice (option 1 to 3) = ”


INPUT Choice

CASE Choice OFF


1 : PRINT LoginAndChangePwd(Choice) ‘// Calling FUNCTION
2 : PRINT LoginAndChangePwd (Choice) ‘// Calling FUNCTION
3 : OUTPUT “Thanks see you again.”
OTHERWISE
OUTPUT “Invalid, re-enter the choice.”
ENDCASE
UNTIL Choice = 3 ‘// Stop the program for choice of option-3

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.

Use procedures and parameters in your program.

You must add comments to explain how your code works.

................................................................................................................
‘// 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

‘// Loop to input 9 different moves for 3x3 cells.


FOR Move=1 TO 9
‘// Input the location of move and accept only if it is empty.
REPEAT
INPUT "Enter the any row (1 to 3) : ", XAxis
INPUT "Enter the any column (1 to 3) : ", YAxis
IF Game[ XAxis, YAxis] < > “” THEN
PRINT “Invalid, this place is not empty”
UNTIL Game[XAxis, YAxis] = “”

‘// 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]

IF NOT(Play = ”X” OR Play = ”O”) THEN OUTPUT “Invalid symbol, try


again”
IF (Move > 1 AND Play = SymbolTag) THEN OUTPUT “Invalid, put other
symbol”
UNTIL (Play = “X” OR Play = “O”) AND NOT(Play = SymbolTag)

‘// Store the input in ARRAY after validation


Game[XAxis, YAxis] = Play

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

‘//Call the Function to check and output the winner.


IF Result(Play) = “won” THEN
PRINT “Player with ”, Play, “-symbol has won the game.”
‘//Stop the game, if function returns “won” by exiting loop.
EXIT FOR
END IF
NEXT Move

‘// PROCEDURE to output the current status of the game board


PROCEDURE DisplayBoard
FOR Row=1 TO 3
RowData = “”
FOR Col=1 TO 3
IF RowData < > “” THEN RowData = RowData + “ ”
RowData = RowData + Game(Row, Col)
NEXT Col
PRINT RowData
NEXT Row
END PROCEDURE

'// 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

‘// Check for same mark in straight column


FOR Col = 1 TO 3
FOR Row=1 TO 3
IF Game[Row, Col] = ParameterMark THEN
InColumn = "True"
ELSE
InColumn = "False"
END IF
IF InColumn = "False" THEN EXIT FOR

Page - 9
NEXT Row
IF InColumn = "True" THEN EXIT FOR
NEXT Col

'// Check for same mark in diagonal-1 (left to right)


FOR D1 = 1 TO 3
IF Game[D1, D1] = ParameterMark THEN
InD1 = "True"
ELSE
InD1 = "False"
END IF
IF InD1 = "False" THEN EXIT FOR
NEXT D1

'// Check for same mark in diagonal-2 (right to left)


D2Col = 3
FOR D2 = 1 TO 3
IF Game[D2, D2Col] = ParameterMark THEN
InD2 = "True"
ELSE
InD2 = "False"
END IF
D2Col = D2Col - 1
IF InD2 = "False" THEN EXIT FOR
NEXT D2

IF (InRow = "True" OR InColumn = "True" OR InD1 = "True"


OR InD2 = "True") THEN
'// RETURNS the parameter value “won”
RETURN "won"
ENDIF
END FUNCTION

........................................................................................................ [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.

Write a program using pseudocode, which :


• input and store the name of the patients in 1D array PName[ ]
• input and store the temperature of each patient in 2D array
Temp[.] after every 30 minutes for a day
• at the end of the day -
→ calculate and output the highest, lowest and average
temperature of each patient with their name
→ output the number of times the temperature of each patient is
out of normal range between 97 and 100 (inclusive)
→ calculate and output the number of patients whose temperature
were normal within the range.

................................................................................................................
DECLARE PName : ARRAY[1:20] OF STRING
DECLARE Temp : ARRAY[1:20, 1:48] OF REAL

FOR Patient = 1 TO 20

INPUT “Enter the name of patient : ”, PName[Patient]

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.”

IF NoAbTemp = 0 THEN NormTempPat = NormTempPat + 1

Page - 11
NEXT Patient

OUTPUT “Number of patients with normal temperature is ”, NormTempPat

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

........................................................................................................ [15]

Q. A hospital stores the name of the patients in a 1D array PatientName[ ]


and their temperature in a 2D array PatientTemp [.] recorded 3-times a
day (morning, afternoon and night).

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.

The temperature status of patient is considered as follows:


Status Temperature
Above normal greater than 100
Normal temperature greater than or equal to 97
Below normal less than 97

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

IF DayTime < 1 OR DayTime > 3 THEN


OUTPUT “Invalid option, re-enter your choice.”
ENDIF
UNTIL DayTime >=1 AND DayTime < =3

‘// 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

‘// Inner-loop to repeat for each patient


FOR Patient = 1 TO NumPatients
IF PatientTemp[Patient, DayTime] > AboveNormal THEN
TempStatus  “above normal”
NoAboveTemp  NoAboveTemp + 1
ELSE
IF PatientTemp[Patient, DayTime] >= Normal THEN
TempStatus  “normal”
NoNormalTemp  NoNormalTemp + 1
ELSE
IF PatientTemp[Patient, DayTime] < Normal THEN
TempStatus  “below normal”
NoBelowTemp  NoBelowTemp + 1
ENDIF
ENDIF
ENDIF

TotalTemp  TotalTemp + PatientTemp[Patient, DayTime]

‘// Output each patient’s details


OUTPUT “Name of patient = ”, PatientName[Patient]
OUTPUT “Patient temperature = ”, PatientTemp[Patient, DayTime]
OUTPUT “Patient temperature status is ”, TempStatus

NEXT Patient

‘// Calculate average temperature of the patients

Page - 13
AverageTemp  TotalTemp / NumPatients

‘// Output details of patients for chosen interval of time


OUTPUT “Number of patients above normal is ”, NoAboveTemp
OUTPUT “Number of patients with normal temperature ”, NoNormalTemp
OUTPUT “Number of patients below normal is ”, NoBelowTemp
OUTPUT “Average temperature of the patients is ”, AverageTemp

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

Q. A mobile company has introduced a new feature in their mobile phones


where customers can earn points by completing certain tasks. The
company has stored the names of all its customers in a 1D array
CustomerName[ ]. The 2D array CustomerPoints[ ] contains the points
earned by each customer for each task they have completed.
The position of each customer’s data in the two arrays is the same, for
example, the customer in position 10 in CustomerName[ ] and
CustomerPoints[ ] is the same.
The variable CustomerCount contains the number of customers in the
company. The variable TaskCount contains the number of tasks that can
be completed to earn points. All the customers have the option to complete
the same number of tasks.
The arrays and variable have already been set up and the data stored.
Customers are awarded a reward based on the total number of points they
have earned.

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

// Initialise variables to count customers for different rewards


NoGold = 0
NoSilver = 0
NoBronze = 0
NoReward = 0

// Outer loop to repeat for each customer


FOR Customer = 1 TO CustomerCount

// Initialise variable to calculate total points for each customer


CTotal = 0

// Inner loop to repeat for each task


FOR Task = 1 TO TaskCount

// Calculate total points of each customer


CTotal = CTotal + CustomerPoints[Customer, Task]
NEXT Task

// Calculate and round the average points


AveragePoints = ROUND(CTotal / TaskCount)

// Check and store the reward and its number of customers


IF AveragePoints >= Gold THEN
Reward = “Gold”
NoGold = NoGold + 1
ENDIF
IF AveragePoints < Gold AND AveragePoints >= Silver THEN
Reward = “Silver”
NoSilver = NoSilver + 1
ENDIF
IF AveragePoints < Silver AND AveragePoints >= Bronze THEN
Reward = “Bronze”
NoBronze = NoBronze + 1
ENDIF
IF AveragePoints < Bronze THEN
Reward = “no reward”
NoReward = NoReward + 1
ENDIF
// Output each customers reward detials
OUTPUT “Name of customer : ”, CustomerName[Customer]

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

Write a program that meets the following requirements :


• calculates the combined total mark for each student for all their subjects
• calculates the average mark for each student for all their subjects, rounded to the
nearest whole number
• outputs for each student
→ name
→ combined total mark
→ average mark
→ grade awarded
• calculates, stores and outputs the number of distinctions, merits, passes and fails for
the whole class.
You must use pseudocode or program code and add comment to explain how your code
works.
You do not need to initialise the data in the array.

.............................................................................................................................................................................
// Initialise constants for different grade awarded
CONSTANT Distinction = 70

Page - 16
CONSTANT Merit = 55
CONSTANT Pass = 40

// Initialise variables to count the number of students with different


grades
NoDistinction = 0
NoMerit = 0
NoPass = 0
NoFail = 0

// Outer loop to repeat for each student of class


FOR Std = 1 TO ClassSize
StdTotal = 0 // Initialise variable to calculate total mark of each
student
// Inner loop to repeat for each subject
FOR Sub = 1 TO SubjectNo
// Calculate total mark of each student
StdTotal = StdTotal + StudentMark[Std, Sub]
NEXT Sub
// Calculate and round the average mark to its nearest whole
number
AverageMark = ROUND(StdTotal/SubjectNo)
// Check and store the grade awarded
IF AverageMark >= Distinction THEN
GradeAwarded = “Distinction”
NoDistinction = NoDistinction + 1
ELSE
IF AverageMark >= Merit THEN
GradeAwarded = “Merit”
NoMerit = NoMerit + 1
ELSE
IF AverageMark >= Pass THEN
GradeAwarded = “Pass”
NoPass = NoPass + 1
ELSE
GradeAwarded = “Fail”
NoFail = NoFail + 1
ENDIF
ENDIF
ENDIF
// Output the student's name, total mark, average and grade
awarded.
OUTPUT “Name : ”, StudentName[Std]
OUTPUT “Total mark : ”, StdTotal
OUTPUT “Average mark : ”, AverageMark
OUTPUT “Grade awarded : ”, GradeAwarded
NEXT Std

‘// Output the overall number of students awarded with different


grade
OUTPUT “Number of Distinctions = ”, NoDistinction

Page - 17
OUTPUT “Number of Merits = ”, NoMerit
OUTPUT “Number of Passes = ”, NoPass
OUTPUT “Number of Fails = ”, NoFail

................................................................................................................................................................... [15]

Page - 18

You might also like