Nothing Special   »   [go: up one dir, main page]

0478 22 Pre 2022 Pseudocode For All Tasks

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

TASK 1 – FOR EXAM

PRINT "Please enter the day (1 to 14) :"


INPUT Day
IsSpaceAllotted <- FALSE
REPEAT
CountSpaces <- 1
IF ParkingSpaces[CountSpaces][Day] == "0" AND IsSpaceAllotted == FALSE
THEN
PRINT "Please enter your Name :"
INPUT Name
PRINT "Please enter your LicenseNumber :"
INPUT LicenseNumber
ParkingSpaces[CountSpaces][Day] <- Name & "," & LicenseNumber
AllottedSpaceNo <- CountSpaces
IsSpaceAllotted <- TRUE
ENDIF
UNTIL IsSpaceAllotted

IF IsSpaceAllotted THEN
PRINT "Your alloted parking space number is :" & CountSpaces
ELSE
PRINT "Sorry, No free space available for your selected day"
ENDIF
TASK 2 – FOR EXAM

PRINT "Please enter the day (1 to 14) :"


INPUT Day

IsSpaceAllotted <- FALSE


REPEAT
CountSpaces <- 1
PRINT "Do you need an accessible space (Y/N):"
INPUT NeedAccessibleSpace

IF ParkingSpaces[CountSpaces][Day] == "0"
AND IsSpaceAllotted == FALSE
THEN
PRINT "Please enter your Name :"
INPUT Name
PRINT "Please enter your LicenseNumber :"
INPUT LicenseNumber

IF NeedAccessibleSpace == 'Y' THEN


ParkingSpaces[CountSpaces][Day] <- Name & "," & LicenseNumber
AllottedSpaceNo <- CountSpaces
IsSpaceAllotted <- TRUE
ELSE
IF CountSpaces > 5 THEN
ParkingSpaces[CountSpaces][Day] <- Name & "," & LicenseNumber
AllottedSpaceNo <- CountSpaces
IsSpaceAllotted <- TRUE
ENDIF
ENDIF
CountSpaces <- CountSpaces + 1
UNTIL IsSpaceAllotted

IF IsSpaceAllotted THEN
PRINT "Your alloted parking space number is :" & CountSpaces
ELSE
PRINT "Sorry, No free space available for your selected day"
ENDIF
TASK 3 – FOR EXAM

REPEAT
CountStats <- 1
PRINT "Please select the below statistics (1 to 6) :"
PRINT "1. The number of accessible spaces used on any of the 14 days."
PRINT "2. The number of general spaces used on any of the 14 days."
PRINT "3. The total number of spaces used on any of the 14 days."
PRINT "4. The number of accessible spaces used in the whole 14-day period."
PRINT "5. The number of general spaces used in the whole 14-day period."
PRINT "6. The total number of spaces used in the whole 14-day period."
INPUT Statistics
PRINT "Please enter a day (1 to 14) :"
INPUT Day

IF Statistics > 0 AND Statistics < 7 THEN


CASE OF Statistics
1:
Count <- 0
FOR CountSpaces <- 1 to 5
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The number of accessible parking spaces used : " & Count

2:
Count <- 0
FOR CountSpaces <- 6 to 20
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The number of general parking spaces used : " & Count
3:
Count <- 0
FOR CountSpaces <- 1 to 20
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The total number of parking spaces used : " & Count
4:
Count <- 0
FOR CountSpaces <- 1 to 5
FOR CountDays <- 1 to 14
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The total number of accessible spaces used in the whole 14-day period.
" & Count
5:
Count <- 0
FOR CountSpaces <- 6 to 20
FOR CountDays <- 1 to 14
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The number of general spaces used in the whole 14-day period." &
Count
6:
Count <- 0
FOR CountSpaces <- 1 to 20
FOR CountDays <- 1 to 14
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The total number of spaces used in the whole 14-day period." & Count
ELSE
PRINT "Please enter a valid number from 1 to 6"
ENDIF
CountStats <- CountStats + 1
UNTIL Statistics > 0 AND Statistics < 7
COMPLETE PSEUDOCODE

DECLARE MaxParkingSpace : INTEGER


