0% found this document useful (0 votes)
13 views10 pages

Programming Concepts and Structures Guide

The document provides an overview of programming concepts including control structures, data types, and modular design. It explains the use of loops, functions, and procedures, as well as file handling and error detection in programming. Additionally, it discusses the importance of structured programming and the role of Integrated Development Environments (IDEs) in code execution and debugging.

Uploaded by

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

Programming Concepts and Structures Guide

The document provides an overview of programming concepts including control structures, data types, and modular design. It explains the use of loops, functions, and procedures, as well as file handling and error detection in programming. Additionally, it discusses the importance of structured programming and the role of Integrated Development Environments (IDEs) in code execution and debugging.

Uploaded by

daterof880
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Prepared for Steve for personal use only.

• an instruction in a program that places a


value into a speci�ed variable
• programming statements are executed
consequently, as they appear in the program
• control structure in which there is a test to
• �ltering out and concentrating on the decide if certain instructions are executed
relevant information in a problem; allowing a • testing 2 possible outcomes
programmer to deal with complexity • testing more than 2 outcomes
• breaking down problems into sub- • control structure in which a group
problems in order to understand a process more clearly; of statements is executed repeatedly
program modules, procedures and functions all help the • count-controlled; executed a set no. of
programmer to break down large problems times
• a solution to a problem expressed as a • pre-conditional; executed based on
sequence of steps condition at start of statements
• post-conditional; executed based on
condition at end of statements

As for selecting what loop to use, it is best to use FOR loops


• name given to a variable in order to call it when you know the number of iterations required, and a
• An identi�er table depicts information about the WHILE or REPEAT loop if you do not know the number of
variable, e.g. iterations required.

• Iterate over an array: FOR Loop


• Reading a �le into a variable: WHILE Loop
• Asking for user input: WHILE/REPEAT Loop
• A loop that should execute n times: FOR Loop


• Must be unique
• Spaces must not be used • Process of developing a modular design by splitting a
• Must begin with a letter of the alphabet problem into smaller sub-tasks, which themselves are
• Consist only of a mixture of letters and digits and the repeatedly split into even smaller sub-tasks until each is
underscore character ‘_’ just one element of the �nal program.
• Must not be a ‘reserved’ word – e.g. Print, If, etc.

• This refers to a modular program design


• self-contained section of code, performing
a speci�c task; part of the main program
• performs a speci�c task, no value returned
to part of code where called
• performs a speci�c task, returns a value to
part of code where called

Copyright © 2025 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Steve at unde�ned on 20/04/25.
< Less than
<= Less than/equal
• An object that stores data, information, settings or
> Greater than commands
>= Greater/equal
= Equal to
• Can be opened, saved, deleted & moved
<> Not equal to • Transferrable across network connections

• Uses 1 byte to store a character


• 7 bits available to store data and 8th bit is a check digit
• 27 = 128, therefore 128 di�erent values
• ASCII values can take many forms: numbers, letters
(capitals and lower case are separate), punctuation, non-
• Positive or negative number; no fractional part
printing commands (enter, escape, F1)
• Held in pure binary for processing and storage
• Some languages di�erentiate short/long integers (more
bytes used to store long integers)

• ASCII allows few number of characters; it is good for


English
• Number that contains a decimal point
• Unicode allows others, too: Chinese, Greek, Arabic, etc.
• Referred to as singles and doubles depending upon the
• Di�erent types of Unicode:
number of bytes used to store
• UTF-8: compatible with ASCII, variable-width encoding
can expand to 16, 24, 32, 40, 48
• UTF-16: 16-bit, variable-width encoding can expand
• A character is any letter, number, punctuation or space to 32 bits
• Takes up a single unit of storage (usually a byte). • UTF-32: 32-bit, �xed-width encoding, each character
exactly 32 bits

• Combination of alphanumeric characters enclosed in “ ”


• Each character is stored in one byte using ASCII code
• Each character is stored in two bytes using Unicode • declared using a single index,
• The maximum length of a string is limited by available can be represented as a list
memory.
• Incorrect to store dates or numbers as strings
• Phone no. must be stored as a string; otherwise, the
initial 0 is lost

• It can store one of only two values; “True” or “False.”


• Stored in 1 byte: True = 11111111, False = 00000000

• Dates are stored as a ‘serial’ number


• Equates to the number of seconds elapsed since 1st
January 1970 00:00:00 UTC, excluding leap seconds. • declared using two indices,
• Usually takes 8 bytes of storage can be represented as a table
• Displayed as dd/mm/yyyy or mm/dd/yyyy

• Data structure consisting of a collection of elements


