Docsity

Computer science IGCSE (0478), Summaries of Computer science

Partial preview of the text

Download Computer science IGCSE (0478) and more Summaries Computer science in PDF only on Docsity!

Chapter

s

PROGRAMMING

Problem - > Solve

5 Basic (^) Constructs for (^) Developing a program ① Data^ Usage :^ Variable^ ,^ Constant^ , Arrays ②Sequence :^ Order of steps^ in (^) a task INPUT Age (^) Input It Age

THEN OUTPUT^ "Adult"

conditiona ③ Selection^ : Choosing a path (^) through the program ⑦ (^) Iteration : Repetition (^) of a sequence of^ steps^ in (^) a Program ⑤ (^) Operator Usage : Arthmetic^ for calculation, Logical

or Booken

statements (^) for decision^ making

③ String

  • > A variable^ or^ constant^ that (^) is several (^) characters in Length (multiple^ characters (^) joined together) 32

aba double -single ④ Char^

  • (^) A variable (^) or constant that (^) is just a single

character

⑤ Boolean^

  • > A (^) variable (^) or constant (^) that can only

have

two values (^) (Yes/No (^) , ONOFF (^) , True/False DECLARATION In part X Product xX

DECLARE VariableName :

Datatype DECLARE Sum^ :^ INTEGER Declare ↓ Sum =^ o^ -^ Initialisation^ Initialise

CONSTANT Name = Value

CONSTANT Pi^ =^3.^142

  • >^ the (^) first (^) fore! Pre (^) Built Functions//STRING HANDLING
  • > (^) first (^) four functions work (^) only with string values and^ also^ return^ string value D Length

: returns/tells the user how

many

characters are in

a specific string

DECLARE Name^ :^ STRING DECLARE LenName^ :^ INTEGER INPUT Name 1/ Length check LenName = (^) LENGTH) (^) Name)

OUTPUT Len Name

LENGTH (456) X

incorrect ② (^) Uppercase =>^ UCASE^ (Vamable)^ can only wood i

INPUT Sentence abc^ -^ >^ ABC

UpperSentence = (^) UCASE (^) (Sentence) memory b

OUTPUT

Uppe

Sentence variable

maltzMunir- MAAZMUNIR

Repeat

Input X Until XPassword^ - separate ~ (^) CASEXnput) ③ Lowes^ Case^ => LCASE^ (Vamable) LCASE (^) ("HELLO") =^ hello INPUT Paragraph Updated - CASE^ (Paragraph)

OUTPUT IDNUM 2 + 3 = 5

intgen

  • > These functions (below]^ are^115 " now (^) applicable to^ Intges/Real too^ : Math

in

nee LIBRARY ROUTINES L ① DIV->^ Divides^ a number^ by a^ value^ String

and returns this

goutient 4 =^ Contient 54 20

DIVC Number/Variable , Value^ with which

you

want to divide TRemainder

DIV(24 , 5) => Qontient when 24 is divided by 5

↓ 4 DECLARE Quotient (^) : (^) INTEGER

Contient =^ DIV (24 , 5)

OUTPUT (^) Quatient

② MOD^ =>^ Returns^ the^ remainder^ of a specific

value

being divided by a^ number Remainder

MOD (17 , 1)

  • > (^3) (Remainder) Remainder =^ MOD^ (Num , 7)

decimal places 35.^894

↓ ③ ROUND (^) (Value (^) , Precision) 35

. 9 ↓ value =^ ROUND (^) (102 ·^578 , 2)^ o

2 d.

p 102. 518 - > 102 · 58

Num =^ ROUND / Num^ , (^) 3) ROUND (102.^578 , 2) ↓ 102.^6

① (^) RANDOM (^) () 103 Real

  • > (^) A generates a random^ value^ between^ o and^1 ~> (^) bracketsindicator Result (^) =RANDOM)) function
  • > (^) Generate a random value (^) between o and^50 Result-^ RANDOM^10 , 50) ARRAYS · Variables= Store (^) Data /Types · (^) Constant //^ 2D Array I^ ↓Ay^ Fusion ↓ · a^ Dimension Arrays /

