305171 Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.

Slides:



Advertisements
Similar presentations
Algorithms An algorithm is a finite sequence of instructions, logic, an explicit step-by-step procedure for solving a problem. Specific algorithms sometimes.
Advertisements

Chapter 2: Problem Solving
Repetition Control Structures School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 9, Friday 3/07/2003)
Introduction to Flowcharting
Introduction to Flowcharting
Chapter 2: Problem Solving
Introduction to Flowcharting
An Object-Oriented Approach to Programming Logic and Design
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Fundamentals of Algorithms MCS - 2 Lecture # 4
1 Pseudocode For Program Design. 22 Rules for Pseudocode Write only one statement per line Capitalise initial keyword Indent to show hierarchy and structures.
ITEC113 Algorithms and Programming Techniques
What is Pseudocode? Pseudocode is "halfway" between english and a programming language. It is a description of a process in detail, though not necessarily.
Chapter 2: Input, Processing, and Output
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
The Program Design Phases
(C)opyright 2003 Scott/Jones Publishers Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Scott/Jones Publishers.
PRE-PROGRAMMING PHASE
ALGORITHMS AND FLOWCHARTS
CSC103: Introduction to Computer and Programming
Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 5 Structured Program.
CSEB114: PRINCIPLE OF PROGRAMMING Chapter 2: Problem Solving.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
CIS Computer Programming Logic
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
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
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Software Life Cycle What Requirements Gathering, Problem definition
Visual Basic Programming
ALGORITHM List of instructions for carrying out some process step by step. A sequence of instructions which has a clear meaning and can performed with.
1 Program Planning and Design Important stages before actual program is written.
Pseudocode An Introduction. Flowcharts were the first design tool to be widely used, but unfortunately they do not reflect some of the concepts of structured.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
 In this chapter you will learn about:  Introduction to Problem Solving  Software development method (SDM)  Specification of needs  Problem analysis.
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.
1 Introduction to Flowcharting Computer Science Principles ASFA.
Pseudocode An Introduction. Flowcharts were the first design tool to be widely used, but unfortunately they do not reflect some of the concepts of structured.
Algorithms and Pseudocode
Fundamentals of Algorithms MCS - 2 Lecture # 3. Representation of Algorithms.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
CSE 110: Programming Language I Matin Saad Abdullah UB 404.
Decision Tables and Pseudocode
Pseudocode (pronounced SOO-doh-kohd)  is a detailed yet readable description of what a computer program or algorithm must do, expressed in a formally-styled.
ALGORITHMS AND FLOWCHARTS
Pseudocode An Introduction
Introduction to Flowcharting
Chapter 2: Input, Processing, and Output
Introduction to Flowcharting
Flowcharting: Decision Structure
Introduction To Flowcharting
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.
Introduction to Flowcharting
Introduction to Computer Programming
Flow Charts What are they good for?.
Computer Programming.
ALGORITHMS AND FLOWCHARTS
Pseudocode An Introduction
How to develop a program?
ALGORITHMS AND FLOWCHARTS
Faculty of Computer Science & Information System
ME 142 Engineering Computation I
Chapter 2: Input, Processing, and Output
Introduction to Flowcharting
Pseudocode For Program Design.
Introduction to Programming
Presentation transcript:

Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University

 Algorithm is a process or a set of rules to be followed in calculations or other problem-solving operations.  The instructions should be simple and clear enough so that each step can be done without confusion. 2

 This is an example of an algorithm for sorting cards with colors on them into piles of the same color: – Pick up all of the cards. – Pick a card from your hand and look at the color of the card. – If there is already a pile of cards of that color, put this card on that pile. – If there is no pile of cards of that color, make a new pile of just this card color. – If there is still a card in your hand, go back to the second step. – If there is not still a card in your hand, then the cards are sorted, you are done. 3

4

5

 A program is a very specific set of steps and rules.  A program is an implementation of an algorithm in a particular language to run on a computer (usually a particular kind of computer) – Algorithm = what we want to do – Program = what we actually did  The process of creating a program is called programming.  Programming is breaking a task down into small steps and rules. 6

 Put these words in alphabetical order: apple, zebra, abacus  Count the number of words in these sentences: – “Programming really can be fun.” – “John,do it again.” – “Some people just love to type really short lines, instead of using the full width of the page.” 7

 A flowchart is a diagram that depicts the “flow” of a program. 8 START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END

 Terminals – represented by rounded rectangles – indicate a starting or ending point 9 START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Terminal

 Input/Output Operations – represented by parallelograms – indicate an input or output operation 10 START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Input/Output Operations

 Processes – represented by rectangles – indicates a process such as a mathematical computation or variable assignment 11 START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Process

