• Home
  • Textbooks
  • AS and A Level OCR Computer Science
  • Programming techniques

AS and A Level OCR Computer Science

PM Heathcote, RSU Heathcote, PG Online

Chapter 11

Programming techniques - all with Video Answers

Educators


Section 53

Programming basics

02:23

Problem 1

A school keeps data about each of its pupils. State the most suitable data type for each of the following data items:
Pupil's surname
A single letter indicating whether they are male or female
The amount owed for school trips
The number of school trips they have participated in
Whether or not the pupil is entitled to free school meals

James Kiss
James Kiss
Numerade Educator
03:47

Problem 2

(a) Write pseudocode for a program which asks the user to enter the total bill for a restaurant meal, and the total number of people who had a meal. The program should add $10 \%$ to the bill as a tip, and then calculate and display to the nearest penny what each person owes, assuming the bill is evenly split.
(b) Complete the following table showing an additional two sets of test data, the reason for each test and the expected result.
$$
\begin{array}{|c|c|l|c|}
\hline \text { Total bill } & \text { Number of people } & \text { Reason for test } & \text { Expected result } \\
\hline 100.00 & 10 & \begin{array}{l}
\text { Total amount exactly divisible by } \\
\text { number of people }
\end{array} & 11.00 \\
\hline & & & \\
\hline & & & \\
\hline
\end{array}
$$

Harriet O'Brien
Harriet O'Brien
Numerade Educator
01:47

Problem 3

(a) Name two ways in which you can help to make your programs understandable to another programmer.
(b) Imagine that you have had a stall at the Summer Fayre. At the end of the day you count up the number of each $1 p, 2 p, 5 p, 10 p, 20 p$ and $50 p$ coins you have received.
Write a pseudocode algorithm to allow the user to input the number of coins of each value, and to calculate and display the total takings.
Make use of two ways of making the program understandable given in your answer to part (a)

Daniel Carr
Daniel Carr
Numerade Educator
02:52

Problem 4

Below is an algorithm that adds VAT to the net price of an item and outputs the total price.
VATRATE $=20 / /$ rate of VAT, currently $20 \%$
NetPrice: Real // net price is price without VAT
PriceWithVAT: Real // total price is price including VAT
AmountofVAT: Real // amount of VAT to be added
NetPrice = input ("Enter net price: ")
AmountofVAT = NetPrice * VATRATE / 100
PriceWithVAT = NetPrice + AmountofVAT
print (AmountofVAT)
print(PriceWithVAT)
VATRATE $=20 / /$ rate of VAT, currently $20 \%$
NetPrice: Real // net price is price without VAT
PriceWithVAT: Real // total price is price including VAT
AmountofVAT: Real // amount of VAT to be added
NetPrice = input ("Enter net price: ")
AmountOfVAT = NetPrice * VATRATE / 100
PriceWithVAT $=$ NetPrice + AmountofVAT
print (AmountOfVAT)
print (PriceWithVAT)
(a) Write down one example of the following from the above algorithm:
(i) a constant;
(ii) a variable;
(iii) a comment
(b) Suggest three standards for naming variables, and give two reasons why such standards are useful.

Rachel Lepak
Rachel Lepak
Numerade Educator