• Identi�ed by at least one array index (or key)

Copyright © 2025 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Steve at unde�ned on 20/04/25.
• A FOR loop is set to stop the sort
• Setting a variable ‘sorted’ to be ‘true’ at the beginning
• Another FOR loop is set up next in order to search
through the array
• An IF is used to see if the �rst number of the array is
greater than the second. If true:
• First number stored to variable
• Second number assigned as �rst number
• Stored variable assigned to second number
• Set ‘sorted’ to ‘false’ causing loop to start again
• The second FOR loop is count based thus will stop after a
speci�c number of times
• • Goes through bigger FOR loop ∴ ‘sorted’ remains ‘true’
• 1-D Array: array = [] • This exits the loop ∴ ending the program
• 2-D Array: array = [[], [], [], …]

• Declaring an array: names = []
• Adding to an array: [Link](‘ZNotes’)
• Length of array, i.e. number of elements:
len(names)
• Printing an element in a 1D array:
print(names[element position]) • A FOR loop goes through the array
• Printing element in a 2D array: print (a[row] • It compares item in question to those in list using an IF:
[column]) • If item matches with another then search is stopped
• Printing row in a 2D array: names[row] = [new • Also the location where it was found is returned
row] • If not found it exits the FOR loop
• Printing column: Use it for loop, add 1 to the row, and • Then returns fact that item in question is not in the list
keep the column the same.

• Files are needed to import contents (from a �le) saved in


secondary memory into the program, or to save the
output of a program (in a �le) into secondary memory, so
that it is available for future use

• Opening a �le: OPENFILE <filename> FOR READ/


WRITE/APPEND
• Reading a �le: READFILE <filename>, <variable>
• Writing a line of text to the �le: WRITEFILE
<filename>, <string>
• Closing a �le: CLOSEFILE <filename>
• Testing for end of the �le: EOF(filename)

• Opening a �le: variable = open(“filename”,


“mode”)

Where the mode can be:

Copyright © 2025 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Steve at unde�ned on 20/04/25.
‘’’python identi�er = value‘’’ or ‘’’python expression‘’’ or
r Opens �le for reading only. Pointer placed at the beginning of the �le.
w
Opens a �le for writing only. Overwrites �le if �le exists or creates new �le if it ‘’’python “string”‘’’
doesn’t
Opens a �le for appending. Pointer at end of �le if it exists or creates a new �le if
a
not

• Reading a �le:
• Read all characters: [Link]() • “IF” Statement
• Read each line and store as list: • Pseudocode: IF…THEN…ELSE…ENDIF
[Link]() • Python: if (expression): (statements) else:
• Writing to a �le: (statements)
• Write a �xed a sequence of characters to �le: • “CASE” Statement
[Link](“Text”) • Pseudocode: CASE OF variable: … … …
• Write a list of string to �le: [Link](‘ OTHERWISE: … ENDCASE
‘.join(‘Z’, ‘Notes’)) • Python: if (expression): (statement) elif
(expression): statement) … else:
(statement)

FOR <identi�er> ← <val1> TO <val2> STEP <val3>


An is a collection of data with <statement(s)>
ENDFOR
associated operations. There are three types of ADTs: for x in range(value1, value2):
statement(s)
Post condition Loop
• an ordered collection of items where the addition REPEAT
Not possible in Python
of new items and removal of existing items always takes <statement(s)>
UNTIL <condition>
Use ‘’’python WHILE‘’’ and ‘’’python IF‘’’

place at the same end. Pre-condition Loop


WHILE <condition>
• a linear structure which follows the First In First <statement(s)>
while expression:
statement(s)
ENDWHILE
Out (FIFO) mechanism. Items are added at one end
(called the rear) and removed from the other end (called
the front)
• a linear collection of data elements whose
order is not given by physical placements in memory
(non-contiguous). Each element to the next.
• Uppercase or lowercase all characters:
(“string”).upper() (“string”).lower()
• Finding length of a string: len(“string”)
• Converting:
• String to Integer - int(“string”)
• Programming is a transferable skill
• Integer to String - str(integer)
• skills developed in one situation
which can be transferred to another situation. [Link](a, b)
Where a and b de�nes the range


