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

Algorithms Worksheet 4 Data Types and Arrays

Uploaded by

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

Algorithms Worksheet 4 Data Types and Arrays

Uploaded by

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

Worksheet 4 Data types and arrays

Task 1
1. The flowchart depicts an algorithm for computing the monthly bill for calls on a mobile
phone.The tariff is as follows:

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
(a) Explain how the total monthly charge is calculated.

____________________________________________________________________

____________________________________________________________________

____________________________________________________________________

____________________________________________________________________

(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 in
each case.

Variable or Data type?


Identifier
constant? Typical value?

MonthlyTariff

TotalCharge

MinutesUsed

ExtraMinutes

PerMinuteRate

ExtraCharge

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

____________________________________________________________________

(c) A second customer makes calls totalling 611.375 minutes. What is their total charge
this month?

___________________________________________________________________ _

(d) Rewrite the statement


TotalCharge = TotalCharge + ExtraCharge
so that it displays TotalCharge rounded to two decimal places.

______________________________________________________________________

2
2. What value is returned in x by each of the following function calls?
(a) x = int (4.567) ___________________________

(b) x = round (345.862, 0) ____________________

(c) x = float (“37.53”) ________________________

(d) x = sqrt (36) ____________________________

3. Write pseudocode for a program which simulate throwing two dice and then outputs the
number on each die and the total of the two dice.

Task 2

3. Julie has collected data on the rainfall for each month of the year. She is writing a program
to print these out in a list, e.g.

January 15.0
February 13.8
March 20.5
etc.

She has defined an array Months [“January”, “February”, “March”, “April”, “May”,
“June”, “July”, “August”, “September”, “October”, “November”, “December”]
She wants to allow the user to input the monthly rainfall into an array rainfall[1..12].
Write pseudocode for inputting the data in Julie’s program, prompting the user with
statements such as “Enter rainfall for January”, “Enter rainfall for February”, etc., and then
prints the data in a list.
Extension
Write pseudocode to input the monthly rainfall. and print
 a list of each month’s rainfall
 the total annual rainfall to one decimal place
 the monthly average over a year
 the number of months that have rainfall above the average value.

You might also like