Вы находитесь на странице: 1из 16

PRE-RELEASE MATERIAL

Oct/Nov 2015
O Level Computer Science 2210 Region 4

Abstract
This document provides solution to the Cambridge pre-release material
for Computer Science 2210

1|Page

Pre-Release Material (Oct/Nov15)

Pre-Release Material Tasks


A new born baby is kept in a cot in a hospital; the temperature of the baby is monitored every 10
minutes. The temperature of the baby is recorded in degrees Celsius to one decimal place and must be
within the range 36.0C to 37.5C
TASK 1
To simulate the monitoring required, write a routine that allows entry of the babys temperature in
degrees Celsius. The routine should check whether the temperature is within the acceptable range, too
high or too low and output a suitable message in each case.
TASK 2
Write another routine that stores the temperature taken over a three hour period in an array. This
routine should output the highest and lowest temperature and calculate the difference between the
temperatures.
TASK 3
For a baby who has a temperature difference of more than one degree Celsius, and/or has been outside
the acceptable range more than twice in the three hour period, output a suitable message giving a
summary of the problem.

Your program must include appropriate prompts for the entry of data. Error
messages and other outputs need to be set out clearly and understandably. All
variables, constants and other identifiers must have meaningful names. Each task
must be fully tested.

Prepared by: Blitz Computing

2|Page

Pre-Release Material (Oct/Nov15)

Concept and Understanding of Tasks


All 3 tasks are a part of one big problem i.e. monitoring the baby temperature and print appropriate
warning message according to it. The general flow and algorithm can be understood by the following
diagram.

Variables and arrays declaration

Loop to take input temperature every 10 minutes

Record the temperatures in an array. Record owest and


highest temperature and its difference
Print approrpaite message if the recorded temperature is
outside the specified range or if the difference of
temperature is greater than 1 degrees

Approach to Solution
There can be many approaches to solve these tasks depending upon the understanding of person. We
are listing down the key points that reflect our understanding and well solve these tasks according to
following assumptions.

As written in the starting scenario that inputs are taken at an interval of 10 minutes, a built-in
function Wait will be used in pseudocode and programming statements to achieve this
functionality.
Task 1 have to written as an independent routine/sub-routine and array will not be used to
store values.
Task 2 is also an independent routine/sub-routine. Array will be used to store temperatures and
a loop of 18 iterations (input to be taken after every 10 minutes so 1 hour equals 6 inputs and 3
hours equals 18 inputs) will be used to input the values.
Task 3 is a dependent task and requires input that have already been taken in task 2 but in order
to test task3 completely we will rewrite all the code and make task3 completely independent.

Programming language used to develop solution is Microsoft Visual Basic .NET1, however C language
code is also included at the end of document.
1

Click to download Microsoft Visual Basic .NET Express edition

Prepared by: Blitz Computing

3|Page

Pre-Release Material (Oct/Nov15)

Task 1 Solution (Pseudocode)


ROUTINE TASK1
SET babytemp AS FLOAT
babytemp 0.0
PRINT Enter the cot temperature
INPUT babytemp
IF babytemp < 36.0 THEN
PRINT Temperature is below the limit
ELSE IF babytemp > 37.5 THEN
PRINT Temperature is above the limit
ELSE PRINT Temperature is normal
END IF
END ROUTNE

Key Points

Variable for storing baby


temperature is declared as FLOAT
IF - ELSE statements to select the
appropriate message to print

Explanation

Variable declaration,
datatype used is float
to store decimal values
Print an information
message and take
input of temperature
IF selection
statement to check
whether input lies
within particular range
or not. Then print
appropriate message.

Prepared by: Blitz Computing

4|Page

Pre-Release Material (Oct/Nov15)

Task 1 Solution (Flowchart)

Start

SET babytemp As Float


babytemp
0.0

PRINT Enter the cot temperature


INPUT babytemp

YES
IF babytemp < 36.0

NO

PRINT Temperature
is above the limit

YES
IF babytemp > 37.5

NO
PRINT Temperature
is normal

END

Prepared by: Blitz Computing

PRINT Temperature
is below the limit

5|Page

Pre-Release Material (Oct/Nov15)

Task 1 Solution (VB .NET)


Module Module1
Sub Main()
Dim babytemp As Decimal = 0.0
Console.WriteLine("Enter the cot temperature")
babytemp = Console.ReadLine()
If babytemp < 36.0 Then
Console.WriteLine("Temperature is below the limit")
ElseIf babytemp > 37.5 Then
Console.WriteLine("Temperature is above the limit")
Else
Console.WriteLine("Temperature is normal")
End If
Console.ReadKey()
End Sub
End Module

Above code is also available online at http://goo.gl/dMsAip


Feel free to edit and modify it to understand its working.

Prepared by: Blitz Computing

6|Page

