100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary OCR A-Level Computer Science topic 2.2

Rating
-
Sold
-
Pages
8
Uploaded on
15-05-2024
Written in
2022/2023

Notes for point 2.2 in the ocr computer science specification focusing on programming techniques and computational methods

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Study Level
Examinator
Subject
Unit

Document information

Uploaded on
May 15, 2024
Number of pages
8
Written in
2022/2023
Type
Summary

Subjects

Content preview

Reading to and
Writing from files


openRead + open a file to read

readline return line of text
from the file
->
a



myfile-openRead ("sample .
Ext")
X= file readline
my
.




file
. close
my
↳ makes
X first line of ext file


endOffile() determines end of a
file
file openRead ("sample
It'l
my
: .




while NOT
my
file. end
Of file )
print (myfile . readLine()
endwhile

myfile . close)

prints contents of sample Ixt .




openWrite -> open a file to write to

writeline add line
of text to file
-




my Gle
=

open Write ("sample Ixt") .




file WriteLine ("Hello
S

World"
my .




file close
my .




↳ hello world is made the contents . It
of sample (previous contents are overwritten

, 2 2 1 . .


Programming techniques
programmingconstruc
its are used to represent a
program's control flow in the
popular subsection of procedural programming called structured
programming
:

Sequence
↳ code executed
line-by-line , top to bottom

Branching
certain block of code is if specific condition is met
If
using
↳ a run a
,


statements.


also known as selection

Iteration a block of code is executed a certain number ofhimes or while a

condition is met
↳ Iteration uses COR ,
WHILE or REPEAT UNTIL loops
↳ Iteration can be either :
count-controlled : iteration number of times
is
given a
-




for i in (0 10
range ,




print i

next i
↳ condition-controlled : iteration continues until condition is
a
given
met
While i = 20 :

print "Not true" :

i = i + 1

endwhile
Recursion :
↳ construct in which a subroutine calls itself during its execution
condition-called the
until
stopping
↳ continues a certain condition is met
↳ suited to certain problems which
produces the same result as iteration , but more are

more
easily expressed using recursion

Advantage:
they can be represented using fewer lines of code so less prone to errors

,



However it is essential that recursive subroutines are to
defined clearly
↳ so as

reach a
stopping condition after a
finite number of
function calls



Common example of a
naturally recursive
function factorial (number
functionisfactoria function calls itself
,
number == O or I stack is created within
if a new frame
return / the call stack , where parameters
,
else : local variables and return addresses

return number # factorial (number-1) ; are .
stored
end if
end function
$4.79
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
nikitabilla-patel

Get to know the seller

Seller avatar
nikitabilla-patel The University of Warwick
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
1 year
Number of followers
0
Documents
6
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions