TopicWise 2.3 Question

Embed Size (px)

Citation preview

  • 7/25/2019 TopicWise 2.3 Question

    1/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 1 of 30

    Past Papers Answers:May/June 2000Oct/NOV 2000May/June 2001

    Oct/NOV 2001May/June 2002Oct/NOV 20024. An examination centre holds data about the candidates at that centre.

    The data held is4 digit candidate numbercandidate namegenderdate of birthnumber of subjects entered.(a) If there are 200 candidates entered by the centre, calculate the expected size of the file.

    Show your working and give your answer in suitable units. [6]

    7. (a) Describe how an array is initialised in the memory of a computer.

    - Size of array calculated Location of array decided

    - according to data type/size Locations reserved

    Array named in look up table. Size of array stored in table Lower bound of array stored in table- Upper bound of array stored in table- Data type stored in table

    Address of first element stored in table(1 per Max 4)

    (b) Describe how an array may be searched serially to find a specific data item.

    - Index set to 0- Array(index) searched

    if = Item then found Else increment index and repeat

  • 7/25/2019 TopicWise 2.3 Question

    2/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 2 of 30

    Until found or error report.(1 per -, max 4)

    May/June 2003Oct/NOV 20035. Details of students in a college are stored in a computer system. Among data items stored are

    _ the student's name_ the student's address_ the student's date of birth_ the mark obtained in the last mathematics examination_ whether or not the student wants to go on a college trip_ how much the student owes towards the cost of the trip.(b) State data types that are suitable for each of the other pieces of data.

    - Date/integer Integer- Boolean/yes or no- Currency/floating pt/real/integer (4)

    May/June 20044. (b) A stock file in a warehouse has the following fields in each record.

    Name of item. Date of last delivery. Price of item. Whether or not an order is outstanding. Number of that item left in stock.

    (ii) Given that there are approximately 10000 different items in the warehouse,estimate the size of the stock file. You should clearly show all the stages in thecalculation.

    Oct/NOV 2004May/June 2005Oct/NOV 2005May/June 2006A small business has one shop. It specialises in taking portrait photographs for customers.Details of customers are stored on paper.It is decided to buy a stand-alone computer and use it to store customer records in a file.7. The following fields are to be stored. Customer name (to allow customer to be addressed properly when contacted) Customer telephone number (so that customer can be contacted when their order hasbeen completed)

  • 7/25/2019 TopicWise 2.3 Question

    3/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 3 of 30

    Date of original commission (so that customers are not kept waiting too long) Whether or not the order has been paid for.

    (a) State a suitable data type for each of the four fields.

    - text/character/string- text/character/string/alphanumeric

    - date/Integer Boolean - [4]

    (b) It is assumed that there will never be more than 1000 records.Estimate the total size of the file needed for these records.

    - 10-30- 5-20

    - 2,4,6,8- 1- (Total = 18-59)- + 10%- * 1000

    - Div 1024 (1000)- Answer (19-64) Kb(1 per unbracketed line, max 4) [4]

    Oct/NOV 2006May/June 2007Oct/NOV 2007May/June 2008Oct/NOV 2008May/June 20092. A stock file in a company has records of all the different items held in stock. The records each

    hold a number of fields: the name of the item in stock

    description of the item cost whether or not in stock number in stock

    (a) (i) State a suitable data type for each field.

    - Name: Text/String/alpha/alphanumeric- Description: Text/String/alpha/alphanumeric- Cost: Currency/integer/real/float- Whether: Boolean- Number: Integer- (1 for first three, 1 for last 2) [2]

    (ii) If there are 1000 items in stock, estimate the size of the stock file. (Show howyou worked out your answer.)

    Field Sizes: 10 5050 250

    4 81

  • 7/25/2019 TopicWise 2.3 Question

    4/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 4 of 30

    1 4Total 66 313 bytes (1)

    - (1) for showing that the field sizes should be added up- Multiply Total by 1000 (1) = 66000 to 313000 bytes- Add extra (10%) for overheads (1) = 72600 to 344300 bytes

    - Convert to sensible unit (1024) (1) = 70.9Kb to 344.3Kb.- (5 possible mark points, max 4) [4]Oct/NOV 2009. P11Oct/NOV 2009. P123. A library stores details of members on the member file.

    (d) The member file contains up to 10,000 records. The estimated size of each record is 250bytes.

    - Multiply 250 and 10000 - Add 10%- Signify that should divide by 1024...- Twice- Answer between 2.35 and 2.75

    - M bytes(1 per -, max 5) [5]

    Oct/NOV 2009. P13May/June 2010. P11May/June 2010. P12May/June 2010. P13Oct/NOV 2010. P113. (a) A school information system stores data about each student in the school.

    For each of the following data items, state the most suitable data type. Justify your choice.(i) Home telephone number

    - Text/alpha/string/alphanumeric (not character)

    - These are sets of characters, not numbers/no calculation involved with them [2]- (second mark depends on the first)

    (ii) Number of subjects studied

    - Integer/byte - Must be whole number [2]

    (iii) Whether or not the student is going on the school trip

    - Boolean (accept yes/no, true/false, 0/1)- Only two possible values (yes/no) [2]Oct/NOV 2010. P12Oct/NOV 2010. P133. (a) A shop's stock control system stores data about the goods in the shop.

    For each of the following data items, state the most suitable data type. Justify your choice.(i) Bar code number [2]

    - Text/alpha/string/alphanumeric- These are sets of characters not numbers [2]

    (ii) Price in dollars [2]

  • 7/25/2019 TopicWise 2.3 Question

    5/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 5 of 30

    - Real/Currency- There will be a fractional part to the value [2]

    (iii) Whether on order or not [2]

    - Boolean- Only two possible values (yes/no) [2]

    (b) Using the example of the shop stock control system, explain how fields, files and recordsare related.

    - Files (all the data on the stock) comprise...- Records (all the data about a single item of stock) comprise...- Fields (individual pieces of data in a record e.g. Price)- (1 mark only for hierarchy given without context) [3]

    May/June 2011. P11

    May/June 2011. P12May/June 2011. P13

    Oct/NOV 2011 P211 Ahmed is writing a program to record the data of members of the school football squad.

    (f) Ahmed needs to store more information about the players. He creates a recordstructure that contains PlayerID (a whole number between 1 and 50), Sex (m or f),PlayerName, Position (f, d or g), and DateOfBirth.Complete the table.

    [10]

    (f)

  • 7/25/2019 TopicWise 2.3 Question

    6/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 6 of 30

    1 mark per cell [10]

    Oct/NOV 2011 P222 Ahmed is writing a program to record the data of members of the school football squad.

    The input data will be validated. One input is the number of years a member has played forthe team. This will be 0, 1 or 2.

    (e) Ahmed thinks it will be a good idea to allow only five attempts at getting the input data

    correct. If it is not a valid entry after five attempts, then a message 'Please check which

    values are allowed' should be output.

    Modify the flowchart to include this additional check.

    [5]

    (e) 1 mark for a counter variable1 mark for correctly initialising counter1 mark for incrementing counter1 mark for correct condition for terminating1 mark for correct output from decision [5]

    (f) Ahmed needs to store more information about the players. He creates a record

  • 7/25/2019 TopicWise 2.3 Question

    7/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 7 of 30

    structure that contains PlayerID (a whole number between 1 and 50), Sex (m or f),

    PlayerName, NumberOfYears and DateOfBirth. Complete the table. [10]

    (f)

    1 mark per cell [10]

    (g) The squad has 30 members. Ahmed stores the records in an array called Squad. To

    calculate how many females there are he designs this pseudocode.NoOfFemales 0

    Index 1

    WHILE Index < 30

    IF Squad[Index].Sex = 'f'

    THEN

    NoOfFemales NoOfFemales + 1

    ENDIF

    Index Index + 1

    ENDWHILE

    This pseudocode will only consider the first 29 records in the array.(i) State the name of this type of error. [1]

    (ii) State the line that needs changing. [1]

    (iii) Rewrite the line to ensure that the pseudocode will consider all 30 records.

    [1]

    (g) (i) -logic (error) [1]

    (h) Write this updated pseudocode using a FOR loop ensuring that it will check all records in

    the array. [3]

  • 7/25/2019 TopicWise 2.3 Question

    8/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 8 of 30

    (h) NoOfFemales0FOR Index1 TO 30IF Squad[Index].Sex = fTHENNoOfFemales NoOfFemales + 1ENDIFENDFOR1 mark for correct FOR loop1 mark for correct content of IF statement and condition1 mark for ENDFOR in correct position or equivalent structure [3]

    Oct/NOV 2011 P23

    2 Ahmed is writing a program to record the data of members of the school football squad.

    The input data will be validated. One input is the number of years a member has played for

    the team. This will be 0, 1 or 2.

    The flowchart for the validation of number of years is shown below.

    (f) Ahmed needs to store more information about the players. He creates a record

    structure that contains PlayerID (a whole number between 1 and 50), Sex (m or f),

    PlayerName, NumberOfYears and DateOfBirth. Complete the table. [10]

    (f)

  • 7/25/2019 TopicWise 2.3 Question

    9/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 9 of 30

    1 mark per cell [10]

    (g) The squad has 30 members. Ahmed stores the records in an array called Squad. To

    calculate how many females there are he designs this pseudocode.

    NoOfFemales 0

    Index

    1WHILE Index < 30

    IF Squad[Index].Sex = 'f'

    THEN

    NoOfFemales NoOfFemales + 1

    ENDIF

    Index Index + 1

    ENDWHILE

    This pseudocode will only consider the first 29 records in the array.

    (i) State the name of this type of error. [1]

    (ii) State the line that needs changing. [1]

    (iii) Rewrite the line to ensure that the pseudocode will consider all 30 records.

    [1]

    (g) (i) -logic (error) [1]

  • 7/25/2019 TopicWise 2.3 Question

    10/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 10 of 30

    (h) Write this updated pseudocode using a FOR loop ensuring that it will check all records in

    the array. [3]

    (h) Gtotal0FOR Index1 TO 45IF Club[Index].Position = G

    THENGtotal Gtotal + 1ENDIFENDFOR1 mark for correct FOR loop1 mark for correct content of IF statement and condition1 mark for ENDFOR in correct position or equivalent structure [3]

    May/June 2012. P21/221 Anna wants to find out about her fellow students reading habits. It will be part of her

    Literature coursework.She will ask questions online, so starts by designing a screen layout. The first fourquestions will ask for:

    students first name date of birth type of book they prefer (printed, audio-book or e-book) whether student reads novels (yes/no)(c) The responses from each student will be stored as a record consisting of the following

    fields: FirstName DateOfBirth BookType ReadsNovelsComplete the following table. Only a single value should be given for the Field Size.

    [8](c)

    [8]

  • 7/25/2019 TopicWise 2.3 Question

    11/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 11 of 30

    (f) The records will be held in a serial file.Give three statements from a high-level language that may be used for the filehandling and explain what each does. [6]

    (f) (File handling statement 1 mark; explanation 1 mark) 3e.g. PascalAssignFile(Channel, ExternalFileName); gives the FileName a

    Channel ID through which access can be made

    Reset(Channel); opens existing file

    Write(Channel, Record); writes record to file

    Read (Channel, Record); reads record from file

    Seek (Channel, RecordAddress); goes directly to record at

    specified address

    CloseFile (Channel); closes file

    e.g. VB 2005

    Channel = New FileStream(ExternalFileName,FileMode.Open)

    FileReader = New BinaryReader(Channel)

    NewFile = New FileStream(ExternalFileName, FileMode.Create

    FileWriter = New BinaryWriter (NewFile)Record.Field = FileReader.ReadString()

    Record.Field = FileReader.ReadDecimal()

    Record.Field = FileReader.ReadInt32()

    FileWriter.Write(Field)

    Channel.Close()

    FileReader.Close()

    FileWriter.Close()

    NewFile.Close()

    e.g. C#

    channel = new FileStream(externalFileName,FileMode.Open)

    fileReader = new BinaryReader(channel)

    newFile = new FileStream(externalFileName, fileMode.CreatefileWriter = new BinaryWriter (newFile)

    record.Field = FileReader.ReadString()

    record.Field = FileReader.ReadDecimal()

    record.Field = FileReader.ReadInt32()

    fileWriter.Write(field)

    channel.Close()

    fileReader.Close()

    fileWriter.Close()

    newFile.Close() [6]

    2 Philipe is trying different ways of designing the process of entering data into an array.

    He declares a variable called ArraySize and sets it to 3.He declares an array Number[ArraySize].

    He then writes the following pseudocode.Element 1

    WHILE Element < ArraySize DO

    INPUT Number[Element]

    Element Element + 1

    ENDWHILE

  • 7/25/2019 TopicWise 2.3 Question

    12/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 12 of 30

    (d) Philipe wants to increase the size of the array to 500. This is too large to check with atrace table.Describe how you would check that the logic of the pseudocode is correct for 500iterations. [3]

    (d) check starting conditioncheck state at iteration 499check state at iteration 500check state at iteration 501 [Max 3]

    May/June 2012. P23

    1 Anna wants to find out about her fellow students' sporting activities. It will be part of herSports Studies coursework.She will ask questions online, so starts by designing a screen layout. The first fourquestions will ask for: student's first name age (16,17,18 or 19) favourite sport whether student is a member of a sports club (yes/no)

    (c) Several of the students are visually impaired.Describe the design issues that Anna should consider to ensure these students cananswer the questions online. [2]

    (c) possibility of making fonts larger incorporating sound changing colours [2]

    (f) The records will be held in a direct access file.Give four statements from a high-level programming language that may be used for thefile handling and explain what each does. [8]

    (f) (File handling statement 1 mark; explanation 1 mark) 4e.g. PascalAssignFile(Channel, ExternalFileName); gives the FileName a

    Channel ID through which access can be madeReset(Channel); opens existing fileWrite(Channel, Record); writes record to fileRead (Channel, Record); reads record from fileSeek (Channel, RecordAddress); goes directly to record atspecified addressCloseFile (Channel); closes filee.g. VB 2005Channel = New FileStream(ExternalFileName,FileMode.Open)FileReader = New BinaryReader(Channel)NewFile = New FileStream(ExternalFileName, FileMode.CreateFileWriter = New BinaryWriter (NewFile)

    Record.Field = FileReader.ReadString()Record.Field = FileReader.ReadDecimal()Record.Field = FileReader.ReadInt32()FileWriter.Write(Field)Channel.Close()FileReader.Close()FileWriter.Close()NewFile.Close()e.g. C#

  • 7/25/2019 TopicWise 2.3 Question

    13/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 13 of 30

    channel = new FileStream(externalFileName,FileMode.Open)fileReader = new BinaryReader(channel)newFile = new FileStream(externalFileName, fileMode.CreatefileWriter = new BinaryWriter (newFile)record.Field = FileReader.ReadString()record.Field = FileReader.ReadDecimal()record.Field = FileReader.ReadInt32()fileWriter.Write(field)channel.Close()fileReader.Close()fileWriter.Close()newFile.Close() [8]

    3 Liliane wants to write a program to play chess. She will represent the board of 8 x 8

    squares, using the 2-dimensional array Board[8,8].

    Each element of the array will need initialising to zero. Later, if a chess piece is on asquare, it will take a value of 1.She starts by writing pseudocode for the initialisation of a 4 x 4 board. This is easier totrace.01 RowNo 1

    02 WHILE RowNo < 4 DO

    03 ColumnNo 1

    04 WHILE ColumnNo < 4 DO

    05 Board[RowNo,ColumnNo] 0

    06 ColumnNo ColumnNo + 1

    07 ENDWHILE

    08 RowNo RowNo + 1

    09 ENDWHILE

    (d) State the count-controlled loop that would be better for this initialisation. [1](d) FOR loop [1]

    (e) On a full 8 x 8 board, state the relative positions of the squares Board[1,8] and

    Board[8,1] . [1]

    (e) at opposite corners [1]

    (f) Liliane's next task is to indicate that there are pieces occupying the first two rows of th8 x8 board.Each square in rows 1 and 2 will be given the value 1.Draw a flowchart that shows how to do this, using loop structures and the variablenames previously used (Board, RowNo, ColumnNo). [5]

    (f) Marking guide:2 FOR loopsnestedrow loop values only 1 & 2assigning value 1correct exit

  • 7/25/2019 TopicWise 2.3 Question

    14/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 14 of 30

    [5]

  • 7/25/2019 TopicWise 2.3 Question

    15/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 15 of 30

    Oct/NOV 2012 P214 Super Bikes will store the data in files.

    (a) One file will store the following data: bike ID bike type date bought currently needs repairComplete the following table. Use a single value for Field Size.Field Name Data Type Field Size (in bytes)

    [4]4 (a)

    Give a tick for each correct cell. Marks are half the number of ticks (round up) [4]

    (b) Estimate the size, in kilobytes, of the file if it stores the details of 90 bikes. Show yourworking. [4]

    (b) (6 + 20 + 8 + 1)* 90 / 1024* 1.1 (or equivalent)=approx 3.4 KB1 mark per row above [4]

    (c) Using a high-level programming language, define a bike record with identifierHireBike and the fields listed in part (a).Programming language used

    Code [5](c) e.g. Pascal

    TYPE HireBike = RECORDBikeID: String[6];BikeType: String[10];DateBought: TDateTime;NeedsRepair: Boolean;END;

    e.g. VB 2005

  • 7/25/2019 TopicWise 2.3 Question

    16/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 16 of 30

    STRUCTURE HireBikeDIM BikeID AS StringDIM BikeType AS StringDIM DateBought AS DateDIM NeedsRepair AS BooleanEND STRUCTURE

    e.g. C#struct hireBike{public string bikeID, bikeType;public dateTime dateBought;public bool needsRepair;}

    1 mark for correct record structure1 mark for each field [5]

  • 7/25/2019 TopicWise 2.3 Question

    17/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 17 of 30

    Oct/NOV 2012 P223 Super Cars will store the data in files.

    (a) One file will store the following data:

    car registration

    make of car

    date car bought

    whether on hire or notComplete the following table. Use a single value for Field Size.

    [4]3 (a)

    [4]

    (b) Estimate the size, in kilobytes, of the file if it stores the details of 100 cars. Show yourworking. [4]

    (b) (6 + 20 + 8 + 1)* 100 / 1024* 1.1 (or equivalent/similar)= 3.8 KB1 mark per row above [4]

    (c) (i) Using a high-level programming language, define a car record with

    Identifier HireCar and the fields listed in part (a).Programming languageCode [5]

    (ii) Car records are stored in a file SuperCars.Write a procedure, AddCar(), to add a record to the end of the file. The record ispassed as the parameter. You should assume that the file is not already in use.

    [5](c) (i) Pascal

  • 7/25/2019 TopicWise 2.3 Question

    18/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 18 of 30

    TYPE HireCar = RECORDCarReg : String[6];Make : String[20];DateBought : TDateTime;OnHire : Boolean;END;

    VB 2005STRUCTURE HireCarDIM CarReg AS StringDIM Make AS StringDIM DateBought AS DateDIM OnHire AS BooleanEND STRUCTURE

    VB6Type HireCarCarReg As StringMake As StringDateBought As DateOnHire As Boolean

    End TypePythonclass HireCar :def __init__(self, carReg, make, dateBought, onHire) :self.CarReg = carRegself.Make = makeself.DateBought = dateBoughtself.OnHire = onHire

    1 mark for correct record structure heading1 mark for correct record structure ending1 mark for 2 STRING fields1 mark for Date field1 mark for Boolean field

    Check programming examplesPenalise once for a repeat mistake

    [5](ii) PascalPROCEDURE AddCar(VAR CarRecord);BEGINAssignFile(CarFile, 'SuperCars');Reset(CarFile);Seek(CarFile, FileSize(CarFile));Write(CarFile, CarRecord);CloseFile(CarFile);END;

    VB 2005

    SUB AddCar(BYREF CarRecord AS HireCar)CarFile = New FileStream('SuperCars', FileMode.Append)Writer = New BinaryWriter(CarFile)CarFile.Write(CarRecord)CarFile.Close()END SUB

    Pythonimport pickledef addCar(CarRecord) :

  • 7/25/2019 TopicWise 2.3 Question

    19/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 19 of 30

    CarFile = open("SuperCars", "ab")pickle.dump(CarRecord, CarFile)CarFile.close()

    Accept pseudocode1 mark for correct procedure heading1 mark for parameter in procedure heading

    1 mark for opening file for writing/appending1 mark for accessing end of file1 mark for writing record1 mark for closing file [5]

    Oct/NOV 2012 P232 Super Bikes owns a rectangular parking area with 30 rows; each row has 4 bike spaces.

    Each bike is always parked in the same space.The array BikeSpace[30,4] stores the bike registrations.Soni uses a flowchart to help him design a module to populate the array with the bikeregistrations.Input is terminated using the rogue value BK000.

  • 7/25/2019 TopicWise 2.3 Question

    20/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 20 of 30

    [7](c) (i) One of the modules uses the expression:

    Area /(SpaceWidth * SpaceLength EmptySpaces)State the value of the part of the expression inside the brackets whenSpaceWidth 7

    SpaceLength 4

    EmptySpaces 28 [1]

    (ii) If this expression is used with the above values, there will be an error.State the name of this type of error. [1]

    (iii) Explain how the programmer can stop this type of error occurring duringexecution. [2]

    (c) (i) 0 (zero) [1](ii) Run-time error (Allow logic error, arithmetic error) [1](iii) check the value of the bracket before the division takes place // write error

    trapping code if bracket = 0 arrange for a message to be output // exception code [2]

  • 7/25/2019 TopicWise 2.3 Question

    21/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 21 of 30

    Accept answers in code

    4 Super Bikes will store the data in files.(a) One file will store the following data:

    bike registration purchase cost of bike

    insurance rating (A, B or C only)

    whether or not service is dueComplete the following table. Use a single value only for Field Size.

    [4]

    4 (a)

    [4]

    (b) Estimate the size, in kilobytes, of the file if it stores the details of 1000 bikes. Showyour working. [4]

    (b) (5 + 8 + 1 + 1)* 1000 / 1024* 1.1 (or equivalent)= 16.1KB (f.t.)

    [4]

    (c) (i) Using a high-level programming language, define a bike record with identifier

    HireBike and the fields listed in part (a).Programming languageCode [5]

    (ii) Bike records are stored in a file SuperBikes.Write the code to read every bike record, count the number of bikes where serviceis due and output the result. You should assume that the file is not already in use.

    [9](c) (i) e.g. Pascal

    TYPE HireBike = RECORD

  • 7/25/2019 TopicWise 2.3 Question

    22/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 22 of 30

    BikeReg: String[5];

    PurchaseCost: Currency;

    InsuranceRating: Char;

    ServiceDue: Boolean;

    END;

    e.g. VB 2005

    STRUCTURE HireBikeDIM BikeReg AS String

    DIM PurchaseCost AS Decimal

    DIM InsuranceRating AS Char

    DIM ServiceDue AS Boolean

    END STRUCTURE

    e.g. C#

    struct hireBike

    {

    public string bikeReg;

    public decimal purchaseCost;

    public char insuranceRating;

    public bool serviceDue;

    1 mark for correct record heading1 mark for correct record structure ending1 mark for first 2 fields1 mark each for 3rd and 4th field [5](ii) e.g. PascalASSIGNFILE(FS, SuperBikes);

    RESET(FS);

    BikesForService := 0;

    WHILE NOT EOF(FS) DO

    BEGIN

    Read(FS, HireBike);

    IF HireBike.ServiceDue

    THEN

    BikesForService:=BikesForService+1;

    END;

    WRITELN(Number of bikes for service: ,

    BikesForService);

    CloseFile(FS);

    e.g. VB 2005

    FS = NEW FileStream(SuperBikes,

    FileMode.open)

    BR = NEW BinaryReader(FS)

    BikesForService = 0

    DO WHILE FS.Position < FS.Length

    HireBike.ServiceDue =

    BR.ReadBoolean()

    IF HireBike.ServiceDue THENBikesForService = BikesForService + 1

    LOOP

    WRITELINE(Number of bikes for service: ,

    BikesForService);

    BR.Close()

    FS.Close()

    e.g. C#

    fs = new Filestream(SuperBikes, FileMode.Open);

  • 7/25/2019 TopicWise 2.3 Question

    23/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 23 of 30

    br = new BinaryReader(fs);

    bikesForService = 0;

    do

    {

    hireBike.ServiceDue =br.Readbool();

    IF (hireBike.ServiceDue)

    {bikesForService:=bikesForService+1;

    }

    }

    while (fs.Position < fs.Length);

    Console.Writeline(Number of bikes

    for service: ,bikesForService);

    br.Close();

    fs.Close;

    1 mark for initialising total1 mark for assigning file name1 mark for opening file for reading1 mark for repeat/while loop

    1 mark for reading record1 mark for testing service due field set to true1 mark for incrementing total1 mark for outputting total1 mark for closing file [9]

    May/June 2013. P21/22

    1 Meena wants to develop a program to keep a record of her coursework assignments.She will want to enter, sort and print out data.

    She decides to modularise the solution.

    (b) (i) Each record needs another field to uniquely identify that record.State an appropriate identifier for this field and state a suitable data type for it.

    [2](ii) In a programming language write the declaration for the record structure, giving it

    the identifier Assignment.Programming languageDeclaration [4]

    (iii) State the number of bytes needed to store a value in the field IsMarked.[1]

    (b) (i) courseworkID/other comparableinteger/other sensible [2]

    (ii) PASCALTYPE Assignment = RECORDCourseworkID : String[6];Subject : String[10];Title : String[10];DateSet : TDateTime;HandInDate : TDateTime;IsMarked : Boolean;

  • 7/25/2019 TopicWise 2.3 Question

    24/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 24 of 30

    DateReturned : TDateTime;Mark : Integer;END;VB.NET / VB2005STRUCTURE AssignmentDIM CourseworkID AS StringDIM Subject AS StringDIM Title AS StringDIM DateSet AS DateDIM HandInDate AS DateDIM IsMarked AS BooleanDIM DateReturned AS DateDIM Mark AS IntegerEND STRUCTUREVB6Type AssignmentCourseworkID AS String * 6Subject AS String * 10

    Title AS String * 10DateSet AS DateHandInDate AS DateIsMarked AS BooleanDateReturned AS DateMark AS IntegerEnd TypeNote: string lengths optionalPYTHONclass Assignment :CourseworkID = "";Subject = ""

    Title = ""DateSet = datetime.date(1,1,1)HandInDate = datetime.date(1,1,1)IsMarked = FalseDateReturned = datetime.date(1,1,1)Mark = 0Marking guidelines:1 mark for correct record header1 mark for correct definition terminator1 mark for all 3 dates declared correctly DateSet HandInDate

    DateReturned1 mark for the following fields defined correctly for language Subject Title IsMarked Mark [4](iii) 1 [1]

  • 7/25/2019 TopicWise 2.3 Question

    25/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 25 of 30

    (c) Describe what the function EOF() does when used in a program. [2](c) uses/detect a marker written to the file

    immediately after the last recordwhen processing a variable length filerecords can be processed until the marker is reachedreturns a Boolean value [Max 2]

    (d) Meena creates a sequential file, MyAssignments, of Assignment records.Using pseudocode write the algorithm to search this file for the first Physicsassignment.OPENFILE MyAssignments FOR OUTPUT

    CLOSEFILE MyAssignments[4]

    (d) Found _ FALSEWHILE NOT EOF(MyAssignments) AND NOT FOUND DO

    Read next RecordIF Assignment.Subject = PhysicsTHENFound _ TRUEENDIFENDWHILE;Marking guidelines:

    set record found to falsewhile NOT EOF and record found is falseread next recordcheck subject field to see if it is the wanted oneif it is, set record found to true [Max 4]

    3 Meena needs to be aware of her average grade and declares a variable AvMark, whichshe decides will be a global variable.To make future computation more straightforward Meena retrieves her marks from the file andstores them in an array, Marks. This array has 30 elements, and marks range from 0 to 100.(d) State a suitable value to initialise each element of the array. Justify your choice.

    Initial valueReason [1]

    (d) a suitable number, e.g. 1 (not any value between 0 and 100 inclusive)reason: this mark is a dummy/rogue value [1]

    (e) Write program code that will declare and initialise the array.Programming languageCode [4]

    (e) PASCALVAR Marks : ARRAY[1..30] OF INTEGER;i : INTEGER;FOR i := 1 to 30 DOBEGINMarks[i] := -1;

  • 7/25/2019 TopicWise 2.3 Question

    26/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 26 of 30

    END;VB.NET / VB2005Dim Marks(30) AS IntegerDIM i AS IntegerFor i = 1 to 30Marks(i) = -1NEXT iVB6DIM Marks(30) AS INTEGERDIM i AS IntegerFOR i = 1 TO 30Marks(i) = -1NEXT iPYTHONMarks = []for i in range(0, 30) :Marks.append(-1)Marking guidelines:

    1 mark for correct array declaration1 mark for correct FOR loop1 mark for assigning the value given in (d) to each element1 mark for LOOPEND / declaration end [4]

    (f) Write program code that will calculate the average of all the marks and assign it toAvMark.Programming languageCode [5]

    (f) PASCALVAR Marks : ARRAY[1..30] OF INTEGER;

    AvMark : REAL;Count, Total, i : INTEGER;BEGIN. . . . . .Total := 0;Count := 0;FOR i := 1 to 30 DOBEGINIF Marks[i] > -1 THENBEGINCount := Count + 1;Total := Total + Marks[i];

    END;END;AvMark := Total/Count;END.VB.NET / VB2005Dim Marks(30) AS Integer. . . . . .Dim Count AS IntegerDim Total AS Integer

  • 7/25/2019 TopicWise 2.3 Question

    27/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 27 of 30

    Dim i AS IntegerDim AvMark AS DoubleTotal = 0Count = 0For i = 1 To 30 ThenIf Marks(i) > -1Count = Count + 1Total = Total + Marks(i)End IFNext iAvMark = Total/CountVB6DIM Marks(30) AS INTEGER. . . . . .DIM Count AS INTEGERDIM Total AS INTEGERDIM i AS INTEGERDIM AvMark AS DOUBLE

    Total = 0Count = 0FOR i = 1 TO 30IF Marks(i) > -1 THENCount = Count + 1Total = Total + Marks(i)END IFNEXT iAvMark = Total/CountPYTHONMarks = []. . . . . .

    Total = 0Count = 0AvMark = 0for i in range(0, 30) :if Marks[i] > -1 :Count = Count + 1Total = Total + Marks[i]AvMark = Total/CountMarking guidelines:1 mark for initialisation of total and marks count1 mark for fully functioning loop1 mark for ignoring the elements with the initial value

    1 mark for incrementing count correctly1 mark for totalling and dividing and assigning the result to AvMark [5]

    May/June 2013. P23

    1 Meena wants to develop a program to keep a record of her examination results.She will want to enter, sort and print out data which is stored as a file of records.Each record will contain at least the following data: subject

  • 7/25/2019 TopicWise 2.3 Question

    28/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 28 of 30

    examination title level date sat markAn example of an examination title is General Certificate of Education.

    The DateSat field will contain only the month and year that the examination was taken.

    For all subjects the mark is between 0 and 100 inclusive.The level is 'O' or 'A'.(a) Complete the table. Use a single value for the size.

    [6]

    1 (a)

    [6]

    (b) Estimate how many records could be held in the file if there are 5 KB available for thefile. [4]

    (b) addition of their field sizes add 10% (x) multiply 5 by 1024

    divide by their (x) [4]

    (c) (i) Each record needs another field to uniquely identify that record.State an appropriate identifier for this field and state a suitable data type for it.

    [2](ii) In a programming language write the declaration for the record structure, giving it

    the identifier Exam.

    Programming languageDeclaration [4]

  • 7/25/2019 TopicWise 2.3 Question

    29/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    http://sites.google.com/site/computing9691/Page 29 of 30

    (c) (i) ExamID / comparable integer/ other suitable [2](ii) e.g. PascalType Exam = RECORDSubject : String [10] ;Title: String [20] ;Level: Char ;DateSat ; String [8] ;Mark ; Integer ;END ;e.g. VB 2005STRUCTURE ExamDIM Subject AS StringDIM Title AS StringDIM Level AS StringDIM DateSat AS DateDIM Mark AS IntegerEND STRUCTURE

    - Correct record header- Definition terminator- Date declared correctly- All other fields declared correctly [4]

    (d) Meena decides to modularise the solution.Describe two ways in which a procedural programming language is appropriate whenmodularising a solution. [4]

    (d) easier to follow logic of problem can focus on one part at a time produces reusable code easier to maintain

    can debug a small section at a time [Max 4]

    (e) Describe what the function EOF() does when used in a program. [2]

    (e) uses/detects a marker written to the file immediately after the last record when processing a variable length file records can be processed until the marker is reached returns a Boolean value [Max 2]

    3 Meena needs to be aware of her average mark and declares a variable with identifierMyAvMark which she decides will be a global variable.

    (c) State a suitable value to initialise each element of the array. [1]

    (c) Integer value outside range 0100/ null value [1]

    (d) In a programming language, write code that will declare and initialise MyMarks.Programming languageCode [4]

    (d) e.g. VB 2005

  • 7/25/2019 TopicWise 2.3 Question

    30/30

    Reinforcement: 05-10 Years' relevant CIE answers.Section 2.3

    DIM MyMarks(50) AS INTEGERDIM Count AS INTEGERFOR Count = 1 TO 50MyMarks(Count) = -1NEXT CountC#Int [ ] myMarks;myMarks = new int[50];for (int count =1; count Highest THENHighest = MyMarks (Count)END IFIF MyMarks(Count) < Lowest THEN

    Lowest =MyMarks(Count);END IFConsole.WriteLine(Highest: , Highest)Console.WriteLine(Lowest: ,Lowest)

    FOR loop Setting a low highest value Setting a high lowest value Comparing each element with both these getting correct highest and lowest values output of values [6]