Pre-Release Material (Oct/Nov15)

Task 2 Solution (Pseudocode)


ROUTINE TASK2
SET babytemp [1:18] 0.0 AS FLOAT
SET highest -10.0, lowest 1000.0, difference 0.0 AS FLOAT
FOR Count 1 to 18
PRINT Enter the cot temperature
INPUT babytemp [Count]

IF babytemp[Count] < lowest THEN


lowest babytemp[Count]
END IF

IF babytemp[Count] > highest THEN

highest babytemp[Count]
END IF
WAIT (10)
NEXT Count
difference highest lowest
PRINT The lowest temperature was, lowest
PRINT The highest temperature was, highest
PRINT The difference was, difference
END ROUTINE
Explanation
Array declaration for 18
values and normal
variables for other
calculations

Loop to take 18 inputs


and calculate highest
and lowest
temperatures

Built-in function to
add a delay of 10
minutes after each
loop iteration

Prints highest, lowest


and difference values

Prepared by: Blitz Computing

Key Points
Array for temperature and
variables for lowest, highest
and difference
FOR loop for taking 18 inputs
Difference calculation at end
of loop
WAIT built-in function to add
delay of 10 minutes at each
loop iteration

7|Page

Pre-Release Material (Oct/Nov15)

Task 2 Solution (Flowchart)


Start

SET babytemp [1:18] 0.0 As FLOAT


SET Count 1 AS INTEGER
SET highest -10.0, lowest 1000.0,
difference
0.0 AS FLOAT

PRINT Enter the cot temperature


INPUT babytemp [Count]

IF
babytemp[Count]
< lowest

YES
lowest

babytemp[Count]

highest

babytemp[Count]

NO

IF
babytemp[Count]
> highest

YES

NO
Count Count + 1
WAIT (10)

YES
IF Count <= 18

NO
Difference

highest - lowest

PRINT The lowest temperature was , lowest


PRINT The highest temperature was , highest
PRINT The difference was , difference

END
Prepared by: Blitz Computing

8|Page

Pre-Release Material (Oct/Nov15)

Task 2 Solution (VB .NET)


Module Module1
Sub Main()
'Task 2
Dim babytemp(17) As Decimal
Dim lowest As Decimal = 1000.0
Dim highest As Decimal = -10.0
Dim difference As Decimal = 0.0
For count = 0 To 17
Console.WriteLine("Enter the cot temperature")
babytemp(count) = Console.ReadLine()
If babytemp(count) < lowest Then
lowest = babytemp(count)
End If
If babytemp(count) > highest Then
highest = babytemp(count)
End If
' Comment the line below to disable 10 minute wait
Threading.Thread.Sleep(600000)
Next count
difference = highest - lowest
Console.WriteLine("The lowest temperature was " & lowest)
Console.WriteLine("The highest temperature was " & highest)
Console.WriteLine("The difference was " & difference)
Console.ReadKey()
End Sub
End Module

Above code is also available online at http://goo.gl/E2aAOE


Feel free to edit and modify it to understand its working

Prepared by: Blitz Computing

9|Page

Pre-Release Material (Oct/Nov15)

Task 3 Solution (Pseudocode)


BEGIN
SET babytemp [1:18] 0.0 AS FLOAT
SET highest -10.0, lowest 1000.0, difference 0.0 AS FLOAT
Key Points
SET out range 0 AS INTEGER
FOR Count 1 to 18
Array for temperature and
PRINT Enter the cot temperature
variables for lowest, highest
INPUT babytemp [Count]
and difference
IF babytemp[Count] < lowest THEN
FOR loop for taking 18 inputs
lowest babytemp[Count]
END IF
Difference calculation at end
IF babytemp[Count] > highest THEN
of loop
highest babytemp[Count]
WAIT built-in function to add
END IF
delay of 10 minutes at each
IF babytemp[Count] < 36.0 OR babytemp[Count] > 37.5 THEN
loop iteration
out range out range + 1
Variables for counting out of
END IF
WAIT (10)
range errors
NEXT Count
difference highest lowest
IF difference > 1 THEN
PRINT Warning! The temperature difference was more than 1 degree
END IF
IF out range > 2 THEN
PRINT Warning! The temperature was out of range more than 2 times
END IF
END
Explanation
Variable & array
declaration
Loop to take input,
calculate highest,
lowest and count of
out of range values

Print appropriate
warning messages
according to condition
Prepared by: Blitz Computing

10 | P a g e

Pre-Release Material (Oct/Nov15)

Task 3 Solution (Flowchart)


Start

SET babytemp [1:18] 0.0 As FLOAT


SET Count 1, out range 0 AS INTEGER
SET highest -10.0, lowest 1000.0,
difference
0.0 AS FLOAT

PRINT Enter the cot temperature


INPUT babytemp [Count]