Scores Assign (^) poss value (^) to a^ variable 23 5

name Ans^

s (^90) & 97 2 &

Ans =^ Scores (3]

to 36 5 Change value of post^ to (^301) Assigning Value (^) to on Array Scores (^) [1] =^30 · Decleration of (^) Array :

DECLARE

ArrayName : ARRAY^ (Starting , Ending]

OF

Datatype

  • > Arrays (^) always store data^ of one type
  • > I need^ to^ create^ an array to store^ marks^ of (^50) students

DECLARE Marks : ARRAY (

, 50]^ OF^ INTEGER

column ↓ (^) Marks Lexecute 50 95 =^ rows I

-- n^ row^ =^50

ID

Array ·

-^ now

1 Column^ St 5

&^ empty

Populating the Array / Filling on Array

Marks[1] 1 To

Marks(2] =^50 -^ This^ is &^ very^ inefficient Marks (^) [so] =^45 Marks(Count] Array Name (^) [Position] FOR (^) Count <1 TO (^50) Count

INPUT (^) Marks Marks LE]^ =^50 Marks [Count]^ <^ Marks Count = 50 as NEXT Count

Marks [50] =

Increments (^) the I (^) automatically Only if

the

question does (^) not specify the^ array size ARRAY (^21) ,^5003 //^ Assuming

the maximum number

of elements are 100

Names error^7

Al (^) OUTPUTTING DATA * Mary am (^6)

DECLARE Names^ : ARRAY^ (1% 6] OF STRING Alena^

j

Harnza

Y

FOR Position^ +^1 TO^6

OUTPUT Names (^) [Position] Mustafa 3

Moosa 2

NEXT Position^ Names^ [1 - >

Maaz

1 error to

  • forLoop
    • (^) - = & =lo

while loop

8 (^1) Repeat

Until

=>+^1 error

  • (^) - (^) to REPEAT (^) Count 1 => Array^ [o]

REPEAT

OUTPUT "Please^ enter a^ name"

INPUT Name

[1 , (^) 5]

Names [Count] <^ Name

Count=^ Count^ +^1

UNTILCount > 10

  • while > DECLARE CSGurus :^ ARRAY [G5]OF^ STRING ↓ Comt Count (^) c = 10 OGelements OUTPUT "Enteyou name" Same INDUT - >^ [0^ ,^ 99]

Name 100

Names (^) [Count] = Name

- > [1 , 100]

Count +=^ I

ENDWHILE

= > -^ - => -

  • > (^) - => =>

FOR (^) Count=^1 To (^10)

INPUT Names^ [Count]^

II INPUTNHey^ Num

NEXT Count

FOR Counter^ =^

To 10

INPUT CheckNumber

not (^) equal IF (^) CheckNumber > (^) Names [Counter]

OUTPUT

"

Chack Number :

" CheckNumber^ , " Array Value" , Names (^) [Counter] , (^) "They do not^ match.^ Recenter

The number'

INDUT Names^ [Counter]

ENDIF

NEXT (^) Counter

OUTPUT "The^ check^ has^ been^

completed" To ensure that you keep

REPEAT

  • on asking the (^) user for IF Check Number (^) > (^) Names [Counter] a value^ till it (^) matches

the

specified conditions one INPUT Names (^) [Counter]

UNTIL Names [Counter =^ CheckNumber

CoLl CoL ↓ (^) ↓ 2D

  • Array - > (^) E5'Maaz - > Anny (^) "7I"
  • > Allows multiple rows^ and (^) columns Rows -^ >^ Alezah^ "67"
  • > (^) Romeen"74" 22x

DECLERATION :

  • > Samraj

COL Num^ a 2

CoL (^) Num 1 CoL^ NumI

Row Num 2 Rowlum^3

RowNum (^) - #^ -

Student 22 , 13

Student(3^.^ A

Student [1^ ,^ D]

O) Initialise^ a^ 2D^ Array that^ asks^ the^ user for Marks^. Suppose

column't has StudentIDs which have^ been

already initialised Class (^) Siz= 35 COLO^ CoL 1 marks I notrequired for this (^) question Star! · (^) = 2 cols (^) I (^2) DECLARE Marks^ :^ ARRAY^10 :^34 , 01]^ OF^ INTEGER 2 3 ↓ (^) Y (^35) rows h 5

FOR RowNumber = 0 TO 34 34

OUTPUT "enter^ marks^ for

Student ID :

" ,

Marks [Row Number^ , 0]

INPUT SMarks

Marks (^) [RowNumber (^) , 1] (^) ID 40

MAX (^0) Is 3 Go

ID +^0

FORRCount =^1 TO (^50)

j j^98

IF (^) StudentMarks [RCount (^) , 2] >^ MAX THEN Max=^ StudentMarks[RCount, 2] ID = StudentMarks [RCount (^) , 1) ENDIF NEXT RCount OUTPUT "the student^ with^ highest

mark has an^ ID

of : " , ID^ , "and the highest marks (^) are : " , Max Linear (^) Search Names []

  • > (^) Write (^) a^ Rameen^ O program that checks^ whether^ -

The

array has the^ name^ "Annas"^ in^ it^ or Alezah (^1) not Annus^2 Samraj

FOR (^) Count 10 TO^3

IF Names [Count] =^ "Annus" -

> Secon

Found"

THEN (^) OUTPUT (^) "person found" -

ENDIF Names [o]^

  • > (^) Maaz ↑ NEXT Cant^

Q) There^ is^ an^ ID array