• Pseudocode: ‘’’DECLARE : ‘’’
• Python: no need to declare however must write
above as a comment (‘’’python #...‘’’) • Lines of code 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
‘’’python ← ‘’’ or ‘’’python ‘’’ • Create routines that can be called like built-in command

Copyright © 2025 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Steve at unde�ned on 20/04/25.
subroutine that performs a speci�c task without
returning a value • de�ne problem, record program
speci�cations and recognize inputs, process, output & UI
• • develop logic plan, write algorithm in
e.g. pseudocode or �owchart and test solution
• translate algorithm into high level
• When a procedure has a parameter, the function can language with comments/remarks and produce user
either pass it by either reference or value interface with executable processes
• data copied into procedure so variable • test program using test data,
not changed outside procedure �nd and correct any errors and ensure results are
correct
PROCEDURE <identifier> (BYVALUE <param>: • review program code, revise
<datatype>) internal documentation and create end-user
<statement(s)> documentation
ENDPROCEDURE • provide education and support to
def identifier(param): end-user, correct any bugs and modify if user requests
statement(s)

• link to variable provided so variable


changed after going through procedure (not in Python) • a classical model, used to create a
system with a linear approach, from one stage to
PROCEDURE <identifier> (BYREF <param>: another
<datatype>) • a initial representation starts with a
<statement(s)> small subset, which becomes more complex over time
ENDPROCEDURE until the system is complete
• a
• prototyping model, with no (or less) speci�c planning put
into it. More emphasis on development and producing a
product-prototype.

subroutine that performs a speci�c task and


returns a value
Functions are best used to avoid having repeating blocks of • A software application that allows the creation of a
code in a program, as well as increasing the reusability of program e.g. Python
code in a large program. • Consists of a source code editor, build automation tools,
FUNCTION <identifier> (<parameter>: <data a debugger
type>) RETURNS <datatype>
<statement(s)>
ENDFUNCTION
def identifier(param): • Reserved words are used by it as command prompts
statement(s) • Listed in the end-user documentation of IDE
return expression • A series of �les consisting of preprogrammed-
subroutines may also be provided by the IDE

Copyright © 2025 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Steve at unde�ned on 20/04/25.
• 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

• Single stepping: traces through each line of code and


steps into procedures. Allows you to view the e�ect of
each statement on variables • Implies that module is executed multiple
• Breakpoints: set within code; program stops temporarily times
to check that it is operating correctly up to that point
• Variable dumps (report window): at speci�c parts of
program, variable values shown for comparison

• 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 a top-down design where a problem
(program) is broken into its components.

• Represents a programming module e.g. a


calculation

• Data being passed from module to module


that needs to be processed

• Check data sent to start or stop a process. E.g.


check if data sent in the correct format

• When source code does not obey rules of the language


• Compiler generates error messages
• Condition will be checked and depending on • Examples:
the result, di�erent modules will be executed • Misspell identi�er when calling it
• Missing punctuation – colon after if
• Incorrectly using a built-in function
• Argument being made does not match data type

Copyright © 2025 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Steve at unde�ned on 20/04/25.
• Use test data for which results already calculated &
• Source code compiles to machine code but fails upon compare result from program with expected results
execution (red lines show up in Python) • Testing only considers input and output and the code is
• When the program keeps running and you have to kill it viewed as being in a ‘black box’
manually
• Examples:
• Division by 0
• Examine each line of code for correct logic and accuracy.
• In�nite loop – will not produce error message,
• May record value of variables after each line of code
program will just not stop until forced to
• Every possible condition must be tested

• Program works but gives incorrect output


• Stubs are computer programs that act as temporary
• Examples:
replacement for a called module and give the same
• Out By One – when ‘>’ is used instead of ‘>=’
output as the actual product or software.
• Misuse of logic operators
• Important when code is not completed however must be
tested so modules are replaced by stubs

• Corrective Maintenance is correcting identi�ed errors


• A process where code is manually traced, without any
• making sample data and running it
software used
through a trace table
• The value of a variable is manually followed to check
• technique used to test algorithms; make
whether it is used and updated as expected
sure that no logical errors occur e.g.
• Used to identify logic errors, but not execution errors

• A test where the code is reviewed carefully by the


developer’s peers, managers, team members, etc.
• It is used to gather useful feedback to further develop
the code.

• Taking modules that have been tested on individually


and testing on them combined together
• This method allows all the code snippets to integrate
with each other, making the program work.

• Making amendments to:


• due to changes in speci�cation
• to enhance functionality or more faster or • This is the testing done on software ‘in-house’, meaning it
both is done by the developers
• to make it more user friendly • Basically another term for ‘�rst round of testing’

• This is the testing done on the software by beta users,


who use the program and report any problems back to
the developer.
• Basically another term for ‘second round of testing’

Copyright © 2025 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Steve at unde�ned on 20/04/25.
• A test carried out by the intended users of the system:
the people who requested the software.
• The purpose is to check that the software performs
exactly as required.
• The acceptance criteria should completely be satis�ed
for the program to be released.

Copyright © 2025 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Steve at unde�ned on 20/04/25.
© ZNotes Education Ltd. & ZNotes Foundation 2025. All rights reserved.
This version was created by Steve on Sun Apr 20 2025 for strictly personal use only.
These notes have been created by Nethul Gunasekara & Shaikh Ayman Abdul-Majid for the 2024-2025 syllabus.
The document contains images and excerpts of text from educational resources available on the internet and printed books.
If you are the owner of such media, test or visual, utilized in this document and do not accept its usage then we urge you to contact us
and we would immediately replace said media. No part of this document may be copied or re-uploaded to another website.
Under no conditions may this document be distributed under the name of false author(s) or sold for �nancial gain.
"ZNotes" and the ZNotes logo are trademarks of ZNotes Education Limited (registration UK00003478331).

Common questions

Powered by AI

Structured programming organizes programs into modules or blocks which facilitates the localization of errors, making the process of error detection and correction more efficient. Through techniques like single stepping and the use of breakpoints, a developer can focus on individual modules for testing and validation, helping to identify and resolve syntax or logic errors more easily. Moreover, this modular approach allows for targeted debugging, as each module operates semi-independently within the larger program structure .

ASCII is a character encoding standard that uses 7 bits to represent 128 different characters, mainly suited for the English language. In contrast, Unicode is a more versatile and expansive encoding system that can represent characters from multiple languages, including Chinese, Greek, and Arabic, using different formats such as UTF-8, UTF-16, and UTF-32. The importance lies in Unicode's ability to accommodate global text processing by supporting a larger variety of characters and symbols from worldwide scripts .

IF statements in algorithms are pivotal for control flow as they enable decision-making by allowing the program to execute certain code blocks based on logical conditions. Used extensively to create branches in execution, IF statements help navigate different program paths by testing conditions and directing operations accordingly. This is essential in implementing complex algorithms where outcomes depend on dynamic input values or state variables, facilitating adaptability and precision in software behavior .

In programming, integers are stored in a binary form, which involves representing numbers using a sequence of bit values (0s and 1s). This binary representation is compact and allows for efficient arithmetic processing by computers. The use of pure binary forms requires understanding of integer limits and overflow risks, as well as differentiation between data sizes, like short and long integers, which use varying amounts of storage bytes. Moreover, binary representation is crucial for efficient data processing and power conservation in hardware systems .

Stubs are used in software testing as temporary replacements for modules that have yet to be developed or are being unit-tested independently. They replicate the behavior of the actual module by returning predetermined outputs. This allows other parts of the system to be tested in isolation, ensuring that interactions between modules behave as expected without needing the complete application. Stubs are particularly useful in integration testing when certain modules are still under development .

File handling operations differ by mode: 'r' (reading) opens a file for reading, placing the pointer at the beginning so data can be progressively accessed; 'w' (writing) opens a file for writing, overwriting existing data or creating a new file; and 'a' (appending) opens a file for adding new data at the end without altering existing content. Reading modes are used when data must be consumed or parsed, writing when generating or exporting data files, and appending for adding logs or continuing data collections .

A FOR loop should be used when the number of iterations is known beforehand, as it is count-controlled. It is ideal for iterating over predefined collections or sequences like arrays. Meanwhile, a WHILE loop is better suited when the number of iterations is variable or dependent on a condition being met; it can continue executing based on a condition at the start (pre-conditional) or the end (post-conditional) of the loop. For example, a WHILE loop is suitable for reading a file into a variable until a condition such as end-of-file is met .

Logic errors occur when a program runs but doesn't produce the expected result, often due to incorrect logical constructs or flawed algorithms. Syntax errors, however, are detected at compile time when program code violates the grammatical rules of the programming language, preventing execution. Logic errors result in incorrect computations or operations, whereas syntax errors halt progress before the program begins. Addressing each type requires different debugging approaches, with syntax errors fixed by correcting code structure and logic errors by altering the underlying logic .

Testing with known input and output values, often referred to as test cases, is critical in debugging because it allows developers to verify that their program behaves as expected under controlled conditions. Such testing uncovers discrepancies between anticipated and actual results, spotlighting errors in the program's logic or implementation. By comparing outputs against expected results, developers can trace faulty logic, debug effectively, and ensure the program's reliability and correctness across different input scenarios .

Modular program design allows programmers to break down complex problems into smaller, manageable sub-tasks until each task is just one element of the final program. This process involves developing a modular design by repeatedly splitting the problem into smaller sub-tasks, facilitating a clearer understanding and allowing for focused problem-solving on individual modules .

You might also like