Upload
pooja-soorjonowa-fowdar
View
220
Download
0
Embed Size (px)
Citation preview
8/18/2019 Pre Release OL Nov15 Final BBycot
1/16
PRE-RELEASE MATERIAL
Oct/Nov 2015O Level Computer Science 2210 – Region 4
AbstractThis document provides solution to the Cambridge pre-release material
for Computer Science 2210
8/18/2019 Pre Release OL Nov15 Final BBycot
2/16
1 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Pre-Release Material Tasks
A new born baby is kept in a cot in a hospital; the temperature of the baby is monitored every 10minutes. The temperature of the baby is recorded in degrees Celsius to one decimal place and must be
within the range 36.0°C to 37.5°CTASK 1
To simulate the monitoring required, write a routine that allows entry of the baby’s temperature indegrees Celsius. The routine should check whether the temperature is within the acceptable range, toohigh 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. Thisroutine should output the highest and lowest temperature and calculate the difference between thetemperatures.
TASK 3
For a baby who has a temperature difference of more than one degree Celsius, and/or has been outsidethe acceptable range more than twice in the three hour period, output a suitable message giving asummary 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.
8/18/2019 Pre Release OL Nov15 Final BBycot
3/16
2 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Concept and Understanding of Tasks
All 3 tasks are a part of one big problem i.e. monitoring the baby temperature and print appropriatewarning message according to it. The general flow and algorithm can be understood by the following
diagram.
Approach to Solution
There can be many approaches to solve these tasks depending upon the understanding of person. Weare listing down the key points that reflect our understanding and we’ll solve these tasks according tofollowing assumptions.
As written in the starting scenario that inputs are taken at an interval of 10 minutes, a built-infunction “ Wait ” will be used in pseudocode and programming statements to achieve thisfunctionality.
Task 1 have to written as an independent routine/sub-routine and array will not be used tostore values.
Task 2 is also an independent routine/sub-routine. Array will be used to store temperatures anda 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 .NET ”1, however ‘C’ languagecode is also included at the end of document.
1 Click to download Microsoft Visual Basic .NET Express edition
Variables and arrays declaration
Loop to take input temperature every 10 minutes
Record the temperatures in an array. Record owest andhighest temperature and its difference
Print approrpaite message if the recorded temperature isoutside the specified range or if the difference oftemperature is greater than 1 degrees
http://download.microsoft.com/download/1/E/5/1E5F1C0A-0D5B-426A-A603-1798B951DDAE/VS2010Express1.isohttp://download.microsoft.com/download/1/E/5/1E5F1C0A-0D5B-426A-A603-1798B951DDAE/VS2010Express1.isohttp://download.microsoft.com/download/1/E/5/1E5F1C0A-0D5B-426A-A603-1798B951DDAE/VS2010Express1.isohttp://download.microsoft.com/download/1/E/5/1E5F1C0A-0D5B-426A-A603-1798B951DDAE/VS2010Express1.iso
8/18/2019 Pre Release OL Nov15 Final BBycot
4/16
3 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Variable declaration,datatype used is floatto store decimal values
“IF” selectionstatement to checkwhether input lieswithin particular rangeor not. Then printappropriate message.
Print an informationmessage and takein ut of tem erature
Task 1 Solution (Pseudocode)
ROUTINE TASK1SET babytemp AS FLOAT
babytemp
0.0PRINT “Enter the cot temperature” INPUT babytempIF 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
Explanation
Key Points
Variable for storing babytemperature is declared as FLOAT
IF - ELSE statements to select theappropriate message to print
8/18/2019 Pre Release OL Nov15 Final BBycot
5/16
4 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Start
SET babytemp As Floatbabytemp 0.0
PRINT Enter the cot temperatureINPUT babytemp
IF babytemp < 36.0PRINT Temperature
is below the limit
IF babytemp > 37.5
END
PRINT Temperatureis above the limit
YES
NO
NO
YES
PRINT Temperatureis normal
Task 1 Solution (Flowchart)
8/18/2019 Pre Release OL Nov15 Final BBycot
6/16
5 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Task 1 Solution (VB .NET)
Module Module1
Sub Main()Dim babytemp As Decimal = 0.0Console .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 it’s working.
http://goo.gl/dMsAiphttp://goo.gl/dMsAiphttp://goo.gl/dMsAiphttp://goo.gl/dMsAip
8/18/2019 Pre Release OL Nov15 Final BBycot
7/16
6 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Array declaration for 18values and normalvariables for othercalculations
Loop to take 18 inputsand calculate highestand lowesttemperatures
Built-in function toadd a delay of 10minutes after eachloop iteration
Prints highest, lowestand difference values
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 18PRINT “Enter the cot temperature” INPUT babytemp [Count]IF babytemp[Count] < lowest THEN
lowest babytemp[Count]
END IFIF babytemp[Count] > highest THEN
highest babytemp[Count]
END IF
WAIT (10) NEXT Count
difference highest – lowestPRINT “The lowest temperature was”, lowest PRINT “The highest temperature was”, highest PRINT “The difference was”, difference
END ROUTINE
Explanation
Key Points
Array for temperature andvariables for lowest, highestand difference
FOR loop for taking 18 inputs Difference calculation at end
of loop
WAIT built-in function to adddelay of 10 minutes at eachloop iteration
8/18/2019 Pre Release OL Nov15 Final BBycot
8/16
7 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Start
SET babytemp [1:18] 0.0 As FLOATSET Count 1 AS INTEGER
SET highest -10.0, lowest 1000.0,difference 0.0 AS FLOAT
PRINT Enter the cot temperatureINPUT babytemp [Count]
IFbabytemp[Count]
< lowest
IFbabytemp[Count]
> highest
END
YES
NO
NO
YES
lowest babytemp[Count]
highest babytemp[Count]
Count Count + 1WAIT (10)
IF Count
8/18/2019 Pre Release OL Nov15 Final BBycot
9/16
8 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Task 2 Solution (VB .NET)Module Module1
Sub Main()
'Task 2 Dim babytemp(17) As Decimal Dim lowest As Decimal = 1000.0Dim highest As Decimal = -10.0Dim difference As Decimal = 0.0For 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 countdifference = highest - lowestConsole .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
http://goo.gl/E2aAOEhttp://goo.gl/E2aAOEhttp://goo.gl/E2aAOEhttp://goo.gl/E2aAOE
8/18/2019 Pre Release OL Nov15 Final BBycot
10/16
9 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Task 3 Solution (Pseudocode)BEGIN
SET babytemp [1:18] 0.0 AS FLOAT SET highest -10.0, lowest 1000.0, difference 0.0 AS FLOATSET out range 0 AS INTEGER FOR Count 1 to 18
PRINT “Enter the cot temperature” INPUT babytemp [Count] IF babytemp[Count] < lowest THEN
lowest babytemp[Count]END IFIF babytemp[Count] > highest THEN
highest babytemp[Count]END IFIF babytemp[Count] < 36.0 OR babytemp[Count] > 37.5 THEN
out range out range + 1
END IFWAIT (10)
NEXT Countdifference highest – lowestIF difference > 1 THEN
PRINT “Warning! The temperature difference was more than 1 degree” END IFIF out range > 2 THEN
PRINT “Warning! The temperature was out of range more than 2 times ” END IF
END
Explanation
Key Points
Array for temperature andvariables for lowest, highestand difference
FOR loop for taking 18 inputs Difference calculation at end
of loop WAIT built-in function to add
delay of 10 minutes at eachloop iteration
Variables for counting out ofrange errors
Variable & arraydeclaration
Loop to take input,calculate highest,lowest and count ofout of range values
Print appropriatewarning messagesaccording to condition
8/18/2019 Pre Release OL Nov15 Final BBycot
11/16
10 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Start
SET babytemp [1:18] 0.0 As FLOATSET Count 1, out range 0 AS INTEGER
SET highest -10.0, lowest 1000.0,difference 0.0 AS FLOAT
PRINT Enter the cot temperatureINPUT babytemp [Count]
IF
babytemp[Count]< lowest
IFbabytemp[Count]
> highest
YES
NO
NO
YES
lowest babytemp[Count]
highest babytemp[Count]
Count Count + 1WAIT (10)
IF Count 37.5
A
Out range out range + 1YES
NO
Task 3 Solution (Flowchart)
8/18/2019 Pre Release OL Nov15 Final BBycot
12/16
11 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
A
END
difference highest - lowest
IF difference > 1
IF out range > 2
PRINT Warning! The temperaturedifference was more than 1 degree
PRINT Warning! The temperature wasout of range 2 times
YES
YES
NO
NO
8/18/2019 Pre Release OL Nov15 Final BBycot
13/16
12 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Task 3 Solution (VB .NET)Module Module1
Sub Main()Dim babytemp(17) As Decimal
Dim lowest As Decimal = 1000.0Dim highest As Decimal = -10.0Dim difference As Decimal = 0.0Dim out_range As Integer = 0For 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 + 1End If' Comment the line below to disable 10 minute waitThreading.Thread.Sleep( 600000 )
Next countdifference = highest - lowestIf 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
http://goo.gl/7icTbThttp://goo.gl/7icTbThttp://goo.gl/7icTbThttp://goo.gl/7icTbT
8/18/2019 Pre Release OL Nov15 Final BBycot
14/16
13 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Solution in ‘C’ Language
Task 1
#include
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 #include
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;
}
8/18/2019 Pre Release OL Nov15 Final BBycot
15/16
14 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Task 3
#include #include
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
http://goo.gl/Tjvk8jhttp://goo.gl/Tjvk8jhttp://goo.gl/Tjvk8jhttp://goo.gl/J8fuB4http://goo.gl/J8fuB4http://goo.gl/J8fuB4http://goo.gl/Lrr5XJhttp://goo.gl/Lrr5XJhttp://goo.gl/Lrr5XJhttp://goo.gl/Lrr5XJhttp://goo.gl/J8fuB4http://goo.gl/Tjvk8j
8/18/2019 Pre Release OL Nov15 Final BBycot
16/16
15 | P a g e P r e - R e l e a s e M a t e r i a l ( O c t / N o v ’ 1 5 )
Prepared by: Blitz Computing
Comments & Feedback
This document is prepared by Blitz Computing to help students prepare for Computer Science 2210Paper 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 Facebookpage.
http://www.facebook.com/blitzcomputinghttp://www.facebook.com/blitzcomputinghttp://www.facebook.com/blitzcomputing