IF
babytemp[Count]
< lowest

YES
lowest

babytemp[Count]

highest

babytemp[Count]

NO

IF
babytemp[Count]
> highest

YES

NO

IF babytemp[Count]
< 36.0 OR > 37.5

NO

Count Count + 1
WAIT (10)

YES
IF Count <= 18

NO
A

Prepared by: Blitz Computing

YES

Out range

out range + 1

11 | P a g e

Pre-Release Material (Oct/Nov15)

difference

highest - lowest

IF difference > 1

YES

PRINT Warning! The temperature


difference was more than 1 degree

NO

IF out range > 2

NO
END

Prepared by: Blitz Computing

YES

PRINT Warning! The temperature was


out of range 2 times

12 | P a g e

Pre-Release Material (Oct/Nov15)

Task 3 Solution (VB .NET)


Module Module1
Sub Main()
Dim babytemp(17) As Decimal
Dim lowest As Decimal = 1000.0
Dim highest As Decimal = -10.0
Dim difference As Decimal = 0.0
Dim out_range As Integer = 0
For count = 0 To 17
Console.WriteLine("Enter the cot temperature")
babytemp(count) = Console.ReadLine()
If babytemp(count) < lowest Then
lowest = babytemp(count)
End If
If babytemp(count) > highest Then
highest = babytemp(count)
End If
If babytemp(count) < 36.0 Or babytemp(count) > 37.5 Then
out_range = out_range + 1
End If
' Comment the line below to disable 10 minute wait
Threading.Thread.Sleep(600000)
Next count
difference = highest - lowest
If difference > 1.0 Then
Console.WriteLine("Warning! The temperature difference was more than 1 degree")
End If
If out_range > 2 Then
Console.WriteLine("Warning! The temperature was out of range " & out_range & "
times")
End If
Console.ReadKey()
End Sub
End Module

Above code is also available online at http://goo.gl/7icTbT


Feel free to edit and modify it to understand its working

Prepared by: Blitz Computing

13 | P a g e

Pre-Release Material (Oct/Nov15)

Solution in C Language
Task 1
#include <stdio.h>
int main()
{
float babytemp = 0.0;
printf("Enter the cot temperature \n");
scanf("%f", &babytemp);
if (babytemp < 36.0)
{
printf("Temperature is below the limit \n");
}
else if (babytemp > 37.5)
{
printf("Temperature is above the limit \n");
}
else printf("Temperature is normal \n");
return 0;
}

Task 2
#include <stdio.h>
#include <stdlib.h>
int main()
{
float babytemp[17];
float highest = -10.0, lowest = 1000.0, difference = 0.0;
int count = 0;
for (count = 0; count < 18; count++)
{
printf("Enter the cot temperature \n");
scanf("%f", &babytemp[count]);
if (babytemp[count] < lowest)
{
lowest = babytemp[count];
}
if (babytemp[count] > 37.5)
{
highest = babytemp[count];
}
// Comment the following line to disable 10 min wait
sleep(600000);
}
difference = highest - lowest;
printf("The highest temperature was %f \n", highest);
printf("The lowest temperature was %f \n", lowest);
printf("The difference was %f \n", difference);
return 0;
}

Prepared by: Blitz Computing

14 | P a g e

Pre-Release Material (Oct/Nov15)

Task 3
#include <stdio.h>
#include <stdlib.h>
int main()
{
float babytemp[17];
float highest = -10.0, lowest = 1000.0, difference = 0.0;
int count = 0, out_range = 0;
for (count = 0; count < 18; count++)
{
printf("Enter the cot temperature \n");
scanf("%f", &babytemp[count]);
if (babytemp[count] < lowest)
{
lowest = babytemp[count];
}
if (babytemp[count] > 37.5)
{
highest = babytemp[count];
}
if (babytemp[count] < 36.0 || babytemp[count] > 37.5)
{
out_range = out_range + 1;
}
// Comment the following line to disable 10 min wait
sleep(600000);
}
difference = highest - lowest;
if (difference > 1)
{
printf("Warning! The temperature difference was more than 1 degree \n");
}
if (out_range > 2)
{
printf("Warning! The temperature was out of range %d times \n", out_range);
}
return 0;
}

Task 1 available online at http://goo.gl/Tjvk8j


Task 2 available online at http://goo.gl/J8fuB4
Task 3 available online at http://goo.gl/Lrr5XJ

Prepared by: Blitz Computing

15 | P a g e

Pre-Release Material (Oct/Nov15)

Comments & Feedback


This document is prepared by Blitz Computing to help students prepare for Computer Science 2210
Paper 2.
For any kind of discussion, corrections and suggestions please visit our Facebook page at:
www.facebook.com/blitzcomputing
Complete solution can also be provided in other programming languages on request on our Facebook
page.

Prepared by: Blitz Computing