9618 Paper 2 Revision
CS Question Bank
165 exam-style questions with model answers from Cambridge past papers
115 questions • 13 topics
Showing 115 questions
Algorithm Theory (9.1, 9.2)
Complete this definition of the term algorithm. An algorithm is a solution to a problem expressed as _________________________
Algorithm Theory (9.1, 9.2)
Algorithms are produced during program development. State when you would produce an algorithm during program development and state its purpose. When: _________________________________________________________________________ Purpose: ______________________________________________________________________
Algorithm Theory (9.1, 9.2)
Explain the process of problem decomposition. State one reason it may be used. Explanation: __________________________________________________________________ Reason: ______________________________________________________________________
Algorithm Theory (9.1, 9.2)
As part of the development of an algorithm, a programmer may construct an identifier table. Describe what an identifier table contains.
Algorithm Theory (9.1, 9.2)
Explain what is meant by abstraction in the context of computational thinking.
Algorithm Theory (9.1, 9.2)
Simple algorithms usually consist of three different stages. Complete the table. Write each example statement in pseudocode. | Stage | Example statement | |-------|-------------------| | Input | | | Process | x ← y / 3 | | Output | |
Algorithm Theory (9.1, 9.2)
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 & MyIDNumber | | | | | READFILE 'AddressBook.txt', NextLine | | | |
Algorithm Theory (9.1, 9.2)
Write a single statement in pseudocode that contains two of the stages (Input, Process, Output). Do not repeat any of the statements from part (c)(i).
Algorithm Theory (9.1, 9.2)
Identify the type of programming statement that assigns a data type to a variable.
Algorithm Theory (9.1, 9.2)
Programming is sometimes referred to as a transferable skill. You are asked to work on a program written in a language you are not familiar with. Explain how transferable skills would help you work on the program.
Algorithm Theory (9.1, 9.2)
Explain the process of stepwise refinement.
Algorithm Theory (9.1, 9.2)
Algorithms may be expressed using four basic constructs. One construct is sequence. Complete the following table for two other constructs. | Construct | Pseudocode example | |-----------|--------------------| | Assignment | | | Selection | | | Iteration | |
Algorithm Theory (9.1, 9.2)
Explain the term algorithm.
Algorithm Theory (9.1, 9.2)
A student is learning about arrays. She wants to write a program to: • search through a 1D array of 100 elements • count the number of elements that contain the string 'Empty' • output the number of elements containing 'Empty' together with a suitable message. Use structured English to describe the algorithm she could use.
Algorithm Theory (9.1, 9.2)
A program needs to search through 1000 elements of an unsorted array to find a given value. The program will output either the position in the array of the value or the message 'Not Found'. Outline the steps the program needs to follow. Do not write pseudocode or program code.
Data Types & Expressions (10.1)
Programming languages can support different data types. Complete the table by naming three different data types together with an example data value for each. | Data type | Example data value | |-----------|-------------------| | | | | | | | | |
Data Types & Expressions (10.1)
Give the most appropriate data type for each variable: | Statement | Data type | |-----------|-----------| | MyAverage ← 13.5 | | | ProjectCompleted ← TRUE | | | Subject ← 'Home Economics' | | | MyMark ← 270 | | | MyGrade ← 'B' | |
Data Types & Expressions (10.1)
Using the values from the previous question, evaluate each expression. If invalid, write 'ERROR'. | Expression | Evaluates to | |------------|--------------| | 'Air-' & MID(Subject, 7, 3) | | | INT(MyAverage / 2) | | | ProjectCompleted AND MyMark > 270 | | | ProjectCompleted OR MyMark > 260 | | | ASC(MyGrade / 3) | |
Data Types & Expressions (10.1)
Program variables have values: • MyGreeting = 'Happy Birthday' • MyInitial = 'C' • AgeInYears = 27 • Weight = 60.5 • Married = TRUE • Children = TRUE Evaluate each expression. If invalid, write 'ERROR'. | Expression | Evaluates to | |------------|--------------| | 'Mon' & MID(MyGreeting, 10, 2) | | | AgeInYears + ASC(MyInitial) | | | INT(MyInitial) | | | MOD(Weight * 2, 10) | | | Married AND (NOT Children) | |
Data Types & Expressions (10.1)
Variables: • MeltingPoint = 180.5 • Soluble = FALSE • Attempt = 3 • ProductName = 'Mushroom Compost' • Version = 'A' • ProductID = 'BZ27-4' Evaluate: | Expression | Evaluates to | |------------|--------------| | STRING_TO_NUM(MID(ProductID, 3, 2)) + 4 | | | INT(MeltingPoint / 2) | | | Soluble AND Attempt > 3 | | | LENGTH(ProductID & NUM_TO_STRING(MeltingPoint)) | | | RIGHT(ProductName, 4) & MID(ProductName, 5, 4) | |
Data Types & Expressions (10.1)
A program stores data about hospital patients. Give a suitable identifier name for each of the data items. | Description of data item | Suitable identifier name | |--------------------------|--------------------------| | The temperature of the patient | | | The temperature of the room | | | The patient identification number | | | The name of the nurse taking the measurement | |
Data Types & Expressions (10.1)
Give an appropriate data type for each of these variables. | Variable | Data type | |----------|-----------| | Title | | | Version | | | PackSize | | | WeightEach | | | Paperback | |
Data Types & Expressions (10.1)
Variables: • Mark = 60 • Subject = 'Computer Science' • Grade = 'B' • CourseCompleted = TRUE • AverageMark = 49.5 Evaluate each expression. If invalid, write 'ERROR'. | Expression | Evaluates to | |------------|--------------| | 'Fas' & MID(Subject, 6, 3) | | | LEFT(Mark, 1) | | | 10 + ASC(Grade) | | | MOD(AverageMark * 2, 3) | | | CourseCompleted AND (Mark >= 60) | |
Data Types & Expressions (10.1)
Variables: • Quality = 'D' • DayNumber = 20 • MyName = 'Stephen' • QualityConfirmed = TRUE • Factor = 6.5 Evaluate each expression. If invalid, write 'ERROR'. | Expression | Evaluates to | |------------|--------------| | MID(MyName, 4, 4) & 'ol' | | | QualityConfirmed AND (Factor >= 6.5) | | | 20 + ASC(Quality) | | | QualityConfirmed + 3 | | | MOD(Factor * 2, 9) | |
Data Types & Expressions (10.1)
Give an appropriate data type for each variable. | Variable | Data type | |----------|-----------| | Married | | | ID | | | MiddleInitial | | | Height | | | IsMarried | |
Selection & CASE (11.2)
The pseudocode contains the following statements: Result ← 2 & 4 IF x = 3 OR 4 THEN Identify the errors in these statements.
Selection & CASE (11.2)
The following pseudocode represents part of the algorithm for a program: CASE OF ThisValue <30 : Level ← 'Low' <20 : Level ← 'Very Low' Check ← ThisValue / 2 30 TO 40 : Level ← 'Medium' Data[ThisValue] ← Data[ThisValue] + 1 >40 : Level ← 'High' ENDCASE (a) Complete the table: - The value assigned to Level when ThisValue is 40 - The value assigned to Level when ThisValue is 18 - The value assigned to Check when ThisValue is 36 - The number of elements in array Data that may be incremented (b) The pseudocode contains an assignment that will never be performed. Identify this assignment and explain why.
Selection & CASE (11.2)
A program will calculate the tax payable based on the cost of an item. CASE OF ItemCost <=50 : TaxRate ← 3.75 <=200 : TaxRate ← 5.23 >200 : TaxRate ← 6.25 HighRate ← TRUE ENDCASE The pseudocode contains a logical error. Identify the error and suggest a correction.
Selection & CASE (11.2)
In a CASE statement, the final condition `> 200` could be replaced with a keyword. Give the keyword.
Selection & CASE (11.2)
The following table shows ranges for tax rates based on item cost: | Item Cost | Tax Rate | |-----------|----------| | <= 50 | 3.75% | | <= 200 | 5.23% | | > 200 | 6.25% | Write pseudocode using a CASE structure to assign the correct TaxRate.
Loops (FOR, WHILE, REPEAT) (11.2)
A 1D array Data of type integer contains 200 elements. Each element has a unique value. An algorithm is required to search for the largest value and output it. Describe the steps that the algorithm should perform. Do not include pseudocode statements in your answer.
Loops (FOR, WHILE, REPEAT) (11.2)
A 1D array Data of type integer contains 200 elements. Each element has a unique value. An algorithm is required to search for the largest value and output it. Write pseudocode for this algorithm.
Loops (FOR, WHILE, REPEAT) (11.2)
An algorithm will: 1. input a sequence of integer values, one at a time 2. ignore all values until the value 27 is input, then sum the remaining values 3. stop summing values when the value 0 is input and then output the sum. Draw a program flowchart to represent the algorithm. (Describe the flowchart in words.)
1D Arrays (10.2)
A student wants to write a program to: - declare a 1D array RNum of 100 elements of type INTEGER - assign each element a random value in the range 1 to 200 inclusive - count and output how many numbers generated were between 66 and 173 inclusive. Write pseudocode to represent the algorithm.
1D Arrays (10.2)
A student wants to modify the algorithm so that each element of the array will contain a unique value. Describe the changes that need to be made to the algorithm.
1D Arrays (10.2)
A global 1D array Data contains 150 elements of type STRING. A function TooMany() will: 1. take two parameters: a string (the search string) and an integer (the maximum value) 2. count the number of strings in the array that exactly match the search string 3. return TRUE if the count is greater than the maximum value, otherwise return FALSE Write pseudocode for the function TooMany().
1D Arrays (10.2)
A program contains a global 1D array Data containing 20 elements of type INTEGER. A global string NumString represents a sequence of three-digit numbers, separated by commas. For example: '101,456,219,754,328' The string contains at least four three-digit numbers. The total number of three-digit numbers in the string is unknown. A procedure Store() will: - extract one three-digit number at a time from NumString - convert each of the three-digit numbers extracted to an integer and assign this to the next array element, starting from index 1 - end when all three-digit numbers have been stored, or when the array is full. Complete the pseudocode for Store(). All local variables used must be declared.
1D Arrays (10.2)
A global 2D array Loyalty is made up of 1000 rows and 2 columns. - Column 1 contains a unique customer ID (starting at 10001) - Column 2 contains the number of loyalty points Rows that are not currently being used have Column 1 set to 99999. The array is sorted in ascending order by customer ID. A function FindCustomer() is called with a customer ID as a parameter. It searches the Loyalty array for this customer ID. The search stops as soon as the customer ID is found. If found, return the loyalty points, otherwise return -1. Write efficient pseudocode for FindCustomer().
1D Arrays (10.2)
A program contains a global 1D array Data containing 20 elements of type INTEGER. A global string NumString represents a sequence of three-digit numbers, separated by commas. For example: '101,456,219,754,328' Write pseudocode for Store() using an alternative method that extracts characters one at a time and tests for commas.
1D Arrays (10.2)
Two 1D arrays of type integer: - Array1 contains 600 elements (sample values from a sensor) - Array2 contains 200 elements The sensor always takes three consecutive samples. A procedure Summarise() will calculate the average of three consecutive values from Array1 and write the result to Array2. This is repeated for all values in Array1. Write pseudocode for Summarise().
1D Arrays (10.2)
A procedure CountVowels() will: - be called with a string containing alphanumeric characters - count and output the number of occurrences of each vowel (a, e, i, o, u) - count and output the number of occurrences of the other alphabetic characters - the string may contain both upper and lower case characters Each count value will be stored in a unique element of a global 1D array CharCount of type INTEGER. The array will contain six elements. Write pseudocode for CountVowels().
1D Arrays (10.2)
A global 2D array Result of type INTEGER is used to store exam candidate numbers together with their marks. The array contains 2000 elements, organised as 1000 rows and 2 columns. Column 1 contains the candidate number and column 2 contains the mark for the corresponding candidate. All elements contain valid exam result data. A procedure Sort() is needed to sort Result into ascending order of mark using an efficient bubble sort algorithm. Write pseudocode for Sort().
1D Arrays (10.2)
A program contains a global 1D array Number consisting of 20 elements of type REAL. A procedure Store() will input a sequence of up to 20 real values, one value at a time. These values will be assigned to elements of the array using four steps: Step 1: store the first value in the sequence in the first element of the array Step 2: check each subsequent value input. If this value is larger than the previous value input, then assign the value to the next array element, otherwise go to step 4 Step 3: repeat from step 2 unless the array is full Step 4: output the count of the number of values stored in the array together with a suitable message. Complete the pseudocode for Store(). All variables used in the algorithm must be declared.
1D Arrays (10.2)
A music player displays track titles. Up to 16 characters can be displayed. Track titles longer than 16 characters need to be trimmed. Words must be removed from the end of the track title until the resulting title is less than 14 characters. When a word is removed, the space in front of that word is also removed. Three dots are added to the end of the last word displayed. Write a function Trim() that takes a string representing the original title and returns the string to be displayed. Assume: - Words are separated by a single space character. - The first word is less than 14 characters.
2D Arrays (10.2)
A video-conferencing program supports up to six users. Digitised values are stored in array Sample (6 rows by 128 columns). Each row contains 128 digitised sound samples from one user. A procedure Mix() will: - calculate the average of each of the 6 sound samples in a column - ignore sound sample values of 10 or less - store the average value in the corresponding position in Result - repeat for each column in array Sample Write pseudocode for Mix(). Assume Sample and Result are global.
2D Arrays (10.2)
A mobile phone touchscreen is represented by a 2D array Screen of type INTEGER (800 rows × 1280 columns). An array element is set to 1 if the user touches that part of the screen. A function FirstRowSet() searches for the first row that has an array element set to 1 and returns the index of that row. Returns -1 if no elements are set. Write efficient pseudocode for FirstRowSet().
2D Arrays (10.2)
A procedure Sort() is needed to sort a 2D array Reading (2000 rows × 2 columns) into ascending order of sensor value (column 1) using an efficient bubble sort algorithm. Column 2 contains the corresponding sensor ID. Write efficient pseudocode for Sort().
2D Arrays (10.2)
RouteTable is a global 2D array of integers (6 rows × 3 columns). - Column 1: lower bound of ID range - Column 2: upper bound of ID range - Column 3: port number Row 3 in the example shows an unused row (column 1 set to -1). A function GetPort() takes a DestinationID as a parameter, searches for the range containing the DestinationID, and returns the port number, or -1 if not found. Write pseudocode for GetPort().
2D Arrays (10.2)
A procedure BestRestaurants() searches a 2D array ReviewScores (20000 rows × 2 columns) for restaurants with an average score that exceeds 8.0. Column 1 stores the geocode and score (separated by '#'), e.g., '1DFG+9N#8.3' Column 2 stores the review comment. The procedure takes a geocode as a parameter. If the parameter matches a geocode in the array and the average score exceeds 8.0, output the geocode concatenated with the review comment. Write pseudocode for BestRestaurants().
2D Arrays (10.2)
Write pseudocode to declare a 2D array Check of type BOOLEAN. The array has 76 elements (indices 0 to 75). All elements should be set to FALSE initially.
Records (10.1)
A program stores data about students and the clubs they join. Each student may join up to three clubs. Write pseudocode to declare a record structure for type Student. Fields required: - StudentID (STRING) - Email (STRING) - Club_1, Club_2, Club_3 (INTEGER, values 1-99)
Records (10.1)
Using the Student record type from the previous question, write pseudocode to declare a 1D array Membership containing 3000 elements.
Records (10.1)
A record type Component is declared: TYPE Component DECLARE Item_ID : STRING DECLARE Reject : BOOLEAN DECLARE Weight : REAL ENDTYPE A global array Batch[1:1000] OF Component is declared. Write a pseudocode clause to check whether the weight of an individual component (indexed by ThisIndex) is within the acceptable range (between Min and Max, inclusive).
Records (10.1)
A record type MyType is defined with three fields: TYPE MyType DECLARE RA : INTEGER DECLARE RB : STRING DECLARE RC : BOOLEAN ENDTYPE Write pseudocode to define MyType and then write the pseudocode header for a procedure Sub-9() that takes a single parameter of type MyType passed by reference.
Procedures & Functions (11.3)
A record type Result is defined: TYPE Result DECLARE Done : BOOLEAN DECLARE Value : REAL ENDTYPE A function Evaluate() takes two string parameters (representing numeric values) and returns a variable of type Result. If either string does not represent a valid numeric value, or the divisor is zero, Done is set to FALSE. Otherwise, Done is set to TRUE and Value is assigned the result of the calculation. Write pseudocode for Evaluate().
Procedures & Functions (11.3)
A text string contains three data items concatenated: <StockID><Description><Cost> Items: - StockID: 5 characters - Description: 32 characters - Cost: the remainder of the string A procedure Unpack() takes four parameters of type string. One parameter is the original text string. The other three parameters are used to represent the three data items and are assigned values within the procedure. Write pseudocode for Unpack().
Procedures & Functions (11.3)
Write pseudocode for the module headers: Sub_Part1A: Takes a parameter R of type INTEGER. Sub_Part2A: Takes a parameter T of type REAL and returns a BOOLEAN. Sub_Part3A: Takes parameters V (INTEGER), W (BOOLEAN), and U (STRING passed by reference).
Procedures & Functions (11.3)
A function Pop() is written to remove an item from a stack. It returns an item of type PopData which is defined: TYPE PopData DECLARE Data : INTEGER DECLARE Exists : BOOLEAN ENDTYPE Complete the pseudocode for Pop(). Stack notes: - SP (stack pointer) contains the array index of the last value pushed - If the stack is empty, SP = 0 - The first item is stored in ThisStack[1] - SP is incremented each time an item is added
Procedures & Functions (11.3)
A function Evaluate() takes two string parameters and returns a record type Result. Write pseudocode for Evaluate() including validation of the string parameters.
Procedures & Functions (11.3)
Write the pseudocode header for the module LoanReturn() based on the following description: LoanReturn() is called with parameters LoanID, BookID and Fine. - LoanID and BookID are of type STRING - Fine is of type REAL and is passed by reference - The module code checks whether the book has been returned on time and then assigns a new value to Fine
Procedures & Functions (11.3)
A function CheckInfo() takes a string parameter representing a line of item information and checks whether the item information is valid. Valid information: - ItemNum: 4 numeric characters (0001-5999) - SupplierCode: 3 alphabetic characters - Description: a minimum of 12 characters Write pseudocode for CheckInfo() using the module OnlyAlpha() which returns TRUE if a string contains only alphabetic characters.
Procedures & Functions (11.3)
A function FindFirst() searches a global array MyData[1:10000] for a given string and returns the index of the first element where that string is found, or -1 if the string is not found. Write the function using an appropriate loop construct.
Procedures & Functions (11.3)
A procedure LoanStatus() is called with two parameters of type STRING (StudentID and BookID). It searches an array Loan (8000 records) for a matching loan. If found, it outputs whether the loan has been returned or not. If not found, it outputs a warning message. Write pseudocode for LoanStatus().
File Handling (10.3)
A procedure Preview() will: - take the name of a text file as a parameter - output a warning message if the file is empty - otherwise output the first five lines from the file (or as many lines as there are in the file if this number is less than five) Write pseudocode for Preview().
File Handling (10.3)
A procedure CreateFiles() takes two parameters: - a string representing a file name - an integer representing the number of files to be created Each file name is formed by concatenating the file name with a suffix based on the file number. The suffix is always three characters. For example: CreateFiles('TestData', 3) creates TestData.001, TestData.002, TestData.003. Each file contains the line: 'This is File TestData.002' Write pseudocode for CreateFiles().
File Handling (10.3)
A text file OldFile.txt contains IDs, names and email addresses stored with each item on a separate line (3 lines per person). The file format is being changed so that each person's data is stored on a single line with the character '\' as a separator. Complete the steps of the algorithm to create NewFile.txt.
File Handling (10.3)
A procedure Preview() will output the first five lines from a file. Write the pseudocode for Preview().
File Handling (10.3)
An algorithm will prompt and input the name and test mark for each of 35 students and add the names of all students with a mark of less than 20 to an existing text file Support_List.txt. Describe the steps of the algorithm. Do not include pseudocode.
File Handling (10.3)
Write the pseudocode statement to call CountErrors() to check the project file Jim01Prog.txt and to stop if more than 20 errors are found.
File Handling (10.3)
A procedure CreateFiles() takes a file name and a number of files as parameters. Each file is given a different name with a 3-character suffix. Write pseudocode for CreateFiles().
File Handling (10.3)
A procedure MakeNewFile() takes three parameters: an existing file name, a new file name, and a search status value. It creates a new file and writes all employee details where the employee status is not equal to the search status value. Write pseudocode for MakeNewFile().
File Handling (10.3)
A function LogEvents() takes a Student ID as a parameter. For each element in LogArray that matches the Student ID: - add the value to the existing text file LogFile - assign an empty string to the array element - count the number of lines added Return the count. Write pseudocode for LogEvents().
File Handling (10.3)
A procedure CreateFiles() will create the number of text files specified. Each file is given a different name with a suffix based on the file number. Write pseudocode for CreateFiles().
File Handling (10.3)
Data is a global 1D array containing 20 elements of type REAL. An algorithm will: - input a sequence of real values, one at a time - assign each value to consecutive array elements, starting from index 1 - end when the value 99.9 is input, or all 20 elements have been assigned - the value 99.9 must not be stored in the array Complete the program flowchart for the algorithm.
File Handling (10.3)
A procedure MakeNewFile() will take three parameters: an existing file name, a new file name, and a search status value. It will create a new file and write all employee details where the employee status is not equal to the search status. Write pseudocode for MakeNewFile().
Flowcharts (9.2)
A program will input 50 unique integer values, output the largest value, and output the average of the values excluding the largest value. Draw a program flowchart to represent the algorithm. Variable declarations are not required.
Flowcharts (9.2)
Data is a 1D array of integers with 30 elements. All values are unique. An algorithm will output the index of the element with the smallest value. Draw a program flowchart to represent the algorithm.
Flowcharts (9.2)
Data is a global 1D array containing 20 elements of type REAL. An algorithm will input a sequence of real values, one at a time, and assign each value to consecutive array elements starting from index 1. It ends when the value 99.9 is input or all 20 elements have been assigned. Complete the program flowchart.
Flowcharts (9.2)
An algorithm will input 100 numbers one at a time, keep a total of all numbers input that have a value between 30 and 70 inclusive, and output this total after the last number has been input. Draw a program flowchart.
Flowcharts (9.2)
A procedure CheckSensor() monitors the temperature in different locations. The temperature is measured by 10 sensors (IDs 1-10). The procedure will prompt for a sensor ID, validate it (1-10), get the temperature using GetTemp(SensorID), and compare it against LowTemp and HighTemp. Actions: - Below LowTemp: Output 'Cold' - From LowTemp to HighTemp: Output 'Normal' - Above HighTemp: Call Alarm() Draw a program flowchart.
Flowcharts (9.2)
Data is a 1D array of integers with 30 elements. All values are unique. An algorithm will output the index of the element with the smallest value. Draw a program flowchart to represent the algorithm.
Flowcharts (9.2)
Data is a global 1D array containing 20 elements of type REAL. An algorithm will input a sequence of real values, one at a time, and assign each value to consecutive array elements starting from index 1. It ends when the value 99.9 is input or all 20 elements have been assigned. Complete the program flowchart.
Flowcharts (9.2)
An algorithm will input 100 numbers one at a time, keep a total of all numbers input that have a value between 30 and 70 inclusive, and output this total after the last number has been input. Draw a program flowchart.
Flowcharts (9.2)
A procedure FillTank() uses a while loop to top up a tank until it is full or until a maximum number of attempts is reached. Complete the program flowchart for FillTank().
Flowcharts (9.2)
An array contains 100 integer values. An algorithm will find the maximum and minimum values. Draw a program flowchart.
Flowcharts (9.2)
A function Status() is called with three integer parameters: Actual, Min, Max. Outcomes: - Accept: 'A' (if weight is within range) - Reject: 'R' (if weight is at least 3 more than Max or 3 less than Min) - Recheck: 'C' (if weight is within 2 of Max or Min) Draw a program flowchart for Status().
Flowcharts (9.2)
An algorithm will input a sequence of numbers until zero is input, sum the negative numbers and sum the positive numbers, then output both sums. Draw a program flowchart.
Flowcharts (9.2)
Data is a global 1D array containing 20 elements of type REAL. An algorithm will input a sequence of real values and assign each value to consecutive array elements. It ends when the value 99.9 is input or all 20 elements have been assigned. Complete the program flowchart.
Structure Charts (12.2)
Explain the meaning of the diamond symbol as used in a structure chart.
Structure Charts (12.2)
Six modules are defined: - Module-A() - Module-X(T1 : INTEGER, S2 : REAL) - Reset(BYREF Code : INTEGER) - Restore(OldCode : INTEGER) RETURNS BOOLEAN - Module-Y(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN - Module-Z(SA : INTEGER) RETURNS INTEGER Module-X() calls Reset() Module-Y() calls Restore() Complete the structure chart.
Structure Charts (12.2)
A structure chart shows the modular structure of a program. The curved arrow symbol begins and ends at Module-A(). Explain the meaning of the curved arrow symbol.
Structure Charts (12.2)
Module Check() repeatedly calls Init() followed by Reset(). Module Init() has no parameters and returns a Boolean. Module Reset() takes a string as a parameter and returns an Integer. Draw a structure chart.
Structure Charts (12.2)
Module Connect() will call either Activate() or Sync(). Headers: - PROCEDURE Connect() - FUNCTION Activate(H1 : STRING, Code : INTEGER) RETURNS BOOLEAN - FUNCTION Sync(T1 : BOOLEAN, S2 : REAL) RETURNS INTEGER - PROCEDURE Initialise(BYREF ID : INTEGER, BYVAL CC : INTEGER) - FUNCTION Reset(RA : STRING) RETURNS INTEGER - FUNCTION Enable(SA : INTEGER) RETURNS BOOLEAN Module Connect() will call either Activate() or Sync(). This is decided at run time. Complete the structure chart for these modules.
Structure Charts (12.2)
Complete the structure chart for modules: - Module-A() - Module-X(T1 : INTEGER, S2 : REAL) - Reset(BYREF Code : INTEGER) - Restore(OldCode : INTEGER) RETURNS BOOLEAN - Module-Y(RA : INTEGER, RB : BOOLEAN) RETURNS BOOLEAN - Module-Z(SA : INTEGER) RETURNS INTEGER Module-X() calls Reset() Module-Y() calls Restore()
Structure Charts (12.2)
Module Check() repeatedly calls Init() followed by Reset(). Module Init() has no parameters and returns a Boolean. Module Reset() takes a string as a parameter and returns an Integer. Draw a structure chart.
Structure Charts (12.2)
A structure chart shows: - Module Setup calls either Restart or Confirm - Confirm takes a string and returns an integer - Modify takes no parameters and returns a Boolean - Update takes a string - Restart repeatedly calls Update followed by Modify - Restart takes a string passed by reference Write pseudocode headers and draw the structure chart.
Trace Tables & Error Detection (12.3)
A procedure Process() manipulates a 1D array: PROCEDURE Process(Start : INTEGER) DECLARE Value, Index, Count : INTEGER Index ← Start Count ← 0 REPEAT Value ← Mix[Index] Mix[Index] ← Mix[Index] - 1 Index ← Value Count ← Count + 1 UNTIL Count = 5 Mix[4] ← Count * Index ENDPROCEDURE Initial array: Mix[1]=1, Mix[2]=3, Mix[3]=4, Mix[4]=2 Complete the trace table for CALL Process(3).
Trace Tables & Error Detection (12.3)
A function IsValid() checks if a string is a valid email address. Complete the trace table for the call: Result ← IsValid('Liz.123@big@net')
Trace Tables & Error Detection (12.3)
A procedure Process() manipulates a 1D array Mix. Initial array: Mix[1]=4, Mix[2]=2, Mix[3]=3, Mix[4]=5 PROCEDURE Process(Start : INTEGER) DECLARE Value, Index, Total : INTEGER Index ← Start Total ← 0 WHILE Total < 20 Value ← Mix[Index] Total ← Total + Value IF Index < 4 THEN Mix[Index] ← Mix[Index] + Mix[Index+1] ELSE Mix[Index] ← Mix[Index] + Mix[1] ENDIF Index ← (Value MOD 4) + 1 ENDWHILE Mix[1] ← Total * Index ENDPROCEDURE Complete the trace table for CALL Process(2).
Trace Tables & Error Detection (12.3)
A function Convert() transforms a string by capitalising the first letter of each word. Complete the trace table for Result ← Convert('VinVaVVCup') where 'V' represents a space character.
Trace Tables & Error Detection (12.3)
The following pseudocode contains an error in the CASE structure: CASE OF ThisValue <30 : Level ← 'Low' <20 : Level ← 'Very Low' Check ← ThisValue / 2 30 TO 40 : Level ← 'Medium' Data[ThisValue] ← Data[ThisValue] + 1 >40 : Level ← 'High' ENDCASE Identify the assignment that will never be performed and explain why.
Trace Tables & Error Detection (12.3)
The pseudocode contains a logical error: CASE OF ItemCost <=50 : TaxRate ← 3.75 <=200 : TaxRate ← 5.23 >200 : TaxRate ← 6.25 HighRate ← TRUE ENDCASE Identify the error and suggest a correction.
Trace Tables & Error Detection (12.3)
A procedure Process() contains the following: PROCEDURE Process(Label : STRING) DECLARE Index : INTEGER Index ← 0 INPUT Data[Index] WHILE Index < 200 Index ← Index + 1 CASE OF (Index MOD 2) 0 : Data[Index] ← TO_UPPER(Label) 1 : Data[Index] ← TO_LOWER(Label) ENDCASE ENDWHILE OUTPUT 'Completed ' & Index & ' times' ENDPROCEDURE Identify the errors.
Trace Tables & Error Detection (12.3)
The pseudocode contains statements with errors: Result ← 2 & 4 IF x = 3 OR 4 THEN Identify the errors.
Trace Tables & Error Detection (12.3)
The following pseudocode contains an error in the CASE structure. CASE OF ThisValue <30 : Level ← 'Low' <20 : Level ← 'Very Low' Check ← ThisValue / 2 30 TO 40 : Level ← 'Medium' Data[ThisValue] ← Data[ThisValue] + 1 >40 : Level ← 'High' ENDCASE (a) Complete the table for ThisValue values 40, 18, and 36. (b) Identify the assignment that will never be performed.
Trace Tables & Error Detection (12.3)
A procedure Process() manipulates a 1D array Mix. Initial array: Mix[1]=1, Mix[2]=2, Mix[3]=5, Mix[4]=3 PROCEDURE Process(Start : INTEGER) DECLARE CaseVar, Index, Count : INTEGER Index ← Start Count ← 0 WHILE Count <= 20 CaseVar ← Num[Index] CASE OF CaseVar 1 : Num[Index] ← Num[Index] + Index Index ← Index + 1 Count ← Count + 1 2 : Num[Index] ← Num[Index] + Index Index ← Index + 2 Count ← Count + 2 3 : Num[Index] ← Num[Index] + 2 Index ← Index + 3 Count ← Count + 1 4 : Count ← Count + 4 OTHERWISE : Count ← 20 ENDCASE Index ← (Index MOD 4) + 1 ENDWHILE ENDPROCEDURE Complete the trace table for CALL Process(1).
Trace Tables & Error Detection (12.3)
The pseudocode statements may contain errors. Describe the error in each statement, or write 'NO ERROR'. (a) Result ← 2 & 4 (b) SubString ← MID('pseudocode', 4, 1) (c) IF x = 3 OR 4 THEN (d) Result ← Status AND INT(x/2) (e) Message ← 'Done' + LENGTH(MyString)
Trace Tables & Error Detection (12.3)
A procedure FormatName() should assign a value to the global variable FString. There is a fault in the program, which means that the assignment does not always take place. Explain two ways of exposing the fault.
Trace Tables & Error Detection (12.3)
A pseudocode algorithm contains a conditional loop. State a more appropriate loop structure and justify your answer.
Trace Tables & Error Detection (12.3)
A program runs but does not give the expected output. Describe two methods you could use to find the error.
Testing & Maintenance (12.3)
A test plan is needed to test a function that validates sensor values (range 0 to 40). Complete the test plan table. The first line has been completed. | Test | Test data value | Explanation | Expected outcome | |------|-----------------|-------------|------------------| | 1 | 23 | Normal data | Data is accepted | | 2 | | | | | 3 | | | | | 4 | | | | | 5 | | | |
Testing & Maintenance (12.3)
A program module tests different paths through an algorithm. State two tests, using valid data, that can be used to test different paths through a bonus calculation program. | Hours worked | Value of sales | Bonus pay | |--------------|----------------|-----------| | | | | | | | |
Testing & Maintenance (12.3)
A program contains modules SuppExists() and CheckSupplier() which have been written but contain errors. These modules are called from several places in the main program and testing of the main program has had to stop. Identify a method that can be used to continue testing before the errors have been corrected and describe how this would work.
Testing & Maintenance (12.3)
A program has been in use for a number of months and adaptive maintenance is required. Give one reason why adaptive maintenance may be required.
Testing & Maintenance (12.3)
Alpha and beta testing has been completed. The final testing stage is carried out by the customer. Identify this final testing stage.