0% found this document useful (0 votes)
4 views6 pages

Module 3

This document outlines the fundamentals of structured programming, including definitions of programming, algorithms, flowcharts, and pseudocode. It emphasizes the importance of a structured problem-solving process and provides examples of algorithms and flowcharts. Additionally, it covers variables, data types, and constants, highlighting their roles in programming.

Uploaded by

romeothird15
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)
4 views6 pages

Module 3

This document outlines the fundamentals of structured programming, including definitions of programming, algorithms, flowcharts, and pseudocode. It emphasizes the importance of a structured problem-solving process and provides examples of algorithms and flowcharts. Additionally, it covers variables, data types, and constants, highlighting their roles in programming.

Uploaded by

romeothird15
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

Structured Programming — Week 1

STRUCTURED PROGRAMMING
Course Module — Week 2

Module 3
Concepts, Algorithms, Flowcharts, and Pseudocode
with Variables, Data Types, and Constants

Page 1
Structured Programming — Week 1

Learning Objectives
By the end of this session, students should be able to:

• Define programming and explain its role in problem-solving.


• Describe the program development life cycle.
• Explain what an algorithm is and identify its key characteristics.
• Construct simple flowcharts using standard symbols.
• Write pseudocode for basic problem-solving tasks.
• Identify and correctly declare variables, data types, and constants in a program.

1. Introduction to Programming
1.1 What is Programming?
Programming is the process of designing and writing a set of instructions that a computer follows to perform a specific
task or solve a problem. These instructions are written in a programming language such as C, Python, or Java, and are
eventually translated into machine-readable code that the computer's processor can execute.

A computer, by itself, cannot think or make decisions. It only follows instructions exactly as they are given. This is why
the quality of a program depends entirely on how clearly and logically its instructions are designed before any code is
written.

1.2 The Problem-Solving Process


Before writing any code, a programmer follows a structured problem-solving process:

• Problem Definition — Understand what the problem is asking and what output is expected.
• Analysis — Identify the given data (input), the required result (output), and any constraints.
• Algorithm Design — Plan the logical steps needed to solve the problem.
• Coding — Translate the algorithm into a programming language.
• Testing and Debugging — Run the program and correct any errors.
• Documentation and Maintenance — Record how the program works and update it as needed.
Structured programming emphasizes doing the analysis and design steps thoroughly — through algorithms, flowcharts,
and pseudocode — before a single line of code is typed.

2. Algorithms
2.1 Definition
An algorithm is a finite, ordered set of well-defined steps or instructions designed to solve a specific problem or
accomplish a particular task. It is written in plain, human-readable language and is independent of any specific
programming language.

2.2 Characteristics of a Good Algorithm


Characteristic Description
Finiteness Must terminate after a limited number of steps.
Definiteness Each step must be clear and unambiguous.
Input May take zero or more inputs from the user or system.

Page 2
Structured Programming — Week 1

Characteristic Description
Output Must produce at least one output or result.
Effectiveness Each step must be simple enough to be carried out
precisely.

2.3 Example Algorithm


Problem: Compute the sum of two numbers entered by the user.

Step 1: Start
Step 2: Input the first number, A
Step 3: Input the second number, B
Step 4: Compute SUM = A + B
Step 5: Display SUM
Step 6: End

3. Flowcharts
3.1 Definition
A flowchart is a diagram that represents an algorithm or process, using standardized symbols connected by arrows to
show the sequence and flow of steps and decisions.

3.2 Standard Flowchart Symbols


Symbol Name and Purpose
Oval / Terminator Represents the Start or End of a program.
Parallelogram Represents Input or Output operations (e.g., reading or
displaying data).
Rectangle Represents a Process — a computation or assignment
step.
Diamond Represents a Decision — a point where the flow branches
based on a condition (Yes/No, True/False).
Arrow Represents the Flow of Control — the direction the
process moves.
Circle (small) Represents a Connector — links parts of the flowchart,
often across pages.

3.3 Example: Flowchart Logic for Sum of Two Numbers


The flowchart for the algorithm above follows this sequence of shapes:

