DCT 1123 Problem Solving & Algorithms

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Fundamentals of Algorithms MCS - 2 Lecture # 4
Program Design Tool. 6 Basic Computer Operations Receive information Put out information Perform arithmetic Assign a value to variable (memory location)
ITEC113 Algorithms and Programming Techniques
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
TEL 104 / MKK Fundamental Programming: Lecture 3
Steps in Program Development
Program Design and Development
Pseudocode.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Pseudocode.
Chapter 3 Planning Your Solution
The Program Design Phases
ALGORITHMS AND FLOWCHARTS
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Sw development1 Software Development 1.Define the problem (Analysis) 2.Plan the solution 3.Code 4.Test and debug 5.Maintain and Document.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Simple Program Design Third Edition A Step-by-Step Approach
CSC141 Introduction to Computer Programming
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Input, Output, and Processing
Selection Control Structures Simple Program Design Third Edition A Step-by-Step Approach 4.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Developing an Algorithm
Selection Control Structure. Topics Review sequence control structure Structure theorem Selection control structure If statement Relational operators.
Chapter 2 Problem Solving On A Computer 2.1 Problem Solving Steps Solving a problem on a computer requires steps similar to those followed when solving.
Flowcharts.
Introduction to Programming with RAPTOR
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Visual Basic Programming
ITEC113 Algorithms and Programming Techniques
Cosc175 - Define Problem/Design Solution/Pseudocode/Trace 1 DEFINE THE PROBLEM.
1 Program Planning and Design Important stages before actual program is written.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
FLOWCHARTING AND ALGORITHMS
LO: We’re learning to outline a program using Pseudo Code.
Lecture Notes 1/20/05 Pseudocode.  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Pseudocode. Algorithm A procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
 Problem Analysis  Coding  Debugging  Testing.
Flow Charts Basic Flow Chart Symbols Few sample flowcharts Rules
1-1 Logic and Syntax A computer program is a solution to a problem.
Algorithm & Programming
PROGRAM CONTROL STRUCTURE
The Selection Structure
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
CHAPTER 2 & 3: Pseudocode and Developing and Algorithm
ALGORITHMS AND FLOWCHARTS
Chapter 4: Algorithm Design
Program Design Introduction to Computer Programming By:
Pseudocode.
Understanding the Three Basic Structures
Lecture Notes 8/24/04 (part 2)
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithms and Programming
Chapter 4: Algorithm Design
Flowcharting & Algorithms
ICT Programming Lesson 3:
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
Flowcharts and Pseudo Code
Introduction to Programming
Introduction to Pseudocode
Presentation transcript:

DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart

Contents How to write a pseudocode Meaningful names The structure theorem Flowchart

SIX basic computer operation A computer can receive information A computer can put out information A computer can perform arithmetic A computer can assign a value to a variable or memory location A computer can compare two variable and select one of two alternative actions A computer can repeat a group of actions

Receive Information When computer is required to receive information or input from a particular source, whether it be a terminal, a disk or any other device ‘Read’ and ‘Get’ are used in the pseudocode Read – receive input from a record/file Get – receive input from keyboard

Receive Information For example: Read student name Get system date Read number1, number2 Get tax code

Put Out Information When a computer is required to supply information or output to a device, the verbs Print, Write, Output or Display are used Print – output is sent to the printer Write – output is to be written to a file Put, Output and Display – output is to be written to the screen

Put Out Information For example: Print ‘Program Completed’ Write customer record to master file Put out name, address and postcode Output total_tax Display ‘End of Data’

Perform Arithmetic Most programs require the computer to perform some sort of mathematical calculation and apply a formula The following symbols can be written in pseudocode: + for add - for substract * for multiply / for divide () for parantheses The verbs ‘Compute’ and ‘calculate’ also used in the pseudocode

Perform Arithmetic For example: Divide total marks by student_count Sales_tax = cost_price * 0.10 Compute C = (F – 32) * 5 / 9

Assign a value to a variable / memory location There are 3 instances in which you may write a pseudocode to assign a value to a variable / memory location: To give data an initial value in pseudocode, the verbs Initialize or Set are used To assign a value as a result of some processing, the symbols ‘=‘ or ‘’ are written To keep a variable for later use, the verbs Save or Store are used

Assign a value to a variable / memory location For example: Initialize total_price to zero Set student_count to 0 Total_price = cost_price + sales_tax Total_price  cost_price + sales_tax Store customer_no in last_customer_no

Compare two variables & select one or two alternative action To represent this operation in pseudocode, special keywords are used: IF, THEN and ELSE The comparison of data is established in the IF clause The choice of alternatives is determined by the THEN or ELSE

Compare two variables & select one or two alternative action For example: IF attendance_status is part_time THEN Add 1to part_time_count ELSE Add 1 to full_time_count ENDIF

Repeat a group of action When there is a sequence of processing steps that need to be repeated, two special keywords, DOWHILE and ENDDO are used in pseudocode The repetition condition is established in the DOWHILE clause and the actions to be repeated are listed beneath it

Repeat a group of action For example: DOWHILE student_total < 50 Read student record Print student name, address to report Add 1 to student_total ENDDO

Meaningful Names A programmer must introduce some unique names, which will be used to represent the variables or objects in the problem A name given to a variable is simply a method of identifying a particular storage location in the computer A name describes the type of data stored in a particular variable A variable may be one of three simple data types: an integer, a real number or a character

Meaningful Names If more than one word is used in the variable name, the underscores are useful as word separator. For example student_number If underscore cannot be used, then words can be joined together with the use of a capital letter as a word separator. For example studentNumber

Flowchart Flowchart is an alternative method of representing algorithms It is popular because they graphically represent the program logic through series of standard geometric symbols and connecting lines

Flowchart Symbols Terminal Symbol Indicates the starting or stopping point in the logic. Every flowchart should begin and end with a terminal symbol. Input / Output Symbol Represents an input or output process in an algorithm, such as reading input or writing output

Flowchart Symbols Process Symbol Represents any single process in an algorithm, such as assigning a value or performing a calculation Predefined Process Symbol Represents an input or output process in an algorithm, such as reading input or writing output

Flowchart Symbols Decision Symbol Represents a decision in the logic involving the comparison of two values. Alternative paths are followed, depending on whether the decision symbol is true or false Flowlines Connect various symbols in a flowchart, and contain an arrowhead only when the flow control is not from top to bottom or left to right

Flowchart Control Structure There are three basic control structures: Sequence Straightforward execution of one processing step after another Selection Presentation of a condition, and the choice between two actions depending on whether the condition is true or false Repetition Presentation of a set of instructions to be performed repeatedly, as long as condition is true

Flowchart Control Structure Sequence flowchart example: Statement A Input / Output Statement C

Flowchart Control Structure Selection flowchart example Condition p? True False Statement B Statement A

Flowchart Control Structure Repetition Flowchart Example Condition p? False True Statement A

Summary Six basic computer operations were listed – receive information, put out information, perform arithmetic, assign a value o a variable, decide between two alternative actions and repeat a group of actions The algorithm can be represented in the pseudocode or flowchart