0% found this document useful (0 votes)
23 views

Programming Worksheet 1

Uploaded by

iwujiterry3
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Programming Worksheet 1

Uploaded by

iwujiterry3
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Worksheet 1 Programming concepts

Unit 6 Programming

Worksheet 1 Programming concepts


Task 1
1. The flowchart depicts an algorithm for computing the monthly bill for calls on a
mobile phone.

Start

MonthlyTariff=23.00

TotalCharge =
MonthlyTariff

Input
MinutesUsed

No
MinutesUsed>600?

Yes

ExtraMinutes =
MinutesUsed - 600

ExtraCharge =
ExtraMinutes *
PerMinuteRate

TotalCharge =
TotalCharge +
ExtraCharge

Output
TotalCharge

End

1
Worksheet 1 Programming concepts
Unit 6 Programming

(a) Explain how the total monthly charge is calculated.

Montly charge =TotalCharge + ExtraCharge

(b) State whether each of the following variables should be declared as a variable or a
constant, and what data type they should be given. Give reasons for your choice of
data type in each case.

Variable or Data type?


Identifier
constant? Typical value?

MonthlyTariff Constant Integer because it is 23

Integer because it is first assigned a value


TotalCharge Variable
of 23.00
Integer because minutes are numbers
MinutesUsed Variable

Integer because the user will input an


ExtraMinutes Variable
integer
Integer because the user will input a
PerMinuteRate Constant
number
Integer because it is the product of two
ExtraCharge Variable
integers

(c) Assume the basic monthly tariff is £23.00 per month, and that extra minutes are
charged at 2p per minute. A customer makes calls totalling 700 minutes on their phone.
What is their total change that month?

223

2. Write pseudocode for an algorithm which calculates how much money a student will need
to buy a meal and two drinks. The user should be prompted to enter how much a meal
costs, how much a drink costs, and then calculate and display the total required.

Meal_cost = int(input("How much does a meal cost? "))

Drink_cost = int(input("How much does a drink cost? "))

print("Welcome to the Terry restaurant")

Drink_Order = int(input("How many drinks do you want?"))

2
Worksheet 1 Programming concepts
Unit 6 Programming
Meal_Order = int(input("How many meals do you want?"))

Total_cost = (Meal_cost * Meal_Order) + (Drink_cost * Drink_Order)

print(f"Your total cost is: $ {Total_cost}")

Task 2
3. What is output by the following algorithm if the user inputs 3, 8, 10?

print ("Please enter values for a, b and c")


a = input()
b = input()
c = input()
x = a * b + c
y = (b + c) / a
z = x DIV y
w = x MOD y
x = x + y
print (x, y, z, w) 34, 6, 5.6, 204, 40

Task 3
4. Write pseudocode for an algorithm which allows the user to enter their name in the format
“firstname surname”, and outputs the name in the format “initial surname”
e.g. Jim Daley will be out put as J Daley.
Assume the string in indexed from 0, so the first character in the string StrExp will be
referred to as StringExp[0].
Make use of concatenation and the following functions:
len (String Exp) finds the length of StringExp
pos (StringExp, CharExp) finds the position of a character within a string
substring(IntExp, IntExp, StringExp) e.g. substring(3, 5, “Harriet”) evaluates to “rie”)

3
Worksheet 1 Programming concepts
Unit 6 Programming

4
Worksheet 1 Programming concepts
Unit 6 Programming

5. The ASCII values for the letters ‘a’, ‘b’, ‘c’, ‘x’, ‘y’ and ‘z’ are given in the table below.

Letter ASCII value


a 97
b 98
c 99
: :
x 120
y 121
z 122

The Caesar cipher is a simple way of encrypting a message so that it cannot be read
without first decrypting it.

Each letter of the alphabet is replaced by a letter one or more places further along the
alphabet. For example, with a shift of 2, a is replaced by c, b by d,…. y by a and z by b.

Complete the pseudocode statements at (A), (B) and (C) for an algorithm which accepts a
character from the user, applies a shift of 3 characters and outputs the encrypted character.

plaintext = ("Please enter character: ")


codedASCII = (A)
if codedASCII >= 122 then
(B)
endif
codedChar = (C)
print (codedChar)

State what will be output if the user enters the letters

(i) a

(ii) x

You might also like