CHAPTER 9 PSEUDOCODE AND FLOWCHARTS LEARNING OBJECTIVE: STUDENT WILL LEARN HOW TO CREATE PSEUDOCODE. • COMPUTER SYSTEM Computer System : A COMPUTER SYSTEM is made up of software, data, hardware, communications and people; each computer system can be divided up into a set of sub-systems. Ex: Alarm app for Smart Phone etc….. TASK 1 IDENTIFY AT LEAST FIVE COMPUTER SYSTEMS YOU FREQUENTLY USE IN YOUR DAILY LIFE. SEE IF YOU CAN DECIDE THE SIZE OF EACH SYSTEM. TOP-DOWN DESIGN • TOP-DOWN DESIGN is the breaking down of a computer system into a set of subsystems, then breaking each sub-system down into a set of smaller sub-systems, until each sub-system just performs a single action. • In order to show top-down design in a diagrammatic form, structure diagrams can be used. LIBRARY ROUTINE A LIBRARY ROUTINE is a set of programming instructions for a given task that is already available for use. It is pre-tested and usually performs a task that is frequently required. Ex: import <math.h>, import <String.h> SUB-ROUTINE(PROGRAM) • A SUB-ROUTINE is a set of programming instructions for a given task that forms a subsystem, not the whole system. Sub-routines written in high-level programming languages are called ‘procedures’ and ‘functions’ depending on how they are used. ALGORITHM: AN ALGORITHM SETS OUT THE STEPS TO COMPLETE A GIVEN TASK. • ALGORITHM CAN BE WRITTEN AS PSEUDOCODE OR FLOWCHART. • PSEUDOCODE: PSEUDOCODE is a simple method of showing an algorithm, using English-like words and mathematical operators that are set out to look like a program. Algorithm Step1: enter the numbers Step2:use mathematical operator+ for adding numbers Step3:print the calculation Pseudocode: DECLARE Num1,Num2,Sum As INTEGERS INPUT “Enter num1”, Num1 INPUT “Enter num2”, Num2 Sum= Num1+Num2 PRINT Sum PSEUDOCODE • It is used to dry run to check whether the programs run properly or not. MATH OPERATORS 3^4=3*3*3*3 RELATIONAL OPERATORS • Relational operations The following symbols are used for relational operators (also known as comparison operators): 1. > Greater than 2. < Less than 3. >= Greater than or equal to 4. <= Less than or equal to 5. = Equal to 6. <> Not equal to LOGICAL OPERATOR • AND both • OR either • NOT not DATA TYPES • Integer: a whole number e.g. 4, -9 • Real: a number capable of containing a fractional part • e.g. 5.6, 3.98, 1.001,0.8 • Char: a single character • e.g. ‘h’ , ‘C’ • String: A sequence of zero or more characters • e.g. “This is string” • Boolean: The logical values TRUE and FALSE • Date: entering Date COST PRICECOST 30 ASSIGNMENT 30 • Values are assigned to a variable using the ‘ ← ‘operator. The variable on the left of the ← is assigned the value of the expression on the right. • Cost ← 30 • Price ← Cost -Cost has the value 30 • Tax ← Price * 0.12 • SellingPrice ← Price + Tax Cost 30 Price -Price = 30 -Price = 30 -SellingPrice = 23.6 cost 30 TASK TO BE DONE IN CLASS • Task1: Write the pseudocode to find the selling price of car if the cost price is 110000 AED and 25% TAX. • COSTPRICE110000 • TAX(25/100)*COSTPRICE • SELLINGPRICE COSTPRICE+TAX • PRINT SELLINGPRICE • Task 2: Write the python program for the same. INPUT AND OUTPUT STATEMENTS IN PSEUDOCODE Plenary FLOW CHART ALARM APP FLOW CHART A flowchart can also be defined as a diagrammatic representation of an algorithm, a step-by-step approach for solving a task. COMPARING TWO NUMBERS • TASK1 : Draw the Flow Chart to Compare two Numbers DRAW THE FLOWCHART AND WRITE PSEUDOCODE • If the temperature of the DAY is greater than 23 degrees than display HOT started else Display its COLD.