100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary OCR A-Level Computer Science topic 2.2 $4.56   Add to cart

Summary

Summary OCR A-Level Computer Science topic 2.2

 6 views  0 purchase
  • Course
  • Institution

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

Preview 2 out of 8  pages

  • May 15, 2024
  • 8
  • 2022/2023
  • Summary
avatar-seller
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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller nikitabilla-patel. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $4.56. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

75759 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$4.56
  • (0)
  Add to cart