Cs Paper 2 Notes
Cs Paper 2 Notes
Analysis:
○ Analysing the problem to be solved by clearly defining it
○ Involves “Abstraction” where unnecessary details to the problem is discarded
○ Involves “Decomposition” to exactly determine the requirements of the
program by breaking the problem into smaller pieces
Design:
○ Shows how the program can be developed,By formally documenting it using
structure diagrams,flowcharts,pseudocode
Coding(And iterative testing):
○ The program or set of programs are developed,each module of the program
is then tested and edited to work as intended before moving onto the next
module.
Testing:
○ The program is tested with different types of test data to make sure it is
working as intended and solves the initial problem
Test data:
Normal test data:
○ Data that the program should accept,used to check if program accepts and
process expected data
Abnormal test data:
○ Data that the program should reject,Used to check if the program rejects data
that should not be accepted
Extreme test data:
○ Data that the program should accept,Used to check if the program accepts
the lowest and highest values that should be accepted
Boundary test data:
○ Data that the program should accept and reject,Used to check if the program
accepts the lowest and highest values that should be accepted and rejects
their counterparts above and below the accepted range.
Validation checks:
Length checks: Checks for the length of a string/array
Range check: Checks if number is within a specific range
Type check: Checks the variable type of a variable
Presence check: Checks if there is a value present in input
Format check: Checks if the input follows a specific format
Check digits: Checks if the value was entered incorrectly
Verification checks:
Double entry: Input is given 2 times to see if they match
Screen/Visual check: A check by the user ensure the input is valid
Decomposing a problem:
The component parts of any computer system are:
Inputs
Processes
Outputs
Storage
Flowcharts:
Structure diagram:
Pseudocode:
Counting Count←Count+1
Totaling Total←Total+Number
Common definitions:
● Constant: Used to store values that do not change throughout the program;Ex: pi.
● Variables: Used to store values that do change throughout the program or in runtime;Ex:
Looping variables.
● Functions: A group of programming statements under a defined name that can be called
repeatedly through the program with the defined name,the function returns a value back to
the program it was called in;Ex: a function to do integer division.
● Procedures: A group of programming statements under a defined name that can be called
repeatedly through the program with the defined name,the procedure does not return a value
back to the program it was called in.
● Local variables: A local variable is a variable that can only be used in the module of code it
was defined in,it does not have a special syntax to initialize it.
● Global variables: A global variable is a variable that can be used anywhere in the code it
was defined in,it does have a special syntax to initialise it.
Database data types:
Data type Example Description
Text “Hello world” A group or ‘string’ of characters
(OR)
‘Hello 1234’
Character “M” (OR) ‘4’ A single character
Create a table:
Format: EXAMPLE:
CREATE TABLE <table name>( CREATE TABLE Students (
<Field Name> <Field Type> PRIMARY KEY, StudentID TEXT NOT NULL PRIMARY KEY,
<Field Name> <Field Type> , StudentName TEXT NOT NULL,
<Field Name> <Field Type> ); StudentGrade INTEGER NOT NULL,
StudentDOB DATE NOT NULL,
StudentAvgMarks REAL NOT NULL,
StudentGender CHARACTER NOT NULL,
IsStudentTopper BOOLEAN NOT NULL);
Insert values into table:
INSERT INTO <table name> VALUES (<value1>,<value 2>,…<value n>);
Inserts a record of all values given for each field into the specified table name
[Text in blue]: Select the values of a field from a specified table, this part of the statement is necessary.
Ex: SELECT code, price FROM Items {returns fields codes and price from table items}
[Text in orange]: Selects the values from the field only if the condition is true, not necessary for the statement to
work.
Ex: SELECT * FROM Items WHERE Price > 250 {returns the whole record of any item with a price over
250}
[Text in purple]: Returns the values in alphabetical order, if DESC is specified then the order is reversed, not
necessary for the statement to work.
Ex: SELECT Item_code FROM Items ORDER BY Item_name {returns items codes by the alphabetical order
of its name}
Extras:
SELECT SUM (<Field>) {Returns the sum of the values in the field, field should be INT or REAL}
SELECT COUNT (<Field>) {Returns the number of records for that field}
Updates the values in the field of a specified table to the new value where the condition is true.
The condition is not necessary.
Logic gates:
Bubble sort:
First ← 1
Last ← 10
REPEAT
Swap ← FALSE
FOR Index ← First TO Last - 1
IF Temperature[Index] > temperature[Index + 1] THEN
Temp ← Temperature[Index]
Temperature[Index] ← Temperature[Index + 1]
Temperature[Index + 1] ← Temp
Swap ← TRUE
ENDIF
NEXT Index
Last ← Last - 1
UNTIL (NOT Swap) OR Last = 1
Linear search:
MaximumMark ← 0
MinimumMark ← 100
FOR Counter ← 1 TO ClassSize
IF StudentMark[Counter] > MaximumMark
THEN
MaximumMark ← StudentMark[Counter]
ENDIF
IF StudentMark[Counter] < MinimumMark
THEN
MinimumMark ← StudentMark[Counter]
ENDIF
NEXT Counter
Total ← 0
FOR Counter ← 1 TO ClassSize
Total ← Total + StudentMark[Counter]
NEXT Counter
Average ← Total / ClassSize
● Pseudocode writing Q:
○ Always recheck the “AND” and “OR” operators in a conditional statement as
they are easy to confuse