Question 5 2018 · October-November · Paper 21 · 10 marks
Reveal official mark-scheme answer
Official answer for Question 5
Show text version of question
Question 5
CarStatus.txt, stores the data.
The format of each line of the text file is as follows:
<Time>,<Amount of fuel used>,<Distance travelled>
Data items are separated by a ‘,’ (comma) character.
The program contains the following functions.
Function Description Returns a string representing the current time. May return NULL under GetTime() certain circumstances. GetFuel() Returns a string representing the amount of fuel used GetDistance() Returns a string representing the distance travelled
The function SaveStatus() will:
- obtain the time, fuel used and distance data using the appropriate function calls
- check that the time string is not NULL
- return FALSE if the current time string remains NULL after three attempts
- form the text string, write it to the file and return TRUE
The file should not be open longer than necessary.
Question 15
Write pseudocode for the SaveStatus() function.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
....................................................................................................................................................[10]
Question 16
Appendix Built-in functions (pseudocode) In each function, if the function call is not properly formed, the function returns an error.
MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns string "BCD"
LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of ThisString
Example: LENGTH("Happy Days") returns 10
LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns string "ABC"
RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns string "FGH"
TO_UPPER(ThisString : STRING) RETURNS STRING returns a string formed by converting all lower case alphabetic characters of ThisString to upper case. Other characters will be unchanged.
Example: TO_UPPER("Disk Error 27") returns "DISK ERROR 27"
INT(x : REAL) RETURNS INTEGER returns the integer part of x
Example: INT(27.5415) returns 27
ASC(ThisChar : CHAR) RETURNS INTEGER returns the ASCII value of character ThisChar
Example: ASC('A') returns 65
Operators (pseudocode)
Operator Description Concatenates (joins) two strings & Example: "Summer" & " " & "Pudding" produces "Summer Pudding" Performs a logical AND on two Boolean values AND Example: TRUE AND FALSE produces FALSE Performs a logical OR on two Boolean values OR Example: TRUE OR FALSE produces TRUE
Why this question appears here
99% assigned-topic match · Data types and structures › Data types and records
Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.
Permanent source page: Educate A Change · From 9608_w18_qp_21.pdf
