9618/22 · May/June 2023
Download PDFRefer to the insert for the list of pseudocode functions and operators. A program calculates the postal cost based on the weight of the item and its destination. Calculations occur at various points in the program and these result in the choice of several possible postal costs. The programmer has built these postal costs into the program. For example, the postal cost of $3.75 is used in the following lines of pseudocode: IF Weight < 250 AND ValidAddress = TRUE THEN ItemPostalCost <- 3.75 // set postal cost for item to $3.75 ItemStatus <- "Valid" // item can be sent ENDIF
Identify a more appropriate way of representing the postal costs.
Describe the advantages of your answer to part (a)(i) with reference to this program.
The lines of pseudocode contain features that make them easier to understand. State three of these features. 1 2 3
Give the appropriate data types for the following variables: ValidAddress ItemPostalCost ItemStatus
A program stores a user's date of birth using a variable MyDOB of type DATE.
Write a pseudocode statement, using a function from the insert, to assign the value corresponding to 17/11/2007 to MyDOB.
MyDOB has been assigned a valid value representing the user's date of birth. Write a pseudocode statement to calculate the number of months from the month of the user's birth until the end of the year and to assign this to the variable NumMonths. For example, if MyDOB contains a value representing 02/07/2008, the value 5 would be assigned to NumMonths.
The program will output the day of the week corresponding to MyDOB. For example, given the date 22/06/2023, the program will output "Thursday". An algorithm is required. An array will be used to store the names of the days of the week. Define the array and describe the algorithm in four steps. Do not use pseudocode statements in your answer. Array definition Step 1 Step 2 Step 3 Step 4
A program stores data in a text file. When data is read from the file, it is placed in a queue.
The diagram below represents an Abstract Data Type (ADT) implementation of the queue. Each data item is stored in a separate location in the data structure. During initial design, the queue is limited to holding a maximum of 10 data items. The operation of this queue may be summarised as follows: • The Front of Queue Pointer points to the next data item to be removed. • The End of Queue Pointer points to the last data item added. • The queue is circular so that locations can be reused. Describe how the data items Orange and Yellow are added to the queue shown in the diagram.
The following diagram shows the state of the queue after several operations have been performed. All queue locations have been used at least once. State the number of data items in the queue.
The design of the queue is completed and the number of locations is increased. A function AddToQueue() has been written. It takes a string as a parameter and adds this to the queue. The function will return TRUE if the string was added successfully. A procedure FileToQueue() will add each line from the file to the queue. This procedure will end when all lines have been added or when the queue is full. Describe the algorithm for procedure FileToQueue(). Do not use pseudocode in your answer.
A function GetNum() will: 1. take two parameters: a string and a character 2. count the number of times that the character occurs in the string 3. return the count. Any comparison between characters needs to be case sensitive. For example, character 'a' and character 'A' are not identical. Write pseudocode for function GetNum().
A programmer has produced the following pseudocode to output the square root of the numbers from 1 to 10. Line numbers are for reference only. 10 DECLARE Num : REAL 11 Num <- 1.0 ... 40 REPEAT 41 CALL DisplaySqrt(Num) 42 Num <- Num + 1.0 43 UNTIL Num > 10 ... 50 PROCEDURE DisplaySqrt(BYREF ThisNum : REAL) 51 OUTPUT ThisNum 52 ThisNum <- SQRT(ThisNum) // SQRT returns the square root 53 OUTPUT " has a square root of ", ThisNum 54 ENDPROCEDURE The pseudocode is correctly converted into program code. Function SQRT() is a library function and contains no errors. The program code compiles without errors, but the program gives unexpected results. These are caused by a design error.
Explain why the program gives unexpected results.
Explain why the compiler does not identify this error.
Describe how a typical Integrated Development Environment (IDE) could be used to identify this error.
The pseudocode is converted into program code as part of a larger program. During compilation, a complex statement generates an error. The programmer does not want to delete the complex statement but wants to change the statement so that it is ignored by the compiler. State how this may be achieved.
A procedure Square() will take an integer value in the range 1 to 9 as a parameter and output a number square. The boundary of a number square is made up of the character representing the parameter value. The inside of the number square is made up of the asterisk character (*). The pseudocode OUTPUT command starts each output on a new line. For example, the following three OUTPUT statements would result in the outputs as shown: OUTPUT "Hello" OUTPUT "ginger" OUTPUT "cat" Resulting output: Hello ginger cat Write pseudocode for procedure Square(). Parameter validation is not required.
A computer system for a shop stores information about each customer. The items of information include name and address (both postal and email) together with payment details and order history. The system also stores the product categories they are interested in and how they would like to be contacted.

The shop wants to add a program module that will generate emails to be sent to customers who may be interested in receiving details of new products. State three items of information that the new module would need. Justify your choice in each case. Information Justification Information Justification Information Justification
Identify two items of customer information that would not be required by the new module. Justify your choice in each case. Information Justification Information Justification
The program includes a module to validate a Personal Identification Number (PIN). This is used when customers pay for goods using a bank card. A state‑transition diagram has been produced for this module. The table show the inputs, outputs and states for this part of the program: Complete the state‑transition diagram to represent the information given in the table.
A computer shop assembles computers using items bought from several suppliers. A text file Stock.txt contains information about each item. Information for each item is stored as a single line in the Stock.txt file in the format: <ItemNum><SupplierCode><Description> Valid item information is as follows: The file is organised in ascending order of ItemNum and does not contain all possible values in the range. A programmer has started to define program modules as follows:
Write pseudocode for module CheckInfo(). Module OnlyAlpha() should be used as part of your solution.
A new module is defined as follows: As a reminder, the file Stock.txt is organised in ascending order of ItemNum and does not contain all possible values in the range. Write pseudocode for module AddItem().
The program contains modules SuppExists() and CheckSupplier(). These have been written but contain errors. These modules are called from several places in the main program and testing of the main program (integration testing) has had to stop. Identify a method that can be used to continue testing the main program before the errors in these modules have been corrected and describe how this would work. Method Description






