0% found this document useful (0 votes)
5 views17 pages

Understanding Algorithms and Constructs

Computer science pseudocode

Uploaded by

simba.mujuru2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views17 pages

Understanding Algorithms and Constructs

Computer science pseudocode

Uploaded by

simba.mujuru2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Cambridge International AS and A Level Computer Science

What  is  an  algorithm  


• It  is  a  solu*on  to  a  problem  expressed  as  a  
sequence  of  defined  steps.  

• ©  Cambridge  University  Press  2016  


Cambridge International AS and A Level Computer Science

Expressing  algorithms    
①Structured  English  
②Pseudocodes  
③Flowcharts  
 
Cambridge International AS and A Level Computer Science

Structured  English  
• Structured  English  provides  a  more  formal  way  of  
documen*ng  the  stages  of  the  algorithm.    
• It  is  a  subset  of  English  language  that  consists  of  
command  statements  used  to  describe  an  
algorithm.    

 
 
Cambridge International AS and A Level Computer Science

Pseudocodes  
• a  way  of  using  keywords  and  iden*fiers  to  describe  
an  algorithm  without  following  the  syntax  of  a  
par*cular  programming  language.  
• It  uses  keywords  commonly  found  in  high-­‐level  
languages  and  mathema*cal  nota*on.    

 
 
Cambridge International AS and A Level Computer Science

Flow  chart  
• Flow  chart  is  a  graphical  
representa*on  of  a  
program.    
• They  use  different  symbols  
containing  informa*on  
about  steps  or  a  sequence  
of  events.    

 
Cambridge International AS and A Level Computer Science

Input-­‐Process-­‐Output    
• Many  problems  we  try  to  solve  with  a  
computer  involve  data.  
• The  solu*on  involves  inpuMng  data  to  
the  computer,  processing  the  data  and  
outpuMng  results    
 
 
Cambridge International AS and A Level Computer Science

Variable  
• A  variable  is  memory  loca*on  that  has  an  
iden*fier  (name)  where  a  value  can  be  
stored.    
• Variable  iden*fiers  should  not  contain  spaces  
–  only  leTers,  digits  and_  (the  underscore  
symbol).    
Cambridge International AS and A Level Computer Science

Variable  
• To  make  algorithms  easier  to  understand,  the  
naming  of  a  variable  should  reflect  the  
variable's  use.  
• This  means  oXen  that  more  than  one  word  is  
used  as  an  iden*fier.    
• The  formaMng  conven*on  used  here  is  
known  as  CamelCaps.  It  makes  an  iden*fier  
easier  to  read.    
Cambridge International AS and A Level Computer Science

Constants  
• Just  like  variables,  constants  are  dataholders.  
• They  can  be  used  to  store  data  that  is  needed  
at  run*me.  
• In  contrast  to  variable,  the  content  of  a  
constant  can't  change  at  run*me,  it  has  a  
constant  value.    
• Before  the  program  can  be  executed  (or  
compiled)  the  value  for  a  constant  must  be  
known.    
Cambridge International AS and A Level Computer Science

Four  basic  Construct  in  Algorithms  


①  Assignment  
②  Sequence  
③  Selec<on  
④  Repe<<on  
 
 
 
Cambridge International AS and A Level Computer Science

Assignments  
• a  value  is  given  a  name  (iden*fier)  or  the  
value  associated  with  a  given  iden*fier  is  
changed.    
– Assigning  a  value    
– Upda<ng  a  value    
– Copying  a  value    
– Swapping  two  values    
Cambridge International AS and A Level Computer Science

Assignments  -­‐  Assigning  a  value    


 
Cambridge International AS and A Level Computer Science

Assignments  –  UpdaBng  a  value    


 
Cambridge International AS and A Level Computer Science

Four  basic  Construct  in  Algorithms  


①  Assignment:  
a  value  is  given  a  name  (iden*fier)  or  the  value  associated  
with  a  given  iden*fier  is  changed.    
②  Sequence:  
a  number  of  steps  are  performed,  one  aXer  the  other.    
③  Selec<on:  
under  certain  condi*ons  some  steps  are  performed,  
otherwise  different  (or  no)  steps  are  performed.    
④  Repe<<on:    
a  sequence  of  steps  is  performed  a  number  of  *mes.  This  is  
also  known  as  itera*on  or  looping.    
Cambridge International AS and A Level Computer Science

 
Input/Output  and  Assignment  
1) Write a program to take as input the length and
width of a rectangular garden. The program is to
calculate and output the surface area.

2) Write a program to take as input a temperature


in degrees Fahrenheit. The program is to convert
and output the temperature in degrees Celsius
(Hint: DegreesC = (DegreesF – 32) * 5/9)
Cambridge International AS and A Level Computer Science

Selec*on    
3 Write a program to take as input air
temperature in degrees Celsius. The
program is to output a message to say
whether it is freezing (below 1 degree)
or not.
4* Amend your program from (3) to say
whether the water in a container is
frozen, liquid or boiling.
Cambridge International AS and A Level Computer Science

Selec*on2    
5 Write a program to take as input an
integer between 1 and 12 (inclusive).
The program is to output the name of
the month corresponding to the number
input. For example, an input of 2 will
output ‘February’. Hint: use a CASE
statement.

You might also like