DECLARE MaxNumberOfDays : INTEGER
DECLARE GeneralSpaceSix : INTEGER
DECLARE Day : INTEGER
DECLARE CountSpaces : INTEGER
DECLARE CountDays : INTEGER
DECLARE CountStats : INTEGER
DECLARE Count : INTEGER
DECLARE Name : STRING
DECLARE LicenseNumber : STRING
DECLARE AllottedSpaceNo : INTEGER
DECLARE Statistics : INTEGER
DECLARE IsSpaceAllotted : BOOLEAN
DECLARE IsSpaceAllotted : BOOLEAN
DECLARE NeedAccessibleSpace : CHAR
DECLARE ParkingSpaces : ARRAY[1:20,1:14] OF STRING

//BELOW ARE THE CONSTANTS


MaxParkingSpace = 20
MaxNumberOfDays = 14
GeneralSpaceSix = 6

//storing empty values in the arrays


FOR CountSpaces <- 1 to MaxParkingSpace
FOR CountDays <- 1 to MaxNumberOfDays
ParkingSpaces[CountSpaces][CountDays] <- "0"
NEXT CountDays
NEXT CountSpaces

//getting inputs
// Below code is the validation for Day input
REPEAT
PRINT "Please enter the day (1 to 14) :"
INPUT Day
IF Day <1 AND Day >14 THEN
PRINT "Please enter a valid day from 1 to 14"
ENDIF
UNTIL Day > 0 AND Day < 15

IsSpaceAllotted <- FALSE


REPEAT
CountSpaces <- 1
PRINT "Do you need an accessible space (Y/N):"
INPUT NeedAccessibleSpace

IF ParkingSpaces[CountSpaces][Day] == "0"
AND IsSpaceAllotted == FALSE
THEN
PRINT "Please enter your Name :"
INPUT Name
PRINT "Please enter your LicenseNumber :"
INPUT LicenseNumber

IF NeedAccessibleSpace == 'Y' THEN


ParkingSpaces[CountSpaces][Day] <- Name & "," & LicenseNumber
AllottedSpaceNo <- CountSpaces
IsSpaceAllotted <- TRUE
ELSE
IF CountSpaces > 5 THEN
ParkingSpaces[CountSpaces][Day] <- Name & "," & LicenseNumber
AllottedSpaceNo <- CountSpaces
IsSpaceAllotted <- TRUE
ENDIF
ENDIF
CountSpaces <- CountSpaces + 1
UNTIL IsSpaceAllotted

IF IsSpaceAllotted THEN
PRINT "Your alloted parking space number is :" & CountSpaces
ELSE
PRINT "Sorry, No free space available for your selected day"
ENDIF

REPEAT
CountStats <- 1
PRINT "Please select the below statistics (1 to 6) :"
PRINT "1. The number of accessible spaces used on any of the 14 days."
PRINT "2. The number of general spaces used on any of the 14 days."
PRINT "3. The total number of spaces used on any of the 14 days."
PRINT "4. The number of accessible spaces used in the whole 14-day period."
PRINT "5. The number of general spaces used in the whole 14-day period."
PRINT "6. The total number of spaces used in the whole 14-day period."
INPUT Statistics
PRINT "Please enter a day (1 to 14) :"
INPUT Day

IF Statistics > 0 AND Statistics < 7 THEN


CASE OF Statistics
1:
Count <- 0
FOR CountSpaces <- 1 to 5
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The number of accessible parking spaces used : " & Count
2:
Count <- 0
FOR CountSpaces <- 6 to 20
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The number of general parking spaces used : " & Count
3:
Count <- 0
FOR CountSpaces <- 1 to 20
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The total number of parking spaces used : " & Count
4:
Count <- 0
FOR CountSpaces <- 1 to 5
FOR CountDays <- 1 to 14
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "Total number of accessible spaces in the 14-day period. " & Count
5:
Count <- 0
FOR CountSpaces <- 6 to 20
FOR CountDays <- 1 to 14
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The number of general spaces used in the 14-day period." & Count
6:
Count <- 0
FOR CountSpaces <- 1 to 20
FOR CountDays <- 1 to 14
IF ParkingSpaces[CountSpaces][Day] <> "0" THEN
Count <- Count + 1
ENDIF
NEXT CountSpaces
PRINT "The total number of spaces used in the whole 14-day period." & Count
ELSE
PRINT "Please enter a valid number from 1 to 6"
ENDIF
CountStats <- CountStats + 1
UNTIL Statistics > 0 AND Statistics < 7

You might also like