0% found this document useful (0 votes)
10 views

Computer Science P2 Unsolved 2023-2024

Computer science p2

Uploaded by

kate.ki.7869
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
10 views

Computer Science P2 Unsolved 2023-2024

Computer science p2

Uploaded by

kate.ki.7869
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 15
COMPUTER SCIENCE Paper 2 Fundamental Problom-solving and Programming Skills You will ni : Insert (onclosed) 9618/21 Dac-2023, Duration « 2 hours READ THESE INSTRUCTIONS FIRST Write your name, student id and grade in the spaces at the top of this page. \Wiite in dark blue or black pen, You may use an HB pencil for any diagrams, graphs or rough working. Do not use staples, paper clips, glue or correction fluid. DO NOT WRITE IN ANY BARCODES, Calculators must not be used in this paper. Answer all questions. No marks will be awarded for using brand names of software packages or hardware. ‘At the end of the examination, fasten all your work securely together. ‘The number of marks is given in brackets { ] at the end of each question or part question. ‘The maximum number of marks is 75 Examiner's Signature: Moderator’s Signature: Invigilator’s Signature: __/ Q.no. | Marks | Obtained a 18 2. 9 2 7 4 2 E 3 6 12. | Mm 8 Total | 75 ee This document consists of 15 printed pages * days ce Meese Oe | Exam Department Beanscanner Refer to the Insort for the list of pseudocode functions and oporators, 41 (a) (I) Algorithms may be expressed using four basic constructs. One construct is soquonce, ‘Complete the following table for two other constructs. Construct Psoudocodo oxample (4) (Ii) Simple algorithms usually consist of input, process and output ‘Complete the table by placing ticks ('/’) in the relevant boxes. Pseudocode statement Input | Process | Output Temp ~ Sensorvalue * Factor WRITEFILE "LogFile.txt", TextLine WRITEFILE "LogFile.txt", MyName & MyTDNumber READFILE "AddressBook. txt", NextLine ‘ “Ting * cel dca AS-C5 9618 Midyeor-2023 P21 bi m Department Banscaner Sy (b) Program variables have values as follows: Val - —_ Title "101 tricks with spaghetti” Version "cr | huthor "Eric Peapod” 2 PackSize 4 = WoightBach 62 Paperback TRUE — | (W) Evaluate each expression in the following tablo, Ian expression is invalid, write ERROR, Expression Evaluates to ] MID(Title, 5, 3) & RIGHT (Author, 3) INT(WeightEach * PackSize) PackSize >= 4 AND WeightEach < 6.2 LEFT (Author, ASC(Version) - 65) RIGHT (Title, (LENGTH(Author) - 6)) (ll) Programming languages support different data types. DI Give an appropriate data type for the following variables from part (b). Varlable Data type Title Version PackSize WeightEach Paperback t AS-CS 9618 Midyear-2023 P21 1o] Beanscinne 4 2.A programmer wants to write a program to calculate the baggage charge for a passenger's airline fight. ‘Two types of ticket are available for a flight: + economy class (coded E) + standard class (coded S) Each ticket type has a baggage weight allowance as shown below. The airline makes a charge if the weight exceeds the allowance, Baggage allowance Charge rate per additional kg Ticket type se Fi ne (ka) s) fe 16 3.50 's 20 5.75 (a) A program flowchart will document the program. The flowchart will contain the folowing statements: ‘Statement filimber ‘Statement 2 Charge = 0 Y INPUT BaggageWeight 3 Charge - ExcessWeight * chargeRate Is ExcessWeight > 0 ? 5 INPUT TicketType « ExcessWeight — Baggageleight - BaggageAllowance r BaggageAllowance ~ 16 af Chargerate - 3.5 9 OUTPUT Charge 10 ChargeRate ~ 5.75 1 BaggageAllowance ~ 20 12 Is TicketType = 'E' ? Complete the flowchart by putting the appropriate statement number in each flowchart symbol. Statement 5 has been done for you. AS-CS 9618 Midyeor-2023 P21 Beanscanner —w4 AS-CS 9618 Midyeor-2023 P21 Beanscanner 6 {b) The program design is to be amended, The value input by the user for the ticket type Is to be validated. Part of the amended flowchart is shown below. No [vos White pseudocode to use a pre-condition loon tor-this Validation 8 AS-C5 9618 Midyear-2023 P21 jéxam Department [} Beanscinne ’ 3. Amobile phone provider has developed an account management program. The program includes a procedure, Aaacredit (). The procedure is 4 and Phonetiun ‘The shown. Ned with two parameters, Tp"lpy fant part of the Kdentifier table and the program Nowchart for the procedure ara as Wdontifior Description Topup Tha amount of credit to ba added | Phonettur STRING | The unique customer phona number Dalance [REAL —_ | Tha current amount of crnat | Multiple - REAL. Tho amount of credit bonus hea the phone number as a parameter and eturna tha currant Getnatancet) |runction | 74 pa A rotuens tha currant SetNalance() | PROCEDURE ‘Set Mutip 1.25 Set Multiple to a ‘Sel Toptip to Topp * Multiple | | Secastncetthonain, Banca + Topp) AS-CS 9618 Midyeor-2023 P21 8 Write pseudocode to implement the procedure AddCredit (). The pseudocode must follow the algorithm represented by the flowchart. Declare any local variables used. . ou)s S AS 2. sesementorth ‘ TDM * Exeter Edad Exam Department CBcamscanner 9 4(a)A 1D array, Directory, of type STRING [s used to store a list of schoo! internal telephone ‘numbers, There are 1000 elements in the array. Each element stores a single data item. The format of each data item is as follows: Nunber is a four-digit numeric string, Nane Is a varlablesength string, For example: "1024Collins Robbie" The following pseudocode is an Initial attempt at defining a procedure Sortcontacts() that will perform a bubble sort on Directory. The array is to be sorted in ascending order of Name. Fill in the gaps to complete the pseudocode. PROCEDURE SortContacts () DECLARE Temp : STRING DECLARE FirstName, SecondName : STRING DECLARE NoSwaps : = DECLARE Boundary, J : INTEGER Boundary + — REPEAT NoSwaps @ TRUE FOR J 170 Boundary ~ FirstName @— .. _——.(Directory(J], LENGTH (Directory(J}) - SecondName € RIGHT (Directory[J + 1], IF FirstName ‘THEN LENGTH(Directory[J + 11) ~ 4) Temp « Directory(J] Directory(J) ¢ Directory ~ Directory[3 + 1] © Temp Noswaps < . . ENDIF ENDFOR Boundary @ Ws UNTIL NoSwaps = TRUE ENDPROCEDURE AS-CS 9618 Midyear-2023 P21 * dapat * Department cs 10 (b) The pseudocode contains a mechanism designed to make this an efficient bubble sort. —~ Describe the mechanism and explain why it may be considered to be efficient. AS-CS 9618 Midyear-2023 P21 Exam Department einen | CBcamscanner Y aay ’ rte 5 The following Is a function design in pseudocode. Line numbers are given for reference only. o1 02 03 04 os 06 07 08 o9 10 11. 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 AS-C5 9618 Midyear-2023 P21 FUNCTION StringClean(InString : STRING) RETURNS STRING DECLARE NextChar : CHAR DECLARE OutString : STRING DECLARE Counter : INTEGER DECLARE MyString : STRING Outstring + "" FOR Counter « 1 TO LENGTH(InString) NextChar «- MID(InString, Counter, 1) NextChar «- LCASE(NextChar) IF (NextChar >= 'a') AND (NextChar <= 'z') THEN OutString < OutString & NextChar ENDIF ENDFOR RETURN OutString ENDFUNCTION 2 Study the function StringClean (). Identify the features of the function in the following table. Feature Answer Aline number containing an example of an assignment statement A line number containing the start of a repetition block A line number containing the end of a repetition block Aline number containing the start of a selection statement |The number ofparametersofthemiDuncion The Boolean operator used The number of local variables The number of function calls from within StringClean() resulting from the call: NewString — StringClean ("Me") The number of a line containing an unnecessary statement ( ? AS-C5 9618 Midyear-2023 P21 ee m Department Beanscanser B 6 (a) An algorithm includes a number of complex calculations. A programmer is writing a program to implement the algorithm and decides to use library routines to provide part ofthe solution State three possible benefits of using library routines in the development ofthe program. @ (b) The following pseudocode is part of a program that stores names and test marks for use in other parts of the program. DECLARE Namel, Name2, Name3 : STRING DECLARE Marki, Mark2, Mark3 : INTEGER INPUT Namel INPU? Markl INPUT Name2 INPUT Mark2 INPUT Name3 INPUT Mark3 (i) The pseudocode needs to be changed to allow for data to be stored for up to 30 students. Explain why it would be good practice to use arrays to store the data, St 3 AS-CS 9618 Midyeor-2023 P21 Stee Pence bein [sam Department Banscaner cy (Il) The following pseudocode statement includes array references: OUTPUT "Student ", Name[Count], " scored ", Mark{Count) State the purpose of the varlable Count and giva its data type. Purpose . . Data type. eR (2) (c) The pseudocode statements in the following table may contain errors. State the error in each case or write 'NO ERROR’ if the statement contains no error. Assume that any variables used are of the correct type for the given function. Statement Error IF EMPTY — “" THEN Status — 1S_NuM(-23.4) X — STR_TO_NUM("37") +5 ¥ — STR_TO_NUM("37" + - . as (i eZ AS-C5.9618 Midyeor-2023 P21 ane i Jxam Department 200 Banscaner 15 7 A sports club maintains a record of the mail address of each of its members, The details are stored In a text fle, Emai10etaiis. txt. The format of each line of the toxt file Is a8 follows: + Menbershipttumber is a four-ch: cler string of numerals, + EmailAddress Is a variable-length string. ‘Membership of the club has increased and a four-character membership number is no longer adequate, A procedure, HakeNewF Le, Is required to perform the following actions: 1, Create a new file, Newemai1detaiis. txt. 2. Read aline from file Emai1Details.txt 3. Extend Menbershiptumber by adding two leading zero digits (for example, "1234" becomes "001234") 4, Write the new line to fle NewEmai1Detaiis.txt 5, Repeat steps 2 to 4 forall lines in the original file. Write pseudocode for the procedure MakeNewFile. AS-C5 9618 Midyeor-2023 P21 [iEsam Department CBeamscanner

You might also like