CS Notes P2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

 Data type: classification of data into groups according to the kind of data they

represent

 Variables and constants are used to store a single item of data in a program. This can
be accessed through the identifier. Variables can be changed during program execution
while constants remain the same.
 Output refers to the process of displaying or saving the results of a program to the
user.Input refers to the process of providing data or information to a program
 Sequence is a concept that involves executing instructions in a particular order

 Selectionis a concept that allows you to execute different sets of instructions based on
certain conditions.
o IF statements allo w you to execute a set of instructions if a condition is true.
o IF… ELSE statements are used to execute one set of instructions if a condition
is true and a different set of statements if the condition is false.
o IF… ELSE… IF statements are used to test multiple conditions and execute
different statements for each condition.
o CASE statements allow you to execute different sets of instructions based on
the value of a variable.

 Iterationis the process of repeating a set of instructions until a specific condition


is met.There are three main types of iteration:

Count-controlled loops
- A count-controlled loop is used when the number of iterations is known beforehand
- It is also known as a definite loop
- It uses a counter variable that is incremented or decremented after each iteration
- The loop continues until the counter reaches a specific value

Pre-condition loops

- A precondition loop is used when the number of iterations is not known beforehand and
is dependent on a condition being true
- It is also known as an indefinite loop
- The loop will continue to execute while the condition is true and will stop once the
condition becomes false
- It might not be iterated – even once.

Post-condition loops

- A post-condition loop is used when the loop must execute at least once, even if the
condition is false from the start
- The condition is checked at the end of the loop
 Strings are a sequence of characters, such as letters, numbers, and symbols.
They are used to represent text in a computer program
 String handling refers to the various operations that can be performed on
strings
 Addition (+): Adds two values together
 Subtraction (-): Subtracts one value from another
 Division (/): Divides one value by another
 Multiplication (*): Multiplies two values together
 Exponentiation (^): Raises a number to a power

 Boolean operators are logical operators that can be used to compare two or
more values and return a Boolean value (True or False) based on the
comparison. There are 3 you need to know:
o AND: Returns True if both conditions are True
o OR: Returns True if one or both conditions are True 4
o NOT: Returns the opposite of the condition (True if False, False if
True)

 Nested 855655 selection is an if statement inside an if statement


 If the first if statement is true, it will run the if statement which is nested inside
 Otherwise, it will skip to the "else if" or "else" which is part of that if statement

 Procedures and functions are types of subroutines. They are a sequence of


instructions that perform a specific task or set of tasks. They are placed under an
identifier (name) by which they can be called at any point in the program.
 Parameters are values that are passed into a subroutine.They can be passed by
value or by reference.

o When a parameter is passed by value, a copy of the parameter is made


and used within the subroutine
o When a parameter is passed by reference, the original parameter is used
within the subroutine, and any changes made to the parameter will be
reflected outside of the subroutine
 What's the difference between a procedure and function?
Functions return a value whereas a procedure does not. The return value can be
stored in a variable.
 Defining and Calling a Subroutine
A subroutine only needs to be defined once to set it up. After this you can call it
as many times as needed to use it.
 A local variable is a variable that is declared inside a subroutine and can only be
accessed from within that subroutine. It cannot be changed in any other part. It’s
scope is limited to the subroutine
 A global variable is a variable that is declared outside of a subroutine and can be
accessed from anywhere in the program. Global variables can be used to pass
data between different subroutine i.e. they can be changed. Their scope covers
the whole program

 Library routines are pre-written code that can be used in programs to perform
specific tasks.
o Using library routines saves time by not having to write code from scratch
o Library routines are also tested and proven to work, so errors are less
likely
 MOD: a function that returns the remainder when one number is divided by another
number
 DIV: a function that returns the quotient when one number is divided by another number
 ROUND: a function that rounds a number to a specified number of decimal places
 RANDOM: a function that generates a random number between two extreme values

Why is it important to create a maintainable program?

 Improve program quality:


o A maintainable program is easier to understand and modify, which leads to
fewer bugs and better program quality
 Reduce development time and costs:
o A maintainable program requires less time and effort to modify, which reduces
development time and costs
 Enables collaboration:
o A maintainable program makes it easier for multiple developers to work together
on the same project, as it's easier to understand and modify

How do you create a well maintained program?

 Use meaningful identifiers


o Identifiers are names given to variables, constants, arrays, procedures and
functions
o Use descriptive and meaningful identifiers to make your code easier to
understand and maintain
o Avoid using single letters or abbreviations that may not be clear to others
 Use the commenting feature provided by the programming language
o Comments are used to add descriptions to the code that help readers understand
what the code is doing
o Use comments to explain the purpose of variables, constants, procedures,
functions and any other parts of the code that may not be immediately clear

 Use procedures and functions


o Procedures and functions should have descriptive names that clearly indicate
what they do
o Prevents duplication of frequently used code – improving readability

 Leave white spaces and indentations


o This would make the code easier to read

 A one-dimensional (1D) array is a collection of items of the same data type – a


list. Elements can be accessed using the same identifier. However, each element
has a single index which can begin from 0 or 1.
 A two-dimensional (2D) array is an array of arrays, creating a grid-like
structure.To access elements in a 2D array, use two indices: the row index and
the column index.

Why Use Files?

 Files provide a way to store data permanently, allowing programs to access and
manipulate it later
 Files allow for organised storage of data – especially large amounts - making it easier to
find, access, and update
 They enable sharing of data between different programs and users
 They support data backup, ensuring data is not lost when a program or computer system
shuts down
 Data can be transported from one system to another

You might also like