Professional Documents
Culture Documents
Pseudocode With VB by Farhan Rahmat
Pseudocode With VB by Farhan Rahmat
Structure
Flow Chart Pseudocode
Diagram
Non- Iterative
Iterative
Formula/Value
Totaling Counting Extreme Values
Calculation
Description Flow Chart Symbol Pseudocode VB/VB.Net
[Variable Name] Initial Value DIM [Variable Name] As Data Type = Initial Value
TempA0 Example: Example:
Variable Declaration & Initialization TempB0 TempA0 DIM TempA As Integer=0
Weather” “ TempB0 DIM TempB As Integer =0
Weather” “ DIM Weather As String=” “
IF { conditional statement }
THEN IF { conditional statement } THEN
{ statement 1 } { statement 1 }
No ELSE ELSE
Yes is
{ statement 2 } { statement 2 }
TempB<20
? ENDIF ENDIF
Highest
TempB (Note: ENDIF is not needed if the whole (Note: End If is not needed if the whole IF….THEN
IF….THEN statement is written on a single line.) statement is written on a single line.)
Foggy
Foggy+1 Example:
Module Module1
Sub Main()
IF Weather =”Foggy” THEN FoggyFoggy+1 DIM Weather as String
IF Weather =”Cloudy” THEN CloudyCloudy+1 DIM Foggy as Integer=0
No IF Weather =”Rainy” DIM Cloudy as Integer=0
Yes is THEN
Weather=
DIM Rainy as Integer=0
”Cloudy” Rainy Rainy +1 DIM Sunny as Integer=0
? Else Weather=Console.ReadLine()
Selection Sunny Sunny +1 Select Weather
Cloudy ENDIF Case "Foggy"
Cloudy+1 Foggy=Foggy+1
Case "Cloudy"
Cloudy=Cloudy+1
Case "Rainy"
Rainy=Rainy+1
Yes is
No Case Else
Weather= Sunny=Sunny+1
”Rainy” End Select
?
Console.WriteLine (Foggy)
Console.WriteLine (Cloudy)
Rainy Sunny
Rainy+1 Sunny +1 Console.WriteLine (Rainy)
Console.WriteLine (Sunny)
End Sub
End Module
(You can try this code online at
http://ideone.com/EOBwlK,)
Yes
is
Foggy Weather=
Foggy +1 ”Foggy”
?
CASE OF [Variable Name ]
expression : statement
No expression : statement
expression : statement
OTHERWISE statement
is
ENDCASE
Cloudy Weather=
Cloudy +1 ”Cloudy” Example:
?
CASE OF Weather
“Foggy” : FoggyFoggy+1
”Cloudy”: CloudyCloudy+1
”Rainy” : RainyRainy+1
OTHERWISE SunnySunny+1
is
ENDCASE
Rainy Weather=
Rainy+1 ”Rainy”
?
Foggy
Foggy +1
Start
Count 0
Counter could be
Yes
Count=100
Count, X, etc.
Counter could be
DIM Counter As Datatype
Count, X, etc.
No
FOR Counter = Start TO End
-------- Things to do within
Output FOR Counter Start TO End
"Hello World" -------- loop
-------- Things to do within --------
-------- loop --------
--------
Count Count + 1 --------
--------
NEXT
-------- Things to do outside
--------
NEXT the loop
Things to do --------
Iteration (Count Based Loop) --------
outside the loop --------
--------
End Example:
--------
Print “Hello World” 100 times:
Module Module1
Example:
Sub Main()
OUTPUT “Hello World” 100 times:
Dim Count As Integer
For Count= 1 To 100
FOR Count=1 TO 100
Console.WriteLine("Hello World”)
OUTPUT “Hello World”
Next
NEXT
End Sub
End Module
Start
Count 0
Input
Code
Count0
CountA0
CountB0 2) Here we decide the variables to be
TempA0
TempB0 used and initialized them. All numerical
Total0 variable will be initialized with 0 except
Avg0
Highest0 for lowest that will be initialized with
Lowest1000 1000.
11) Always
Calculate 3) Start of the loop. Set loop exit
Yes
Average outside is
loop. Count=100 condition i.e. Count=100 if you
?
have to input temperature over
100 days.
AvgTotal/100
No 4) Input
Command
Input
TempA
5) Value
Output
Avg,
calculation if
CountA, TempB (TempA-32)/1.8 required.
CountB
Highest,
Lowest
6) Output
result only if
Output point 5 exists.
TempB
13) End of End
Flowchart 7) Add the input value or
Total Total +TempB result of value calculated if
average has been asked to
calculate
12) Always Print
Average, 8) Set the counting condition
Counting if tally is required and
No
Yes is
Variables, and
TempB<20
increment the respective
Extreme Values ? counting variable with 1.
outside the loop.
CountA CountB
CountA+1 CountB+1
Question: Write an algorithm in the
form of a flowchart which takes
temperatures input in Fahrenheit
over a 100 day period (once per 9) If extreme values such as
day). Convert the temperature in Yes
is
No Highest/Lowest,
Celsius with the help of following TempB>Hi Tallest/Shortest,
ghest
formula: ? Maximum/Minimum is
Temp (in Celsius)=(Temp (in required.
Fahrenheit) - 32)/1.8 Highest
and output temperature in Celsius, TempB
also print:
(b) number of days when the
temperature was below 20C
and the number of days when
Yes No
the temperature was 20C and is
TempB<Lo
above. west
(c) average temperature of 100 ?
days.
(d) the highest and lowest Lowest
TempB
temperature recorded in these
100days.
10) Increment the loop
counter by 1 for the next
Count Count+1
iteration and go back to loop
exit condition.
Start
Initialization Box
Input Value
Value Calculation
Output Result
Totaling
(Add Input value or result to
Total Variable)
Initialization
Yes Counting No
Condition Check
([Variable]Initial Value)
For Count Starting Value to End Value
Increment the Increment the
Input [Variable]
counter by 1 counter by 1
period (once per day). Convert the Total0 Dim Highest As Integer=0
Input
temperature in Celsius with the help of TempA Dim Lowest As Integer=1000
Avg0
following formula: For Count= 1 To 100
Temp (in Celsius)=(Temp (in TempB (TempA - Highest0 TempA=Console.ReadLine()
32) / 1.8
Fahrenheit) - 32)/1.8 Lowest1000 TempB=(TempA-32)/1.8
and output temperature in Celsius,
Output
TempB
FOR Count 1 TO 100 Console.WriteLine (TempB)
also print: Total=Total+TempB
(b) number of days when the Total Total + TempB INPUT TempA If TempB < 20 Then
temperature was below 20C and TempB (TempA-32)/1.8 CountA=Count+1
the number of days when the
Yes No
TempB<20
OUTPUT TempB Else
temperature was 20C and above. CountB=CountB+1
(c) average temperature of 100 days. TotalTotal+TempB
End If
CountA CountA + 1 CountB CountB + 1
(d) the highest and lowest IF TempB < 20 THEN If TempB>Highest Then Highest=TempB
temperature recorded in these
CountACountA+1 If TempB<Lowest Then Lowest=TempB
100days.
Yes No
TempB>Highest
Next
ELSE
Variables to be to Store/Count Avg=Total/100
HighestTempB CountBCountB+1 Console.WriteLine(Avg & CountA & CountB &
used
Count No of iteration ENDIF Highest & Lowest)
TempA Temp in Fahrenheit Yes No
End Sub
TempB<Lowest
IF TempB>Highest THEN HighestTempB
TempB Temp in Celsius End Module
Number of days IF TempB<Lowest THEN LowestTempB
CountA
temp was below 20 Lowest TempB
NEXT
Number of days (You may try this code online at
CountB temperature was 20 AvgTotal/100
Count Count + 1 http://ideone.com/6su9L2 ,simply fork it and then
and above OUTPUT Avg, CountA, CountB, Highest, Lowest
Running sum of 100 Run)
Total
days temperature
Average Avg Total/100
Avg temperature of
100days Output
Avg, CountA, CountB,
Highest temperature Highest, Lowest
Highest
in 100 days
Lowest temperature End
Lowest
in 100 days
Start
Num0
Write an algorithm, using Count0
pseudocode or a flowchart, which CountA0
Largest00
• inputs 50 positive numbers
• outputs how many of the
numbers were > 100 Yes
Count=50 Module Module1
• Outputs the value of the No Sub Main()
largest (highest) number DIM Num As Integer=0
Num0
input Input
Num DIM Count As Integer=0
Count0
DIM CountA As Integer=0
Yes No CountA0
Num>100 DIM Largest As Integer=0
Largest0
For Count= 1 To 50
FOR Count1 TO 50
Num=Console.ReadLine()
CountA CountA + 1 INPUT Num
If Num>100 Then CountA=CountA+1
IF Num>100 THEN CountACountA+1
If Num>Largest Then Largest=Num
Yes No IF Num>Largest THEN LargestNum
Num>Largest
Next
NEXT
Console.WriteLine (CountA & Largest)
OUTPUT CountA, Largest
End Sub
Largest Num
End Module
Count Count + 1
End
1) Start of
Start Flowchart
Count0
CountA0
CountB0 2) Here we decide the variables to be
TempA0
TempB0 used and initialized them. All numerical
Total0 variable will be initialized with 0 except
Avg0
Highest0 for lowest that will be initialized with
Lowest1000 1000.
Day” “
3) Input
Input
Command
Day,
TempA
12) Always
Calculate 4) Start of the loop. Use input
Yes
Average outside Day=
loop.
variable to set loop exit condition
”Friday”
?
i.e. Day=”Friday” or Num=-1 etc.
No 5) Value
AvgTotal/Count
calculation if
TempB (TempA-32)/1.8 required.
Output
6) Output
Avg, result only if
CountA, Output point 5 exists.
CountB TempB
Highest,
Lowest
7) Add the input value or
Total Total +TempB result of value calculated if
average has been asked to
14) End of End calculate
Flowchart
8) Nothing to do with loop
Count Count+1
but required for computing
Average.
13) Always Print
Average, 9) Set the counting condition
Counting No
if tally is required and
Yes is
Variables, and
TempB<20
increment the respective
Extreme Values ? counting variable with 1.
outside the loop.
CountA CountB
CountA+1 CountB+1
days.
Lowest
(d) the highest and lowest TempB
temperature recorded in these
100days.
11) Input command for next
Input
Day, iteration before returning to
TempA loop,
Start
Initialization Box
Input Value
Value Calculation
Output
Calculate Average Result
(Avg Total/Count)
Totaling
Output (Add Input value or result to
Avg, CountA, CountB, Total Variable)
Highest, Lowest
Count Count + 1
(to calculate average)
End
Initialization
Yes Counting Condition No
Check [Variable]Initial Value)
Input [Variable]
Increment the Increment the
counter variable by 1 counter variable by 1 While [Variable]<> Exit condition
Value Calculation (if required)
Yes Extreme Value No
Check Output Calculated Value ([Variable])
Totaling (if average is required)
Swap the values
(TotalTotal+[Variable])
(CountCount+1)
Yes Extreme Value No
Check Counting based on condition (if sub-set
data to find)
Swap the values
(IF { conditional statement } THEN
CountACountA+1)
Input Value
Extreme values (if highest/lowest to
find)
(IF [Variable]>Highest THEN
Highest [Variable])
(IF [Variable]<Lowest THEN
Lowest [Variable])
Module Module1
Sub Main()
Dim Count As Integer=0
Count0 Dim CountA As Integer=0
CountA0
Dim CountB As Integer=0
CountB0
Question: Write an algorithm in the Dim TempA As Integer=0
TempA0
form of a flowchart which takes Dim TempB As Integer=0
TempB0
temperatures input in Fahrenheit on Dim Total As Integer=0
Total0
certain days (stop by Friday). Convert Dim Avg As Integer=0
Avg0
the temperature in Celsius with the Dim Highest As Integer=0
Highest0
help of following formula: Dim Lowest As Integer=1000
Lowest1000
Temp (in Celsius)=(Temp (in Dim Day As String=” “
Day“ ”
Fahrenheit) - 32)/1.8 Day=Console.ReadLine()
INPUT TempA, Day
and output temperature in Celsius, TempA=Console.ReadLine()
WHILE DAY<>”Friday”
also print: While Day <> “Friday”
(b) number of days when the Do
TempB=(TempA-32)/1.8
temperature was below 20C and TempB (TempA-32)/1.8
Console.WriteLine (TempB)
the number of days when the OUTPUT TempB
Total=Total+TempB
temperature was 20C and above. TotalTotal+TempB
Count=Count+1
(c) average temperature of 100 days. CountCount+1
If TempB < 20 Then
(d) the highest and lowest IF TempA < 20
CountA=Count+1
temperature recorded in these THEN
Else
100days. CountACount+1
CountB=CountB+1
ELSE
End If
Variables to be to Store/Count CountBCountB+1
If TempB>Highest Then Highest=TempB
used ENDIF
Count No of days If TempB<Lowest Then Lowest=TempB
IF TempB>Highest THEN HighestTempB
Day Day of week Day=Console.ReadLine()
IF TempB<Lowest THEN LowestTempB
TempA Temp in Fahrenheit TempA=Console.ReadLine()
INPUT TempA, Day
TempB Temp in Celsius End While
ENDWHILE
Number of days Avg=Total/Count
CountA AvgTotal/Count
temp was below 20 Console.WriteLine(Avg & CountA & CountB &
Number of days OUTPUT Avg, CountA, CountB, Highest, Lowest
Highest & Lowest)
CountB temperature was 20
End Sub
and above
End Module
Running sum of 100
Total
days temperature
Average
Avg temperature of
100days (You may try this code online at
Highest temperature http://ideone.com/MjUhYu , simply fork it and then
Highest
in 100 days Run)
Lowest temperature
Lowest
in 100 days
Start
Count0
CountA0
CountB0
Total0
Avg0
Highest0
Lowest1000
Day“ ”
Input
TempA, Day
Yes Day="Friday"
No
TempB (TempA -
32) / 1.8
Output
TempB
Avg Total/100
Output Total Total +TempB
Avg, CountA, CountB,
Highest, Lowest
Count Count + 1
End
Yes No
TempB<20
CountACountA + 1 CountBCountB + 1
Yes TempB>Highest No
Highest TempB
Yes TempB<Lowest No
LowestTempB
Input
Day, TempA"
Write an algorithm, using
Start
pseudocode or a flowchart, which
• inputs a set of positive
numbers (which end with -1) Num0
CountA0
• outputs how many of the Largest0
numbers were > 100
Module Module1
• outputs the value of the Input
Sub Main()
largest (highest) number Num Num0
DIM Num As Integer=0
input CountA0
Yes Num= - 1 DIM CountA As Integer=0
Largest00
No DIM Largest As Integer=0
INPUT Num
Num=Console.ReadLine()
Yes No WHILE Num<> -1
Num>100
While Num<>-1
Do
If Num>100 Then CountA=CountA+1
IF Num>100 THEN CountACountA+1
If Num>Largest Then Largest=Num
CountA CountA + 1 IF Num>Largest THEN LargestNum
Num=Console.ReadLine()
INPUT Num
End While
ENDWHILE
Yes Num>Largest No
Console.WriteLine (CountA & Largest)
OUTPUT CountA, Largest
End Sub
End Module
Largest Num
Input
Num
OUTPUT
CountA , Largest
End
Write an algorithm, using
pseudocode or a flowchart, which
• inputs a set of positive
Start
numbers (which end with -1)
• outputs the average
(mean) value of the input
Num0
numbers Total0
• outputs the value of the Count0
Module Module1
Largest00
largest (highest) number Avg0 Sub Main()
Num0
input DIM Num As Integer=0
Input Count0
Num DIM Count As Integer=0
Total0
DIM Total As Integer=0
Avg0
Yes
Num= - 1 DIM Largest As Integer=0
Largest0
No Num=Console.ReadLine()
INPUT Num
While Num<>-1
TotalTotal + Num WHILE Num<> -1
Total=Total+Num
Do
Count=Count+1
CountCount + 1 TotalTotal+Num
If Num>Largest Then Largest=Num
CountCount+1
Num=Console.ReadLine()
Yes
Num>Largest No
IF Num>Largest THEN LargestNum
End While
INPUT Num
Avg=Total/Count
ENDWHILE
Largest Num Console.WriteLine (Avg & Largest)
AvgTotal/Count
End Sub
OUTPUT Avg, Largest
End Module
Input
Num
End
Practice Questions:
(1) Daniel lives in Italy and travels to Mexico, India and New Zealand. The times differences are:
Country Hours Minutes
Mexico -7 0
India +4 +30
New Zealand +11 0
Thus, if it is 10:15 in Italy it will be 14:45 in India.
(a) Write an algorithm, using pseudocode or otherwise, which:
• Inputs the name of the country
• Inputs the time in Italy in hours (H) and minutes (M)
• Calculates the time in the country input using the data from the table
• Outputs the country and the time in hours and minutes
(2) As part of an experiment, a school measured the heights (in metres) of all its 500 students.
Write an algorithm, using pseudocode, which inputs the heights of all 500 students and outputs the height of the tallest person and the shortest person in the school.
(3) A geography class decide to measure daily temperatures and hours of sunshine per day over a 12 month period (365 days)
Write an algorithm, using pseudocode, which inputs the temperatures and hours of sunshine for all 365 days, and finally outputs the average (mean) temperature for the year
and the average (mean) number of hours per day over the year.
(4) A small shop sells 280 different items. Each item is identified by a 3 – digit code. All items that start with a zero (0) are cards, all items that start with a one (1) are sweets, all
items that start with a two (2) are stationery and all items that start with a three (3) are toys.
Write an algorithm, using pseudocode, which inputs the 3 – digit code for all 280 items and outputs the number of cards, sweets, stationery and toys.
(5) A company are carrying out a survey by observing traffic at a road junction. Each time a car, bus, lorry or other vehicle passed by the road junction it was noted down.
10 000 vehicles were counted during the survey.
Write an algorithm, using pseudocode, which:
inputs all 10000 responses
outputs the number of cars, buses and lorries that passed by the junction during the survey
outputs the number of vehicles that weren’t cars, buses or lorries during the survey
(6) Speed cameras read the time a vehicle passes a point (A) on the road and then reads the time it passes a second point (B) on the same road (points A and B are 100
metres apart). The speed of the vehicle is calculated using:
The maximum allowed speed is 100 kilometres per hour. 500 vehicles were monitored using these cameras over a 1 hour period.
Calculate the BMI for a person whose weight is 80kg and height is 2 metres. [1]
(b) Using pseudocode or otherwise, write an algorithm that will input the ID, weight (kg) and height (m) of 30 students, calculate their body mass index (BMI) and
output their ID, BMI and a comment as follows:
A BMI greater than 25 will get the comment ‘OVER WEIGHT’, a BMI between 25 and 19 (inclusive) will get ‘NORMAL’ and a BMI less than 19 will get ‘UNDER
WEIGHT’. [6]
20 Temperatures (°C) are being collected in an experiment every hour over a 200 hour period. Write an algorithm, using pseudocode or otherwise, which inputs
each temperature and outputs
• how many of the temperatures were above 20°C
• how many of the temperatures were below 10°C
• the lowest temperature that was input [5]
May/June 2007
19 A company has 5000 CDs, DVDs, videos and books in stock. Each item has a unique 5-digit code with the first digit identifying the type of item, i.e.
1 = CD
2 = DVD
3 = video
4 = book
For example, for the code 15642 the 1 identifies that it is a CD, and for the code 30055 the 3 identifies that it is a video.
What would be the Fuel Economy of a car travelling 40 km on 10 litres of fuel? [1]
(b) The Fuel Economy for 1000 cars is to be calculated using the formula in Question 16(a).
Write an algorithm, using pseudocode or otherwise, which inputs the Distance Travelled (km) and the Fuel Used (litres) for 1000 cars. The Fuel Economy for each
car is then calculated and the following outputs produced:
• Fuel Economy for each car
• average (mean) Fuel Economy for all of the cars input
• the best Fuel Economy (i.e. highest value)
• the worst Fuel Economy (i.e. lowest value) [6]
May/June 20
19 Customers can withdraw cash from an Automatic Teller Machine (ATM).
• withdrawal is refused if amount entered > current balance
• withdrawal is refused if amount entered > daily limit
• if current balance < $100, then a charge of 2% is made
• if current balance $100, no charge is made
Write an algorithm which inputs a request for a sum of money, decides if a withdrawal can be made and calculates any charges. Appropriate output messages
should be included. [5]
Oct/Nov 2008
19 The manufacturing cost of producing an item depends on its complexity. A company manufactures three different types of item, with costs based on the
following calculations:
May/June 2009
18 A small airport handles 400 flights per day from three airlines:
FASTAIR (code FA)
SWIFTJET (code SJ)
KNIGHTAIR (code KA)
Each flight is identified by the airline code and 3 digits. For example FA 156.
Write an algorithm, using pseudocode or otherwise, which monitors the 400 flights into and out of the airport each day. The following inputs, processing and
outputs are all part of the monitoring process:
• input flight identification
• calculate number of flights per day for each of the three airlines
• output the percentage of the total flights per day by each airline
• any validation checks must be included [5]
What is the final speed of a car if it takes 2 hours to get from A to B? [1]
(b) Write an algorithm, using pseudocode or otherwise, which inputs the times for 500 cars, calculates the final speed of each car using the formula in part (a),
and then outputs:
• the final speed for ALL 500 cars
• the slowest (lowest) final speed
• the fastest (highest) final speed
• the average final speed for all the cars. [6]
May/June 2010. P11
18 A group of students were monitoring the temperature every day over a one-year period.
Readings were taken ten times every day (you may assume a year contains 365 days).
(b) Describe, with examples, two sets of test data you would use to test your algorithm. [2]
(b) Describe, with examples, TWO sets of test data you would use to test your algorithm. [2]
Oct/Nov 2011. P11
17 (a) Write an algorithm, using pseudocode or flowchart only, which:
• inputs three numbers
• outputs the largest of the three numbers
(b) Write an algorithm, using pseudocode or flowchart only, which:
• inputs 1000 numbers
• outputs how many of these numbers were whole numbers (integers)
(You may use INT(X) in your answer e.g. Y = INT(3.8) gives the value Y = 3)
16 A small shop uses barcodes which represent 5 digits. The last digit is used as a check digit.
For example:
abcde
01234
The check digit (e) is found by:
• multiplying the first and third digits (i.e. a and c) by 3
• multiplying the second and fourth digits (i.e. b and d) by 2
• adding these four results together to give a total
• dividing this total by 10
• remainder is check digit (e)
Write an algorithm, using pseudocode or flowchart only, which
• inputs 100 five-digit barcodes in the form a, b, c, d, e
• re-calculates the check digit for each number and checks whether the input check digit (e) is correct
• outputs the number of barcodes which were entered correctly [5]
17 A country has four mobile phone network operators. Each mobile phone number has eight digits. The first three digits identify the network operator:
444 Yodafone
555 N2 network
666 Kofee mobile
777 Satsuma mobile
Write an algorithm, using pseudocode or flowchart only, which reads 50 000 eight-digit mobile phone calls made during the day and outputs the number of calls
made on each of the four networks. [6]
16 (a) A greenhouse is being monitored by a computer using 2 sensors. SENSOR1 measures the temperature and SENSOR2 measures oxygen levels.
If the temperature exceeds 45°C or oxygen levels fall below 0.19, then an error message is output by the computer.
Write an algorithm, using pseudocode or flowchart only, which
• inputs both sensor readings
• checks the sensor input values and outputs a warning message if either are out of
range
• continues monitoring until the <ESCAPE> key is pressed
(You may assume that READ SENSORn will take a reading from SENSORn and that
READ KEY inputs a key press from the keyboard). [5]
Oct/Nov 2013. P13
15 5000 numbers are being input which should have either 1 digit (e.g. 5), 2 digits (e.g. 36), 3 digits (e.g. 149) or 4 digits (e.g. 8567).
Write an algorithm, using pseudocode or flowchart only, which
• inputs 5000 numbers
• outputs how many numbers had 1 digit, 2 digits, 3 digits and 4 digits
• outputs the % of numbers input which were outside the range [6]
15 A survey is being carried out which involves reading and recording sound levels near a busy road junction. Once all the data are collected, they are input
manually into a computer. A sound level of 0 decibels (0 dB) is input to indicate the end of the data.
Write an algorithm, using pseudocode or a flowchart, which:
• inputs all the sound levels
• after a sound level of 0 is input, outputs the following:
o average sound level
o highest recorded sound level.
18 A school has 1500 students. It is conducting a survey on their music preferences. Each student uses a computer and inputs their name and then chooses one
of 5 options:
• rock (input value 1)
• soul (input value 2)
• pop (input value 3)
• jazz (input value 4)
• classical (input value 5)
Write an algorithm, using pseudocode or a flowchart, which:
• inputs the choice of all 1500 students (values 1 to 5)
• outputs all the names of the students who chose classical music
• outputs the percentage who chose each option.
Questions:
1 Daniel lives in Italy and travels to Mexico, India and New Zealand. The times differences are:
Country Hours Minutes
Mexico -7 0
India +4 +30
New Zealand +11 0
3(a) A formula for calculating the body mass index (BMI) is:
Calculate the BMI for a person whose weight is 80kg and height is 2 metres.
(b) Using pseudocode or otherwise, write an algorithm that will input the ID, weight (kg) and height (m) of a students, calculate his/her body mass index (BMI)
and output his/her ID, BMI and a comment as follows:
A BMI greater than 25 will get the comment ‘OVER WEIGHT’, a BMI between 25 and 19 (inclusive) will get ‘NORMAL’ and a BMI less than 19 will get ‘UNDER
WEIGHT’.
7 (a) A car’s speed is measured between points A and B, which are 200 km apart.
What is the final speed of a car if it takes 2 hours to get from A to B? [1]
(b) Write an algorithm, using pseudocode or otherwise, which input the time of a cars, calculates the final speed of that car using the formula in part (a), and
then outputs the final speed for that car.