Pre Release OL Nov15 Final BBycot
Pre Release OL Nov15 Final BBycot
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
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.
2|Page
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
3|Page
Key Points
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.
4|Page
Start
YES
IF babytemp < 36.0
NO
PRINT Temperature
is above the limit
YES
IF babytemp > 37.5
NO
PRINT Temperature
is normal
END
PRINT Temperature
is below the limit
5|Page
6|Page
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
Built-in function to
add a delay of 10
minutes after each
loop iteration
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
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
END
Prepared by: Blitz Computing
8|Page
9|Page
Print appropriate
warning messages
according to condition
Prepared by: Blitz Computing
10 | P a g e
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
YES
Out range
out range + 1
11 | P a g e
difference
highest - lowest
IF difference > 1
YES
NO
NO
END
YES
12 | P a g e
13 | P a g e
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;
}
14 | P a g e
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;
}
15 | P a g e