HANomes[] that stores the

names of

150 students who

got

on ** Last session. Create

a program That (^) takes a (^) name (^) as on input from^

the user

and (^) check whether the (^) name exists (^) in the array

or not

UNTIL (FOUND^ =^ TRUE)^ OR^

(Count >^ 150)

IF Found =^ TRUE

THEN (^) OUTPUT (^) "person (^) found" ELSE

Output "not

found" ENDIF Bubble Arrange-^ Ascending (Descending (^1) , 8

, 4 , 12 , 3 < Unordered

↓ (^) Algorithm

  • > Ascending Order

, 12 = (^) Ordered

Num ofvalues

& S I (^) ,^ "^ , (^12) , 3 Q^ n=^5 ENDING

Y

184 , (^12) , 32 ↓^3 ->^ Q 1 , (^4) , 8 , 12 ,^38 For^ are iteration^ out of

I (^) , (^4) , (^8) , 12 , (^3 5) , one value^ is being sorted

#^4 ,^8 ,^3 ,^12 -^ > Largest

* 5 - I

sorted (^1) , 4 , 8 ,^3 ,^12 = " = (^1) , (^4) , 8 , 3 , 12 1 ,^4 , (^8) ,^3 , 12 (^1) , (^4) ,^8 , 12 -^3 ,^8 , 2 are (^) sorted perfectly

(^1) , 4,3 , (^8) , 12 ① My > ② (^1) , (^) 4 3 , (^8) , 12 l (^) D, (^4) , (^8) , 12 ③^ -^ >^ Sorted^ Array

  • > Ascending

sorted

=> 1 , (^3) ,^4 , (^8) ,^12 T T, (^3) , (^4) , 8 , 12 At^ a = ↑ 1 sorted^2 2

temp =^2

  • > Perfect & F & 7

b^3

a =^3 au tempe a b = 3 at^ b HOW (^) DOES IT SORT b a^ b^ < temp Values (^) [1] (^) < 6 ⑥, (^4) , 3 ,^9 ,^11 , 1 Values (^) [2] 4 Vanished a b^ ( values [1] = Values^ (2]^4 , (^4) , (^3) , 9 , (^11) , 1

Values [2] = Values (1)

Gerror (^) Value (2)

(^4) , 3 , 9 , 1. 1 T (^) w values (^) (

  • > Create a temporary

Variable

Temp =^ Values^ [1] 3 3 ,Bali !

Values [1] = Values [2]

Swapping (^3) , (^4) , 9 , (^4) , 1

Values (2] - >

Temp TIP : Sorting always^ includes^ the temporary variable