• Start (Oval)
• Input A, B (Parallelogram)
• SUM = A + B (Rectangle)
• Display SUM (Parallelogram)
• End (Oval)
Note: Have students draw this flowchart by hand or using a diagramming tool (e.g., [Link], Lucidchart) as an in-class
activity.

3.4 Example with a Decision Structure


Problem: Determine whether a number is positive or negative.

• Start

Page 3
Structured Programming — Week 1

• Input N
• Decision: Is N ≥ 0?
◦ If Yes → Display "Positive"
◦ If No → Display "Negative"
• End

4. Pseudocode
4.1 Definition
Pseudocode is a semi-formal, English-like way of describing an algorithm's logic without following the strict syntax
rules of any particular programming language. It bridges the gap between a plain-language algorithm and actual source
code.

4.2 Common Pseudocode Conventions


Keyword Usage
START / END Marks the beginning and end of the pseudocode.
INPUT / READ Indicates data entry from the user.
OUTPUT / DISPLAY / PRINT Indicates data shown to the user.
IF / ELSE / ENDIF Represents a decision structure.
WHILE / FOR / ENDLOOP Represents a repetition (loop) structure.
SET / ASSIGN (=) Assigns a value to a variable.

4.3 Example Pseudocode


Problem: Compute the sum of two numbers (same problem as before, in pseudocode form).

START
DECLARE A, B, SUM AS INTEGER
DISPLAY "Enter first number:"
INPUT A
DISPLAY "Enter second number:"
INPUT B
SET SUM = A + B
DISPLAY "The sum is: ", SUM
END

Example with a decision structure — determining the larger of two numbers:

START
DECLARE A, B AS INTEGER
INPUT A, B
IF A > B THEN
DISPLAY A, " is greater"
ELSE
DISPLAY B, " is greater"
ENDIF
END

5. Variables, Data Types, and Constants


5.1 Variables

Page 4
Structured Programming — Week 1

A variable is a named storage location in a computer's memory whose value can change during the execution of a
program. Every variable has three key properties:

• Name (Identifier) — how the variable is referred to in code.


• Data Type — the kind of value it can hold.
• Value — the actual data currently stored.

5.2 Rules for Naming Variables


• Must begin with a letter or underscore, not a digit.
• Can contain letters, digits, and underscores only (no spaces or special characters).
• Cannot be a reserved keyword (e.g., int, if, while).
• Is case-sensitive (age and Age are treated as different variables).
• Should be descriptive and meaningful (e.g., studentAge instead of x).

5.3 Common Data Types


Data Type Description and Example
Integer (int) Whole numbers, positive or negative, no decimal point.
Example: 25, -10
Floating-Point (float / double) Numbers with decimal points. Example: 3.14, -0.005
Character (char) A single letter, digit, or symbol enclosed in quotes.
Example: 'A', '5'
String A sequence of characters (text). Example: "Hello World"
Boolean (bool) Logical values representing true or false only.

5.4 Declaring Variables — Example (C-style syntax)


int age;
float price = 19.99;
char grade = 'A';
string studentName = "Juan Dela Cruz";
bool isEnrolled = true;

5.5 Constants
A constant is similar to a variable, except that its value is fixed and cannot be changed once it has been assigned.
Constants are used for values that must remain the same throughout program execution, such as mathematical constants
or fixed configuration values.

const float PI = 3.14159;


const int MAX_STUDENTS = 40;

Using named constants instead of directly writing fixed numbers throughout a program (sometimes called "magic
numbers") makes code easier to read, update, and maintain.

5.6 Variables vs. Constants — Quick Comparison


Aspect Variable vs Constant
Value Variable: can change | Constant: fixed, cannot change
Keyword (typical) Variable: declared with data type only | Constant: often
uses const keyword
Typical Use Variable: storing user input, running totals | Constant: PI,
tax rate, max limits

Page 5
Structured Programming — Week 1

6. Summary
• Programming is the process of writing instructions for a computer to solve a problem.
• An algorithm is a step-by-step, unambiguous plan for solving a problem.
• A flowchart visually represents an algorithm using standard symbols.
• Pseudocode expresses algorithm logic in structured, English-like statements.
• A variable stores data that can change; a constant stores data that stays fixed.
• Data types (integer, float, character, string, boolean) define what kind of value a variable can hold.

Page 6

You might also like