0% found this document useful (0 votes)
72 views9 pages

Cambridge International Computer Science 2

Cambridge International Computer Science 2 Summary of knowledge

Uploaded by

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

Cambridge International Computer Science 2

Cambridge International Computer Science 2 Summary of knowledge

Uploaded by

maikhoi.mai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
CAIE - TQB CAIE AS LEVEL COMPUTER SCIENCE (9618) SUMMARIZED NOTES ON THE PRACTICAL SYLLABUS CAIE AS LEVEL COMPUTER SCIENCE (9618) 1. Algorithm Design & Problem-Solving ‘= Abstraction: filtering out and concentrating on the relevant information in a problem; allowing a programmer to deal with complexity = Decomposition: breaking down problems into sub- problems in order to understand a process more clearly; program modules, procedures and functions all help the programmer to break down large problems * Algorithm: a solution to a problem expressed as a sequence of steps 1.2. Identifier Table ‘Identifier: name given to a variable in order to call it + An identifier table depicts information about the variable, eg. Daa Daan + Rules for naming identifiers: = Must be unique + Spaces must not be used ‘+ Must begin with a letter of the alphabet + Consist only of @ mixture of letters and digits and the underscore character!” ‘+ Must not be a ‘reserved’ word - eg. Print If, ete. 1.3. Basic Program Operations «Assignment: an instruction in a program that places a value into 2 specified variable + Sequence: programming statements are executed consequently, as they appear in the program + Selection: control structure in which there isa test to decide if certain instructions are executed ‘+ IFselection: testing 2 possible outcomes + CASE selection: testing more than 2 outcomes. + Repetition/teration: control structure in which a group of statements is executed repeatedly ‘+ FORIoop: count-controlledt executed a set no. of times + WHILE loop: pre-conditional executed based on condition at start of statements ‘+ REPEAT loop: post-conaitionat executed based on condition at end of statements A for selecting what loop to use, itis best to use FOR loops when you know the number of iterations required, and a WHILE or REPEAT loop if you do not know the number of iterations required. + Iterate over an array: FOR Loop ‘+ Reading a file into a variable: WHILE Loop ‘© Asking for user input: WHILE/REPEAT Loop ‘+ Aloop that should execute n times: FOR Loop 1.4. Stepwise Refinement + Process of developing a modular design by splitting a problem into smaller sub-tasks, which themselves are repeatedly split into even smaller sub-tasks until each is just one element of the final program 1. ; Program Modules ‘+ This refers to a modular program design + Subroutines: self-contained section of code, performing a specific task; part of the main program ‘+ Procedures: performs a specific task, no value returned topart of code where called ‘+ Functions: performs a specific task, returns a value to part of code where called 1.6. Logic Statements Operator Meaning < Less than < I Less than/equal > T Greater than > Greater/equal Equal to & Not equal to 2. Data Representation 2.1, Data Types Integer: «Positive or negative number; no fractional part ‘+ Held in pure binary for processing and storage + Some languages differentiate short/long integers (more bytes used to store long integers) Real: ‘+ Number that contains a decimal point ‘+ Referred to as singles and doubles depending upon number of bytes used to store Character: + Acharacteris any letter, number, punctuation or space CAIE AS LEVEL COMPUTER SCIENCE (9618) + Takes up a single unit of storage (usually a byte). String: + Combination of alphanumeric characters enclosed in“* + Each character stored in one byte using ASCII code + Each character stored in two bytes using Unicode + Max length of a string limited by available memory. + Incorrect to store dates or numbers as strings + Phone no, must be stored as string else initial 0 lost Boolear + Can store one of only two values; “True” or “False” + Stored in 1 byte: True = 11111111, False = 00000000 Date: # Dates are stored as a'serial' number + Equates to number of seconds elapsed since 1st January 1970 00:00:00 UTC, excluding leap seconds. + Usually take 8 bytes of storage + Displayed as dd/mmiyyyy or mmidd/yyyy + Data structure consisting of a collection of elements Identified by at least one array index (or key) File: * Object that stores data, information, settings or commands ‘+ Canbe opened, saved, deleted & moved + Transferable across network connections 2.2. ASCII Code + Uses 1 byte to store a character + 7bits available to store data and 8° bit sa check digit + 27 =128, therefore 128 different values ‘+ ASCII values can take many forms: numbers, letters (capitals and lower case are separate), punctuation, non- printing commands (enter, escape, Fl) 2.3. UI de + ASCII allows few number of characters; good for English * Unicode allows others too: Chinese, Greek, Arabic etc. + Different types of Unicode: * UTF8: compatible with ASCI, variable width encoding can expand to 16, 24, 32, 40, 48 + UTF16: 16it, variable-width encoding can expand to 22 bits ‘+ UTF-32: 32 bit, fixed-width encoding, each character exactly 32 bits 2.4. Arrays + 1-Dimensional (10) Array: declared using a single index, canbe represented asa lst Index Element fo) JONES [1] | ERICSON (2) | WiLLiAMS (3) ADAMS (4) JOHAL ‘+ 2.Dimensional (20) Array: declared using two indices, can. be represented as a table Indexes () (1) (2) (0) 1" 2 + 2DAay:array = (0, (My Oy ol + Python: + Declaring an array: names = () + Addingto an array: nanes append *Zifotes" ) + Length of array ie. number of elements: Len (name: + Printing an element in @ 1D array: print (names [element position)) + Printing element in a 20 array: print (atzow] {column} + Printing row in a 2D array:names trow) = (new r0¥] + Printing column: use for loop and keep adding 1 to the row and keep column seme 2.5. Bubble Sort CAIE AS LEVEL COMPUTER SCIENCE (9618) Bubblesort( int a[], Begin for i = 1 to n-1 sorted = true for j = 0 to n-1-i if ati > aljet ahs SH ‘int n) = temp sorted = false end for " streak fi id eak from i loop end for End | + AFOR oop is set to stop the sort ‘Setting a variable ‘sorted’ to be ‘rue’ at the beginning + Another FOR loop is set up next in order to search through the array + An IF is used to see ifthe first number of the array is greater than the second. Iftrue: ‘First number stored to variable ‘+ Second number assigned as first number ‘+ Stored variable assigned to second number + Set ‘sorted! to ‘alse’ causing loop to start again +The second FOR loop is count based thus will stop after 2 specific number of times + Goes through bigger FOR loop. ‘sorted’ remains ‘rue! + This exits the loop "ending the program 2.6, Linear Search For each jten in the lise: SPichae stew has the desired value: Stop the search ang return the item's Tocation. neturn the fees fs not tn the Vise + AFOR loop goes through the array + Itcompares item in question to those in list using an IF ‘+ item matches with another then search is stopped + Also the location where it was found is returned + Hfnot found it exits the FOR loop Then returns fact thar item in question is notin the list 2.7. File Handling + Files are needed to import contents (from a file) saved in secondary memory into the program, or to save the ‘output of 2 program (ina file) into secondary memory, so that its available for future use Pseudocode: * Opening a file: opEN= READ/WRITE/APPEND ‘+ Reading a fle: READFILE © Writing a line of text to the file: WRITS=1LE , filename> FOR + Closing a fle: cuoseen + Testing for end of the file: 50F () Python: + Opening file: variable “node”") open (“filenane”, Where the mode can be: Mode Description (Opens file for reading only. Pointer placed at the beginning of the file, Opens a file for writing only. Overwrites file if file exists or creates new file if it doesn't r (Opens a file for appending. Pointer at end of fle ifit exists or creates a new file ifnot «Reading a file: ‘+ Read! all characters: variable.read() + Read each line and store as list: variable. readlines ( © Writing to a file: © Write a fixed a sequence of characters to file: variable.write (“Text”) + Write a list of string to fle: variable.write(* ‘.join(1z", ‘Notes’)) Abstract Data Types (ADT) An Abstract Data Type (ADT) is collection of data with associated operations, There are three types of ADTS: + Stack: an ordered collection of items where the addition Cf new items and removal of existing items always takes place at the same end. + Queue: a linear structure which follows the First In First Out (FIFO) mechanism. tems are added at one end (called the rear) and removed from the other end (called the front) + Linked Lista linear collection of date elements whose order is not given by physical placements in memory (non-contiguous). Each element points o the next. 3. Programming ‘+ Programming is a transferable skill ‘+ Transferable skill: skills developed in one situation which can be transferred to another situation 3.2. Variables + Declaring a variable: CAIE AS LEVEL COMPUTER SCIENCE (9618) + Pseudocode: “python DECLARE : " + Python: no need to declare however must write above a5 a comment ("python #..) ‘+ Assigning variables: “python " or “python TO’ STEP ENDFOR for xin range(valuel, value2):| statements) Post condition Loop REPEAT UNTIL Pre-condition Loop WHILE ENDWHILE Not possible in Python Use “python WHILE" and “python IP" while expression: statement(s) 3.5, Built-in Functions String/character manipulation: = Uppercase or lowercase all characters: (string”) .upper() (“string”) lower 0) ‘© Finding length of a string: ten (“string”) * Converting: ‘© String to Integer- int (“string”) + Integer to String - str (integer) Random number generator: rancom.vandint (a, i) Where 2 and b defines the range 3.6. Benefits of Procedures and Functions: ‘© Lines of cade can be re-used; don't have to be repeated + Can be tested/improved independently of program + Easy to share procedures/functions with other programs ‘© Create routines that can be called like built-in command 3.7. Procedure Procedure: subroutine that performs a specific task without returning a value ‘+ Procedure without parameters: PROCEDURE def -ENDPROCEDURE _identifier()statement(s) + When a procedure has a parameter, the function can either pass it by either reference or value + Pass by value: data copied into procedure so variable not changed outside procedure FROCEDURE (BYVALUE : ) def identifier (param): statement (s) + Pass by reference: link to variable provided so variable changed after going through procedure (not in Python) FROCEDURE (BYREF : ) «statement (s)> ENDPROCEDU «Calling a procedure: ALLO Identifier 3.8. Function Function: subroutine that performs a specific task and returns avalue Functions are best used to avoid having repeating blocks of code in a program, as well as increasing the reusability of code in a large program. FUNCTION () RETURNS ENDFUNCTION def identifier (param): statement (s) return expression data CAIE AS LEVEL COMPUTER SCIENCE (9618) 4. Software Development 4.4. Program Development Cycle ‘+ Analyze problem: define problem, record program specifications and recognize inputs, process, output & Ul + Design program: develop logic plan, write algorithm in eg, pseudocode or flowchart and test solution + Code program: translate algorithm into high level language with comments/remarks and produce user interface with executable processes + Test and debug program: test program using test data, find and correct any errors and ensure results are correct + Formalize solution: review program code, revise internal documentation and create end-user documentation + Maintain program: provide education and support to end.user, correct any bugs and modify if user requests, ‘There are three different development life cycles: + Waterfall model: classical model, used to create a system with a linear approach, from one stage to another + Iterative model: a intial representation starts with a small subset, which becomes more complex over time until the system is complete ‘+ Rapid Application Development (RAD) model: 3 prototyping model, with no (or less) specific planning put into it. More emphasis on development and producing a product-prototype, 4.2. Integrated Development Environment ‘© Asoftware application that allows the creation of a program e.g. Python + Consists of a source code editor, build automation tools, a debugger Coding: = Reserved words are used by it as command prompts ‘© Listed in the end-user documentation of IDE + Aseries of files consisting of preprogrammed- subroutines may also be provided by the IDE Initial Error Detection: The IDE executes the code & initial error detection carried ‘out by compiler/interpreter doing the following: ‘© Syntax/Logic Error: before program is run, an error message warns the user about this, ‘+ Runtime Error: run of the program ends in an error Debugging: + Single stepping: traces through each line of code and steps into procedures. Allows you to view the effect of each statement on variables + Breakpoints: set within code; program stops temporarily to check that its operating correctly up to that point + Variable dumps (report window} at specific parts of program, variable values shown for comparison 4.3. Structure Charts + Purpose: used in structured programming to arrange program modules, each module represented by a box + Tree structure visualizes relationships between modules, showing data transfer between modules using arrows. + Example of e top-down design where a problem (program) is broken into its components. Rules: + Process: Represents a programming module eg. @ caleulation Process ‘+ Data couple: Deta being passed from module to module that needs to be processed o> ‘+ Flag: Check data sent to start or stop a process. Eg. check if data sent in the correct format e-> ‘Selection: Condition will be checked and depending on the result, different modules will be executed Process aN Process Process ‘Iteration: implies that module is executed multiple times Process Y Process Example: CAIE AS LEVEL COMPUTER SCIENCE (9618) Calculate Average ne rag & inputNum: outputAvg| average 4.4. Types of Errors syntax errors: = When source code does not obey rules of the language * Compiler generates error messages + Examples: ‘+ Misspell identifier when calling it ‘© Missing punctuation - colon after if ‘© Incorrectly using a builtin function ‘+ Argument being made does not match data type Run-time errors: + Source code compiles to machine code but fails upon execution (red lines show up in Python) + When the program keeps running and you have to kill it manually + Examples: * Division by 0 + Infinite loop - will not produce error message, program will just not stop until forced to Logic errors: ‘Program works but gives incorrect output + Exemples: ‘© Out By One - when >’ is used instead of >=" + Misuse of logic operators, 4.5. Corrective Maintenance + Corrective Maintenance is correcting identified errors + White-Box testing: making sample data and running it through a trace table + Trace table: technique used to test algorithms; make sure that no logical errors occur eg. ine [ aaegece [x [vatueixi> insgeet] output 4.6. Adaptive Maintenance + Making amendments to: + Parameters: due to changes in specification ‘+ Logic: to enhance functionality or more faster or both + Design: to make it more user friendly 47. Testing Strategies Black box testing: ‘+ Use test data for which results already calculated & compare result from program with expected results, + Testing only considers input and output and the code is, viewed as being in a black box’ White box testing: + Examine each line of code for correct logic and accuracy. + May record value of variables after each line of code + Every possible condition must be tested ‘Stub testing: + Stubs are computer programs that act as temporary replacement for a called module and give the same output as the actual product or software. + Important when code is not completed however must be tested so modules are replaced by stubs Dry run testing: + Aprocess where code is manually teaced, without any software used + The value ofa verlable is manually followed to check wihether itis used and updated as expected + Used to identify logic errors, but not execution errors Walkthrough testing: + Atest where the code is reviewed carefully by the developers peers, managers, team members, etc. ‘+ Itis used to gather useful feedback to further develop the code, Integration testing: ‘+ Taking modules that have been tested on individually and testing on them combined together CAIE AS LEVEL COMPUTER SCIENCE (9618) + This method allows all the code snippets to integrate with the developer. teach other, making the program work. «Basically another term for ‘second round of testing’ Alpha testing: ‘Acceptance testing: + Thisis the testing done on software ‘in-house’, meaning it | + Atest carried out by the intended users of the system: is done by the developers the people who requested the software. + Basically another term for first round of testing’ +The purpose isto check that the software performs, . exactly as required Beta testing: ‘+ The acceptance criteria should completely be satisfied for ‘© This is the testing done on the software by beta users, the program to be released who use the program and report any problems back to CAIE AS LEVEL Computer Science (9618)

You might also like