Variable Contents: Hours: ? Pay Rate: ? Gross Pay: ? 12 START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END

Variable Contents: Hours: ? Pay Rate: ? Gross Pay: ? 13 START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END How many hours did you work?

Variable Contents: Hours: 40 Pay Rate: ? Gross Pay: ? 14 START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END How many hours did you work? 40

Variable Contents: Hours: 40 Pay Rate: ? Gross Pay: ? 15 START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END How many hours did you work? 40 How much do you get paid per hour?

Variable Contents: Hours: 40 Pay Rate: 300 Gross Pay: ? 16 START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END How many hours did you work? 40 How much do you get paid per hour? 300

Variable Contents: Hours: 40 Pay Rate: 300 Gross Pay: START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END How many hours did you work? 40 How much do you get paid per hour? 300

Variable Contents: Hours: 40 Pay Rate: 300 Gross Pay: START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END How many hours did you work? 40 How much do you get paid per hour?

Variable Contents: Hours: 40 Pay Rate: 300 Gross Pay: START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END How many hours did you work? 40 How much do you get paid per hour?

 Sequence  Decision  Repetition  Case 20

 a series of actions are performed in sequence  The pay-calculating example was a sequence flowchart. 21

 One of two possible actions is taken, depending on a condition.  In the flowchart segment below, the question “is x < y?” is asked. If the answer is no, then process A is performed. If the answer is yes, then process B is performed. 22 A X < Y ? B YesNo

 A repetition structure represents part of the program that repeats. This structure is commonly known as a loop.  In the flowchart segment, the question “is x < y?” is asked. If the answer is yes, then Process A is performed. The question “is x < y?” is asked again. Process A is repeated as long as x is less than y. When x is no longer less than y, the repetition stops and the structure is exited. 23 x < y? A YES

 One of several possible actions is taken, depending on the contents of a variable.  The structure below indicates actions to perform depending on the value in years_employed. 24 CASE years_employed Other bonus = 100 bonus = 200 bonus = 400 bonus = 800

 Sometimes a flowchart will not fit on one page length.  A connector (represented by a small circle) allows you to connect two flowchart segments on the same page.  The “A” connector indicates that the second flowchart segment begins where the first segment ends. 25 A A START END

The position of the module symbol indicates the point the module is executed. A separate flowchart can be constructed for the module. 26 START END Read Input. Call calc_pay function. Display results. calc_pay return net = rate * hour pay = net - tax

 Off-page connector – Used to connect remote flowchart portion on different page  Comment – Used to add description  Document – Used to represent a print out  Database – Used to represent a database 27 Put any Comments Here.

 Pseudocode is a compact and informal high- level description of a computer programming algorithm that uses the structural conventions of a programming language, but is intended for human reading rather than machine reading. Pseudocode typically omits details that are not essential for human understanding of the algorithm, such as variable declarations, system-specific code and subroutines. (Wikipedia) 28

 Pseudocode generally does not actually obey the syntax rules of any particular language.  There is no systematic standard form.  Pseudocode may therefore vary widely in style, from a near-exact imitation of a real programming language at one extreme, to a description approaching formatted prose at the other. 29

 Write only one statement per line  Capitalize initial keyword  Indent to show hierarchy  End multiline structures  Keep statements language independent 30

BEGIN Procedure_NetCalc READ name, grossPay, taxes IF taxes > 0 net = grossPay – taxes ELSE net = grossPay ENDIF WRITE name, net END Procedure_NetCalc 31

 Pseudocode IF Y > 3 X = 5 ELSE X = 10 ENDIF 32 X = 5 3 < Y ? X = 10 YesNo

BEGIN count = 0 WHILE count < 10 DO Process ENDWHILE WRITE “The End” END BEGIN Process ADD 1 to count WRITE count END Process 33 count = 0 Start Count < 10 End Write “The End” Process No Yes Add 1 to count Process Count < 10 Return Write count

AdvantagesDisadvantages Flowchart Standardized Visual Hard to modify Structured design elements not implemented Special software required Pseudocode Easily modified Implements structured concepts Done easily on word processor Not visual No accepted standard, varies from company to company 34