0% found this document useful (0 votes)
8 views8 pages

Chapter 11 Notes

The document provides an overview of programming basics, including converting flowcharts and structured English into pseudocode, and outlines key programming constructs such as conditional statements, looping structures, and procedures. It emphasizes the importance of using pseudocode for algorithm development and includes examples of various programming techniques. Additionally, it covers the use of parameters in procedures and functions, as well as built-in functions for string manipulation and arithmetic operations.

Uploaded by

nkengkate3
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)
8 views8 pages

Chapter 11 Notes

The document provides an overview of programming basics, including converting flowcharts and structured English into pseudocode, and outlines key programming constructs such as conditional statements, looping structures, and procedures. It emphasizes the importance of using pseudocode for algorithm development and includes examples of various programming techniques. Additionally, it covers the use of parameters in procedures and functions, as well as built-in functions for string manipulation and arithmetic operations.

Uploaded by

nkengkate3
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

11.

1 Programming Basics
Implementing Pseudocode from a Given Design
Candidates should be able to convert a program flowchart or structured English into
pseudocode.

d
hi
Za
a
hr
Za
Za
hr
a
Za
hi
d
Pseudocode to calculate area of rectangle:
DECLARE length, width, area AS REAL
OUTPUT "Enter length: "
INPUT length
OUTPUT "Enter width: "
INPUT width
area ← length * width
OUTPUT "The area is ", area
Key Skills Required:
• Convert flowcharts and structured English into working pseudocode.

d
• Use arithmetic operations, input/output, and control structures properly.

hi
11.2 Programming Constructs
Conditional Statements Za
IF Statement (Including ELSE Clause and Nested IFs)

IF age >= 18 THEN


OUTPUT "You are an adult."
ELSE
a

OUTPUT "You are a minor."


hr

ENDIF
Nested IF Statement
IF age >= 18 THEN
Za

IF age >= 65 THEN


OUTPUT "You are a senior citizen."
ELSE
OUTPUT "You are an adult."
ENDIF
ELSE
OUTPUT "You are a minor."
ENDIF
CASE Statement (Switch Statement Alternative)
Used when multiple conditions exist.

CASE OF day
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday": OUTPUT "Weekday"
"Saturday", "Sunday": OUTPUT "Weekend"
OTHERWISE:
OUTPUT "Invalid day"
ENDCASE
When to use?

d
• Use CASE when checking a single variable against multiple possible values.

hi
• Use IF-ELSE when conditions involve complex expressions.

Looping Structures (Iteration) Za


Count-Controlled Loop (FOR Loop)
Used when the number of iterations is known in advance.

FOR i ← 1 TO 10
OUTPUT i
a

ENDFOR
hr

Pre-Condition Loop (WHILE Loop)


Used when the number of iterations is unknown and should only run while a condition
Za

is true.

DECLARE num AS INTEGER


num ← 0
WHILE num < 5 DO
OUTPUT num
num ← num + 1
ENDWHILE
Post-Condition Loop (REPEAT-UNTIL Loop)
Ensures the loop executes at least once, regardless of the condition.

REPEAT
OUTPUT "Enter a positive number: "
INPUT num
UNTIL num > 0
When to use?

Loop Type Use Case

FOR When the number of iterations is fixed (e.g., looping 10 times).

d
When the condition should be checked before execution (e.g., wait for

hi
WHILE
user input).

REPEAT- When the code must execute at least once before checking the
UNTIL condition.
Za
11.3 Structured Programming
Procedures (Subroutines)
a

A procedure is a block of reusable code that performs a specific task but does not
hr

return a value.
Defining and Using a Procedure
Za

PROCEDURE Greet()
OUTPUT "Hello, welcome!"
ENDPROCEDURE

Greet() // Calling the procedure


Where to use a procedure?
• When a block of code needs to be reused multiple times.
• For modular and structured programming.
Functions
A function is similar to a procedure but returns a value.
Defining and Using a Function

FUNCTION Square(num)
RETURN num * num
ENDFUNCTION

DECLARE result AS INTEGER


result ← Square(4)

d
OUTPUT "Square of 4 is ", result

hi
Where to use a function?
• When a value needs to be computed and returned.
• For mathematical calculations or data processing.
Za
Parameters in Procedures and Functions
Using Parameters in a Procedure

PROCEDURE Greet(name: STRING)


a

OUTPUT "Hello, " & name


hr

ENDPROCEDURE

Greet("Alice") // Calling the procedure with a parameter


Za

Passing Parameters: By Value vs. By Reference

Method Description Example Use Case

Sending an integer to a
Pass by The procedure gets a copy of the variable
function that performs a
Value (original remains unchanged).
calculation.

The procedure gets the memory address


Pass by Modifying a list inside a
of the variable (original value can be
Reference procedure.
modified).
PROCEDURE ModifyValue(BYREF num: INTEGER)
num ← num + 10
ENDPROCEDURE

DECLARE x AS INTEGER
x ←5
ModifyValue(x)
OUTPUT x // Output will be 15 (original variable changed)
When to use?

d
• Pass by Value: When the function should not modify the original value.

hi
• Pass by Reference: When the function should modify the original value.

Terminology in Procedures and Functions


Za
Term Description

Procedure Header First line defining the procedure.

Function Header First line defining the function.


a

Parameter Variable passed inside the function/procedure.


hr

Argument The actual value passed when calling the function.

Return Value The value a function sends back after execution.

Example:
Za

FUNCTION Add(a: INTEGER, b: INTEGER)


RETURN a + b
ENDFUNCTION

DECLARE sum AS INTEGER


sum ← Add(5, 10) // "5" and "10" are arguments
Writing Efficient Pseudocode
1. Declaration and Initialization of Constants
CONST PI ← 3.1416
2. Declaration and Assignment of Variables
DECLARE age AS INTEGER
age ← 18
3. Using Arithmetic and Logical Operators
total ← price * quantity
IF (age >= 18 AND hasID = TRUE) THEN
OUTPUT "You can vote"

d
ENDIF

hi
4. Input and Output
OUTPUT "Enter your name: "
INPUT name Za
OUTPUT "Hello, " & name

Built-in Functions and Library Routines


Candidates should use provided built-in functions in pseudocode, such as:
a

Function Description

LENGTH(string) Returns length of a string


hr

MID(string, start, length) Extracts a part of a string

UPPERCASE(string) Converts string to uppercase


Za

LOWERCASE(string) Converts string to lowercase

ROUND(number, decimalPlaces) Rounds a number to given decimal places

RANDOM(min, max) Generates a random number between min and max

Example of string manipulation:

DECLARE name AS STRING


name ← "Alice"
OUTPUT LENGTH(name) // Output: 5
OUTPUT UPPERCASE(name) // Output: "ALICE"

You might also like