








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









Lesson 1: Introduction to Pseudocode
1. Overview of Pseudocode
Pseudocode is a simplified, half-English, half-code outline of a computer program that helps programmers develop algorithms before implementing them in actual programming languages. It serves as an intermediary step between the problem statement and the final code, providing a clear structure for the logic of a program without worrying about syntax.
2. Purpose of Pseudocode - Simplifies the coding process : Helps programmers understand the flow and logic before writing actual code. - Facilitates communication : Acts as a universal language that anyone with basic programming knowledge can understand. - Problem-solving tool : Breaks complex problems into manageable steps, making it easier to develop solutions. 3. Key Characteristics of Pseudocode - Plain Language : Uses simple English to describe steps. - Structured Logic : Follows logical statements such as "IF," "ELSE," "FOR," "WHILE," etc. - Readable and Understandable : Should be easy to read for non-programmers. 4. Basic Pseudocode Structure - Start/Begin : Indicates the starting point of the pseudocode. - Input/Output : Used for gathering data and displaying results. - Process : Describes actions or calculations. - Decision-making : Incorporates conditional statements ("IF," "ELSE," "ENDIF"). - Looping : Includes iteration statements ("FOR," "WHILE," "ENDWHILE"). 5. Pseudocode Syntax Conventions - Use indentation for clarity and organization. - Capitalize keywords like START, IF, ELSE, WHILE, FOR, ENDIF. - Describe actions in simple, clear sentences. 6. Basic Example: Finding the Sum of Two Numbers
Problem Statement : Write pseudocode to find the sum of two numbers entered by the user.
Pseudocode:
START DISPLAY "Enter the first number" READ number DISPLAY "Enter the second number" READ number sum = number1 + number DISPLAY "The sum is ", sum END
Explanation :
Problem Statement : Write pseudocode for withdrawing money from an ATM.
Pseudocode:
START DISPLAY "Insert your ATM card" READ cardInserted IF cardInserted is TRUE THEN DISPLAY "Enter your PIN" READ PIN IF PIN is correct THEN DISPLAY "Enter amount to withdraw" READ amount IF amount <= accountBalance THEN Dispense cash DISPLAY "Collect your cash" ELSE DISPLAY "Insufficient funds" ENDIF ELSE DISPLAY "Invalid PIN" ENDIF ELSE DISPLAY "Please insert a valid card" ENDIF DISPLAY "Thank you for using our ATM service" END
9. Exercise Example
Step 4: Use Simple Language Write in clear, plain English, avoiding unnecessary complexity.
Step 5: Incorporate Control Structures Use "IF," "ELSE," "WHILE," "FOR," and other control statements to handle decision-making and repetition.
3. Application/Examples
Example 1: Calculating the Average of Three Numbers
Problem Statement : Write pseudocode to calculate the average of three numbers entered by the user.
Pseudocode:
START DISPLAY "Enter the first number" READ number DISPLAY "Enter the second number" READ number DISPLAY "Enter the third number" READ number sum = number1 + number2 + number average = sum / 3 DISPLAY "The average is ", average END
Explanation :
Example 2: Determining the Largest of Three Numbers
Problem Statement : Write pseudocode to find the largest of three numbers entered by the user.
Pseudocode:
START DISPLAY "Enter the first number" READ number DISPLAY "Enter the second number" READ number DISPLAY "Enter the third number" READ number IF number1 > number2 AND number1 > number3 THEN DISPLAY "The largest number is ", number ELSE IF number2 > number1 AND number2 > number3 THEN DISPLAY "The largest number is ", number ELSE DISPLAY "The largest number is ", number
ENDIF END
Explanation :
Example 3: Calculating the Factorial of a Number
Problem Statement : Write pseudocode to calculate the factorial of a number entered by the user.
Pseudocode:
START DISPLAY "Enter a positive integer" READ number factorial = 1 FOR i = 1 TO number factorial = factorial * i ENDFOR DISPLAY "The factorial of the number is ", factorial END
Explanation :
Example 4: Checking for Prime Numbers
Problem Statement : Write pseudocode to check whether a given number is prime.
Pseudocode:
START DISPLAY "Enter a number" READ number IF number <= 1 THEN DISPLAY "The number is not prime" ELSE isPrime = TRUE FOR i = 2 TO number / 2 IF number MOD i = 0 THEN isPrime = FALSE BREAK ENDIF ENDFOR IF isPrime = TRUE THEN DISPLAY "The number is prime" ELSE DISPLAY "The number is not prime"
1. Overview
Flowcharts are visual diagrams that represent the steps or processes involved in solving a problem or executing an algorithm. They use different symbols to depict the flow of a program, making it easier to understand the logic, sequence, and decision-making involved in a task.
2. Purpose of Flowcharts - Visual Clarity : Helps to visualize the sequence of actions in a process. - Problem Solving : Simplifies complex problems into manageable steps. - Communication : Acts as a universal tool to communicate ideas and logic between programmers, designers, and stakeholders. - Debugging : Identifies potential issues in the logic before implementation. 3. Basic Components of a Flowchart - Flowchart Symbols : Different shapes represent different types of actions or decisions. - Arrows : Indicate the direction of the flow from one step to the next. 4. Common Flowchart Symbols
Symbol Name Description Example Terminal Represents the start or end of the process. Start/End
Process Shows an instruction or action to be performed. Calculate sum
Input/Output Indicates data input or output. Enter number
Decision Represents a decision-making step with two possible outcomes (e.g., Yes/No).
Is x > 0?
Flowline Shows the flow direction from one step to another. →
Connector Indicates a connection point when flowcharts are large and split across multiple pages.
Continue to Page 2
5. Basic Flowchart Structure
A flowchart typically starts with a Start symbol and ends with an End symbol. The steps between these symbols include actions (processes), inputs/outputs, and decisions.
6. Applications of Flowcharts
Example 1: Calculating the Sum of Two Numbers
Problem Statement : Create a flowchart to calculate the sum of two numbers entered by the user.
Flowchart Explanation :
Flowchart:
Example 2: Finding the Largest of Three Numbers
Problem Statement : Create a flowchart to find the largest of three numbers.
Flowchart Explanation :
Flowchart:
Example 3: Checking if a Number is Even or Odd
Problem Statement : Create a flowchart to determine if a number entered by the user is even or odd.
Flowchart Explanation :
Flowchart:
Example 4: Simple ATM Withdrawal Process
2. The Most Common Flowchart Symbols
Symbol Name Description Example Usage Terminal (Start/End)
Indicates the start or end of a flowchart.
Start/End a process
Process Represents an action or step in the process.
Calculating a sum
Input/Output Used for inputting data or displaying output.
Enter a number, Display results Decision Shows a point where a decision is made, typically with Yes/No or True/False paths.
Is the number > 10?
Flowline Arrows that show the direction of flow from one symbol to another.
Indicates the process flow Preparation Represents a step that prepares for the next action.
Initialize variables
Connector Connects different parts of a flowchart, often used for large or complex charts.
Continuation from one page to another
3. Detailed Explanation of Key Symbols - Terminal (Start/End) : This oval shape marks the beginning or end of the process. Every flowchart must have a "Start" and an "End" symbol.
Example : Start of a program to calculate the sum of two numbers.
Example : "Add Number1 and Number2."
Example : "Read Number1" or "Display Total."
Example : "Is Number greater than 10?"
4. Conventions and Best Practices for Creating Flowcharts - Top to Bottom, Left to Right : Always arrange the flow of your chart from top to bottom or left to right. - Avoid Crossing Flowlines : Try to arrange the flowchart in a way that lines do not cross each other. - Consistent Use of Symbols : Always use the correct symbol for each action to maintain clarity. - Keep It Simple : Avoid overly complex flowcharts. If a process is too complicated, break it into multiple smaller flowcharts. - Use Labels : Clearly label each decision path (e.g., "Yes" or "No") to enhance understanding. 5. Examples Demonstrating Flowchart Symbols and Conventions
Example 1: Flowchart for Checking If a Number Is Positive, Negative, or Zero
Problem Statement : Create a flowchart to check whether a number entered by the user is positive, negative, or zero.
Flowchart:
Example 2: Flowchart for a Simple Login System
Problem Statement : Create a flowchart for a simple login system where a user enters a username and password.
Flowchart Explanation :
Flowchart:
6. Practical Applications of Flowcharts Using Symbols and Conventions - Banking Systems : Flowcharts can be used to design the process of withdrawing money from an ATM, showcasing the various decision points such as correct PIN, sufficient funds, etc. - Manufacturing Processes : Representing the steps involved in product assembly, quality checks, and packaging. - Customer Support : Designing the flow of handling a customer's query, from receiving the query to resolving it or escalating to a higher authority. 7. Practice Problems
Flowchart :
Explanation : The flowchart starts by getting the value of N, initializes the sum and counter, and then iteratively adds the counter to the sum until the counter exceeds N. Finally, it displays the sum.
Example 2: Algorithm for Finding the Maximum of Three Numbers
Problem Statement : Create a flowchart to find the maximum of three numbers entered by the user.
Algorithm :
Flowchart :
Explanation : The flowchart takes three inputs and uses decision blocks to identify the largest number among A, B, and C.
Example 3: Algorithm for a Simple Password Verification
Problem Statement : Create a flowchart for a simple password verification system that allows a user three attempts to enter the correct password.
Algorithm :
Flowchart :
Explanation : The flowchart allows the user up to three attempts to enter the correct password, displaying "Access Granted" or "Access Denied" accordingly.
Example 4: Algorithm for Calculating the Area of a Circle
Problem Statement : Create a flowchart to calculate the area of a circle given its radius.
Algorithm :
Flowchart :
Explanation : The flowchart takes the radius as input, calculates the area using the formula, and displays the result.
5. Tips for Creating Flowcharts for Algorithms - Start with Simple Problems : Practice with basic algorithms before moving to complex ones. - Use Clear and Consistent Symbols : Ensure every step is represented with the correct symbol. - Review the Flow : Check that the flowchart accurately represents the logical flow of the algorithm. - Test the Flowchart : Use sample data to test whether the flowchart produces the correct results. 6. Practice Problems - Create a flowchart for a program that calculates the average of five numbers entered by the user. - Develop a flowchart for an algorithm that determines whether a number entered by the user is prime. - Design a flowchart for an ATM transaction where the user can check their balance, withdraw money, or exit.
By the end of this lesson, students should be able to create flowcharts for simple algorithms, gaining confidence in translating logical steps into visual representations using standard flowchart symbols.