Ict133 Jan 2022 Toa
Ict133 Jan 2022 Toa
Structured Programming
Thursday, 19 May 2022 1:00 pm – 3:00 pm
____________________________________________________________________________________
INSTRUCTIONS TO STUDENTS:
1. This Timed Online Assignment (TOA) contains FOUR (4) questions and comprises
SIX (6) pages (including cover page).
3. If you have any queries about a question, or believe there is an error in the question,
briefly explain your understanding and assumptions about that question before
attempting it.
4. You MUST submit your answers via Canvas (similar to TMA submission) at the
end time of this TOA (as stated on this cover page). The 15 minutes grace period as
shown on Canvas is strictly meant for technical issues encountered during
submission. Thereafter, you will not be able to submit your answers and you will be
considered as having withdrawn from the course. No appeal will be allowed.
5. You are to include the following particulars in your submission: TOA Course Code,
Your Name, and SUSS PI No. Name your submission file as
TOACourseCode_FullName_StudentPI. Use underscore and NOT Space. Example:
TOAXYZ_RaphaelLee_T1923161 (omit D/O, S/O).
6. Your submission should consist of only one file and must not exceed 500MB in size.
The file must be a Microsoft Word file saved in .doc or .docx format. All answers are
to be typed. Flowcharts and graphs may be scanned or photographed and embedded
in the Word file provided it does not exceed the file size limit of 500MB. Images of
handwritten answers will not be marked.
8. The University takes plagiarism and collusion seriously, and your Turnitin report will
be examined thoroughly as part of the marking process.
____________________________________________________________________________________
You can use ONLY built-in functions and packages covered in the module, e.g., math,
random. You can use ONLY built-in types. Do not write classes.
Question 1
(a) Given a string, display valid if the length of the string is 8 letters, of which the
first 3 must be uppercase letters, followed by 4 digits and the last letter ends with
one of the letters ‘S’, ‘X’, or ‘Z’. Otherwise, display invalid.
(10 marks)
(b) Given a positive integer n less than 10, display a n by n multiplication table. For
example, if n is 5, display the following:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
(15 marks)
Question 2
A car park has a grace period of 10 minutes, after which the charge is $1.50 for the first
hour or part thereof of parking and 2 cents per minute after the first hour. The maximum
charge however, is $5.00.
A program continually reads in a float value representing a duration and displays the car
park charge. Input is a value in the format h:mm, where h is the hour and mm the minutes.
Assume input will be in the correct format. The program ends when user presses just the
<Enter> key at the prompt.
(c) Write the program. Make use of the functions in Q2(a) and (b).
(10 marks)
Question 3
Solve computational problems using structured programming and apply data structures
in problem solving.
2 x 1.5 = 3.0
4 x 0.5 = 2.0
1 x 2.5 = 2.5
3 x 2.0 = 6.0
4 items.
Total price $13.50
(15 marks)
Enter num: 5
[5]
Enter num: 9
[5,9]
Enter num: 5
[5,5,9]
Enter num: 2
[2,5,5,9]
Enter num: 7
[2,5,5,7,9]
(10 marks)
Question 4
Solve computational problems using structured programming, apply data structures and
file handling.
A media screening room has rows of seats. The rows are labelled A, B, C, etc and seat
numbers 1, 2, 3 etc. A seating plan for 3 rows, 4 seats per row is as follows:
A O X O X
B O O O X
C O X O O
1 2 3 4
Empty seats are marked with O, while those occupied marked with X.
(a) A seating plan with some seats occupied is stored in a file, seating.txt as
follows:
A,O,X,O,X
B,O,O,O,X
C,O,X,O,O
Write a code segment to read the file and store the seating plan in a dictionary.
The dictionary structure after reading the file should be as follows:
seatingPlan = {'A':['O','X','O','X'], 'B':['O','O','O','X'],
'C':['O','X','O','O'] }
(8 marks)
(c) Write a code segment to allow for booking of seats. To book seats, the user inputs
a seat by row and seat number, followed by number of seats to book. Assume all
input to be valid. If the seats are available, update the dictionary and display a
message. The following sample shows the scenarios to consider:
Sample 2
Enter seat no: C1
Enter number of seats to book: 2 Not available because C2 is
Not available occupied.
Sample 3
Enter seat no: C3
Enter number of seats to book: 5 Not available because of
Not available insufficient seats.
(9 marks)