Write pseudocode to increment the value held in the variable score
by one.
Did this page help you?
Write pseudocode to increment the value held in the variable score
by one.
Did this page help you?
A fast food restaurant offers half-price meals if the customer is a student or has a discount card. The offer is not valid on Saturdays. A computer system is used to identify whether the customer can have a half-price meal.
The table identifies the three inputs to the computer system:
Input | Value |
---|---|
A | Is a student |
B | Has a discount card |
C | The current day is Saturday |
The restaurant adds a service charge to the cost of a meal depending on the number of people at a table. If there are more than five people 5% is added to the total cost of each meal.
Customers can also choose to leave a tip, this is optional and the customer can choose between a percentage of the cost, or a set amount.
Identify all the additional inputs that will be required for this change to the algorithm.
Did this page help you?
Write a pseudocode statement to assign the value 7.3
to a variable with the identifier timer
State the most appropriate data type for the variable timer
Did this page help you?
The algorithm for one section of a vending machine program is shown in pseudocode.
if money >= price then
venditem()
giveChange(money – price)
else
print("Error – not enough money inserted")
endif
Give the identifier of one variable used in the algorithm.
State how many parameters are passed into the giveChange()
subroutine.
Did this page help you?
A programmer creates an algorithm using a flow chart.
Complete the table to give the output when each of the following set of values are input into the algorithm as X and Y.
Input value of X | Input value of Y | Output |
---|---|---|
15 | 10 | |
6 | 5 | |
2 | 3 | |
12 | 2 |
Did this page help you?
A programmer has written an algorithm to output a series of numbers. The algorithm is shown below:
01 for k = 1 to 3
02 for p = 1 to 5
03 print (k + p)
04 next p
05 next k
06 m = 7
07 print m * m
Describe what is meant by a variable.
Identify two variables that have been used in the algorithm above.
Did this page help you?
A program creates usernames for a school. The first design of the program is shown in the flowchart in Fig. 2.
Fig. 2
For example, using the process in Fig. 2, Tom Ward’s username would be TomWa.
State, using the process in Fig. 2, the username for Rebecca Ellis.
Did this page help you?
A hotel car park charges £4 per hour. If the car is electric, this price is halved to £2 per hour.
Write an algorithm to:
take as input the number of hours the user has parked and whether their car is electric or not
calculate and output the total price
repeat continually until the user enters 0 hours.
You must use either:
OCR Exam Reference Language, or
a high level programming language that you have studied.
Did this page help you?
A program needs to perform the following tasks:
Input two numbers from the user
Compare both numbers and output the largest number.
Complete the pseudocode for this program.
num1 = ………………………………………………
num2 = input("enter second number")
……………………… num1 > ……………………… then
………………………………………………
else
………………………………………………
endif
A second program needs to perform the following tasks:
Input a number from the user
Double the number input and print the result
Repeat bullets 1 and 2 until the user enters a number less than 0.
Write an algorithm for this program.
Did this page help you?
The following program uses a condition-controlled loop.
x = 15
y = 0
while x > 0
y = y + 1
x = x – y
endwhile
print(y)
Complete the trace table to test this program.
|
|
|
---|---|---|
Did this page help you?
Ali’s computer uses virtual memory. Ali has written two procedures to help himself understand how virtual memory works.
storeData()
describes how data is stored in RAM. accessData()
describes how data is read from RAM
Write the letter of the missing statements from the table in the correct place to complete the algorithms.
Not all statements are used, and some statements might be used more than once.
procedure storeData()
if RAM is ......................... then
move data from RAM to ...............................
endif
store data in next free space in .........................
....................................................
procedure accessData()
if .................... (data required is in RAM) then
if RAM is full then
move unneeded data from RAM to HDD
endif
move required data from HD to RAM
endif
read data from ...................
endprocedure
Letter | Statement |
---|---|
A |
|
B |
|
C |
|
D |
|
E |
|
F |
|
G |
|
H |
|
Did this page help you?
Dru writes the following program using a high-level language.
01 function newscore(a,b)
02 temp = a*b
03 temp = temp + 1
04 return temp
05 endfunction
06 score = 18
07 name = "Dru"
08 print (score)
09 print ("name")
10 print (newscore(score,2))
11 print (score)
The following table contains the program code for each line where this program outputs values.
State the values output by the program on each of the lines.
Line | Program code | Value output |
---|---|---|
08 |
| |
09 |
| |
10 |
| |
11 |
|
Did this page help you?
A vending machine can be in one of three states: on, off or suspended. A user can change the state of the vending machine by using the following algorithm.
newstate = input("Enter the new state : ")
switch newstate:
case "on":
statevalue = 1
case "off":
statevalue = 2
case "suspended":
statevalue = 3
default: print("Invalid state")
endswitch
Rewrite the algorithm to perform the same actions using IF statements in place of the switch statement.
Did this page help you?
A programmer has written an algorithm to output a series of numbers. The algorithm is shown below:
01 for k = 1 to 3
02 for p = 1 to 5
03 print (k + p)
04 next p
05 next k
06 m = 7
07 print m * m
Give the first three numbers that will be printed by this algorithm
State how many times line 03 will be executed if the algorithm runs through once.
Did this page help you?
A fast food restaurant offers half-price meals if the customer is a student or has a discount card.
The offer is not valid on Saturdays.
A computer system is used to identify whether the customer can have a half-price meal.
The table identifies the three inputs to the computer system:
Input | Value |
---|---|
A | Is a student |
B | Has a discount card |
C | The current day is Saturday |
The restaurant needs an algorithm designing to help employees work out if a customer can have a half price meal or not. It should:
input required data
decide if the customer is entitled to a discount
output the result of the calculation.
Design the algorithm using a flowchart.
Did this page help you?
Each member of staff that works in a restaurant is given a Staff ID. This is calculated using the following algorithm.
01 surname = input("Enter surname")
02 year = input("Enter starting year")
03 staffID = surname + str(year)
04 while staffID.length < 10
05 staffID = staffID + "x"
06 endwhile
07 print("ID " + staffID)
Complete the following trace table for the given algorithm when the surname “Kofi” and the year 2021 are entered.
You may not need to use all rows in the table.
Line number | surname | year | staffID | Output |
---|---|---|---|---|
01 | Kofi | |||
02 | 2021 | |||
Did this page help you?
Jack is writing a program to add up some numbers. His first attempt at the program is shown.
a = input("Enter a number")
b = input("Enter a number")
c = input("Enter a number")
d = input("Enter a number")
e = input("Enter a number")
f = (a + b + c + d + e)
print(f)
Jack decides to improve his program. He wants to be able to input how many numbers to add together each time the algorithm runs, and also wants it to calculate and display the average of these numbers.
Write an algorithm to:
ask the user to input the quantity of numbers they want to enter and read this value as input
repeatedly take a number as input, until the quantity of numbers the user input has been entered
calculate and output the total of these numbers
calculate and output the average of these numbers.
Did this page help you?
When a new booking is recorded, the details are entered into a program to validate the values. The following criteria are checked:
firstName
and surname
are not empty
room
is either “basic” or “premium”
nights
is between 1 and 5 (inclusive).
If any invalid data is found “NOT ALLOWED” is displayed. If all data is valid “ALLOWED” is displayed.
Complete the following program to validate the inputs.
firstName = input("Enter a first name")
surname = input("Enter a surname")
room = input("Enter basic or premium")
nights = input("Enter between 1 and 5 nights")
stayComplete = False
You must use either:
OCR Exam Reference Language, or
a high-level programming language that you have studied.
Did this page help you?
A program creates usernames for a school. The first design of the program is shown in the flowchart in Fig. 2.
Fig. 2
The program design is updated to create usernames as follows:
If the person is a teacher, their username is the last 3 letters of their surname and then the first 2 letters of their first name.
If the person is a student, their username is the first 3 letters of their first name and then the first 2 letters of their surname.
What would be the username for a teacher called Fred Biscuit using the updated process?
Write an algorithm for the updated program design shown in part(a).
Did this page help you?
Data for one week (Monday to Friday) is stored in a 2D array with the identifier minsPlayed
.
The following table shows part of this array, containing 4 students.
The teacher writes a program to add up and print out the total number of minutes student 2 played computer games over 5 days (Monday to Friday).
total = 0
total = total + minsPlayed[2,0]
total = total + minsPlayed[2,1]
total = total + minsPlayed[2,2]
total = total + minsPlayed[2,3]
total = total + minsPlayed[2,4]
print(total)
Refine the program to be more efficient. Write the refined version of the algorithm.
You must use either:
OCR Exam Reference Language, or
a high-level programming language that you have studied.
The following flowchart outputs a message depending on how long each person has spent playing computer games.
Rewrite the flowchart as a program.
You must use either:
OCR Exam Reference Language, or
a high-level programming language that you have studied.
Did this page help you?
Taylor is writing an algorithm to record the results of an experiment.
Taylor needs to be able to enter a numeric value which is added to a total which initially starts at 0.
Every time she enters a value, the total is output.
The algorithm repeats until the total is over 100.
Write an algorithm to implement Taylor’s requirements.
Did this page help you?
For the next part of the experiment, Taylor needs to be able to enter 10 values and count how many of the values are over 50, outputting this value once all values have been entered.
Complete the following flowchart to implement this algorithm
Write a pseudocode algorithm that uses iteration to allow Taylor to:
enter 10 values
count how many values are over 50
output the count of values over 50 after all 10 values are entered.
Did this page help you?
OCRBlocks is a game played on a 5 × 5 grid. Players take it in turns to place blocks on the board. The board is stored as a two-dimensional (2D) array with the identifier gamegrid
Fig. 6.1 shows that players A and B have placed three blocks each so far
Write an algorithm to allow player A to select a position for their next block on the game board.
The algorithm must:
ask the player for the position of their block on the board
use the checkblock()
function to check if this position is free
if the position is free, add the letter "A" to the position chosen in the gamegrid
array
if the position is not free, repeat the above steps until a free position is chosen.
Did this page help you?
The algorithm for one section a the vending machine program is shown in pseudocode
if money >= price then
venditem()
giveChange(money – price)
else
print("Error – not enough money inserted")
endif
Draw the vending machine algorithm as a flowchart.
Did this page help you?
The following names of students are stored in an array with the identifier studentnames.
studentnames = ["Rob", "Anna", "Huw", "Emma", "Patrice", "Iqbal"]
A school uses the array to call an attendance register every morning.
Write an algorithm using iteration to:
display the name of each student one at a time from studentnames
take as input whether that student is present or absent
display the total number of present students and number of absent students in a suitable message, after all student names have been displayed.
Did this page help you?
One encryption method is a Caesar cipher.
This Caesar cipher moves each letter of the alphabet one place to the right.
The following table shows the original letters in the first row, and the new letters in the second row.
For example, if the message read: HELLO
This would be stored as: IFMMP
The following pseudocode algorithm takes a string of uppercase letters as input and uses the Caesar cipher to encrypt them.
The functions used in the algorithm are described in the table:
Function | Description |
| Returns the ASCII value for character e.g. A |
| Returns the single character for ASCIIvalue e.g. |
| Returns the Number of characters starting at position Value (where 0 is the first character) |
Complete the pseudocode algorithm to perform a Caesar cipher.
01 message = input("Please enter your string")
02 newMessage = ""
03 messageLength = message.length
04 for count = 0 to............................
05 ASCIIValue = ASC(message.subString(...............,1))
06 ASCIIValue = ASCIIValue + ..........
07 if ASCIIValue >90 then
08 ASCIIValue = ................................ – 26
09 endif
10 newMessage = .................... + CHR(ASCIIValue)
11 next count
The algorithm needs adapting. An extra line (line 12) is needed to output the encrypted message.
Write line 12 to output the encrypted message in pseudocode or programming code.
Did this page help you?
Write this algorithm using pseudocode.
Did this page help you?
A single record from this database table is read into a program that uses an array with the identifier studentdata. An example of this array is shown below:
studentdata = [“Kirstie”, “Homework forgotten”, “-2”, “FALSE”]
The array is zero based, so studentdata[0]
holds the value “Kirstie”.
Write an algorithm that will identify whether the data in the studentdata
array shows that a letter has been sent home or not for the student. The algorithm should then output either “sent” (if a letter has been sent) or “not sent” (if a letter has not been sent).
Did this page help you?
Using pseudocode, write an algorithm that will use a count-controlled loop to print out the numbers 1 to 10 in ascending order.
Did this page help you?
OCR town are holding an election with three candidates (A, B and C). An electronic voting booth will be used to allow people to vote.
Write an algorithm that:
Allows voters to enter either A, B or C.
Keeps track of how many times each candidate has been voted for.
As soon as one person has finished voting, allows the next person to vote.
At any point allows the official to type in “END”, which will print out the number of votes for each candidate and the total number of votes overall.
Did this page help you?