1 Chapter 8 Designing Small Programs. 2 A ‘Procedure’ v A set of instructions which describe the steps to be followed in order to carry out an activity.

Slides:



Advertisements
Similar presentations
PROBLEM SOLVING TECHNIQUES
Advertisements

COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
PSEUDOCODE & FLOW CHART
Understanding the Three Basic Structures
Chapter 1 - An Introduction to Computers and Problem Solving
An Object-Oriented Approach to Programming Logic and Design
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Programming Logic and Design Fourth Edition, Introductory
ITEC113 Algorithms and Programming Techniques
Steps in Program Development
Chapter 2: Algorithm Discovery and Design
Program Design and Development
Lecture Notes 1/21/04 Program Design & Intro to Algorithms.
Chapter 1 Program Design
Problem Solving Chapter 2. What is an algorithm? n A solution to a problem that is: –Precise –Effective –Terminating.
Chapter 2: Algorithm Discovery and Design
Chapter 3 Planning Your Solution
ALGORITHMS AND FLOWCHARTS
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
The University of Texas – Pan American
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Simple Program Design Third Edition A Step-by-Step Approach
Invitation to Computer Science, Java Version, Second Edition.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.
Flowcharts. Problem Solving Computer programs are written to solve problems or perform tasks Programmers translate the solutions or tasks into a language.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
ITEC113 Algorithms and Programming Techniques
Cosc175 - Define Problem/Design Solution/Pseudocode/Trace 1 DEFINE THE PROBLEM.
Program Design BUILDING A HOUSE. Steps to Designing a Program 1. Define the Output 2. Develop the logic to get that output 3. Write the program.
Flowcharting & Algorithms. Quick. Close your Eyes and Listen You are still sitting in the classroom. However, you have been called to the counselor’s.
Chapter 7 Problem Solving with Loops
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Algorithms and Pseudocode
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Lecture 3: Developing Procedural Thinking (How to think like a programmer) B Burlingame 16 Feb 2016.
Lecture Notes 1/20/05 Pseudocode.  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
PROBLEM SOLVING. What is a Problem? A problem is a situation that needs to be resolved.
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.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Algorithms and Flowcharts
ALGORITHMS AND FLOWCHARTS
Understand Problem Solving Tools to Design Programming Solutions
GC101 Introduction to computers and programs
INTRODUCTION TO PROBLEM SOLVING
Flowcharts and Pseudocode
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Programming Fundamentals
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Programming We have seen various examples of programming languages
Data and Flowcharts Session
Data and Flowcharts Session
Introduction to Programming
Data and Flowcharts Session
Basic Concepts of Algorithm
Presentation transcript:

1 Chapter 8 Designing Small Programs

2 A ‘Procedure’ v A set of instructions which describe the steps to be followed in order to carry out an activity. v This can be for any activity: –eg recipe, assembly instructions etc v If it is written in a computer language it is called a program.

3 To solve a problem by writing a computer program! v Make sure you understand the problem! –be clear in your mind what you are trying to achieve. v Plan the solution! –work out how the task should be done on the computer. v Implement the solution! –write the computer program. v Test the solution! –make sure the program does what it is supposed to do.

4 Planning the Solution v The solution must be prepared before any programming starts. –on paper –using computerised tools –in your head v Divide problem into separate tasks if necessary. –called ‘modules’ or ‘components’ v These tasks may also be divided. v Tasks must be precisely described. –the ‘ procedure ’ must be described

5 Testing the Program v Unit testing –testing modules separately v Integration testing –do the modules work together? v System testing –testing on the computer it will be used on. v User acceptance testing –are they happy with the program?

6 Describing Procedures Precisely v Flowcharts –Diagrams that include words which describe the individual tasks to be carried out and the decisions to be made in regard to carrying out tasks. v Pseudocode –Words that describe the individual tasks and special ‘keywords’ that describe the decisions to be made in regard to carrying out these tasks.

7 Flowcharts v Flowchart describing the procedure involved in preparing a set of envelopes for posting. Write address on envelope. Is letter urgent? Begin Stick first class stamp on envelope. Stick 2nd class stamp on envelope Fold letter Lick gum Seal envelope Any more letters? End Yes No Yes No

8 Flowcharts v Rectangle represents actions. –can only have one entry point. –can only have one exit point. v Diamond represents a decision. –phrased like a question. –can only have one entry point. –must have one exit point for each possible answer. v Arrows show which action is executed after the previous one. Open door Is door open? YesNo

9 Flowchart Exercises v Design flowcharts for the following tasks! –Leaving the classroom. u imagine you are writing instructions for a robot! –Knocking a set of nails into a block of wood. u see French 8.20 u You don’t know how long each nail will take. –Making a sandwidge (choice of ham or cheese) u look at answer in Appendix II –Making sandwidges from a loaf. u Appendix II –Keep to the Rules!

10 Top Down Programming with Stepwise Refinement v Designing a computer program by specifying as little of the details of how the job will be done at the early stages, but gradually defining tasks in more detail at later stages. –Leave details as long as possible! –Divide a job into it’s major components. –Take each component and specify the major tasks involved. –Break each task down into further tasks. –This ‘refinement’ can be done as often as required. v Top-Down Design is used in all areas of design!

11 Procedure for leaving room Start Walk to door Open door Move through door End v Top down design/stepwise refinement Place hand on door handle Turn handle Swing door open Are we inside or outside the room? Push door Pull door OutsideInside Details of ‘Open door’ Details of ‘swing door open’ Unlock door

12 Data v Identify Data Items –data items are given names (identifiers) –classified as either: u constant –value does not change during the operation of the program. u variable –value may change during operation of program. –data type u numeric (real, fixed, floating, integer) u text (alphanumeric) u other (date, etc)

13 Data v Constant –a piece of data that does not change v Variable –a piece of data that may change –in BASIC or JavaScript programs variables may be used to store constants in which case it is up to the programmer to make sure it does not change during the operation of the program. v Identifier –the name by which the piece of data is known ie. what the variable or constant is called. v Literal –a piece of text that is fixed in a program. –not necessarily given a name. –usually has ““ around it to differentiate it from an identifier (variable name) eg cost “cost”

14 Structured Programming v Modularise your program. –use top-down design methods. –write the program as separate units (subroutines) v Use standard pre-built modules if available. –don’t ‘re-invent the wheel’ –eg ‘Windows’ programming libraries. v Use the 3 basic programming ‘control structures’. v Use Pseudocode (not flowcharts)

15 The Three Programming Control Structures. v All programs can be described by combining the following 3 control structures: Simple Sequence Simple Selection (IF-THEN-ELSE) Simple Repitition (Loop)

16 Pseudocode v Words that describe the individual tasks and special ‘keywords’ that describe the decisions to be made in regard to carrying out these tasks. v Keywords for the 3 basic control structures. v Forces the programmer to stick to these structures. v Looks like a programming language but is NOT. It is a strict form of english.

17 Simple Sequence BEGIN Walk to door Open door Move through door END Start Walk to door Open door Move through door End Note the ‘indentation’

18 Simple Selection IF inside room THEN Pull door ELSE Push door ENDIF Are we inside or outside the room? Push door Pull door OutsideInside Note the ‘indentation’

19 Simple Repitition WHILE nail is sticking out hit nail ENDWHILE Hit nail Is nail sticking out? yes no Note the ‘indentation’

20 Hints for writing pseudocode(1) v Identify the appropriate structure for the task to being described. –sequence, selection or repitition v Try these: –Adding up a large set of numbers. –putting ham or cheese onto a slice of bread. –printing out ‘pass’ or ‘fail’ for a student. –addressing and stamping an envelope. – printing out results for a class of students.

21 Hints for writing pseudocode(2) v Write down all the keywords for that structure and fill in the gaps. v The gaps can be filled with ordinary english statements. v The statements can represent complicated procedures which can be described in detail later. BEGIN END IF THEN ELSE ENDIF WHILE ENDWHILE

22 Pseudocode Exercises v Design pseudocode for the following tasks! –Leaving the classroom. –Knocking a set of nails into a block of wood. –Making a sandwidge (choice of ham or cheese) –Making sandwidges from a loaf. –Adding up a set of numbers. –Calculating the average of a set of numbers. –Finding the largest of a set of numbers. –Finding the middle on of 3 numbers. –Printing out results for a class of students. u <40 is a fail u <60 is a pass u <70 is a merit u >=70 is a distinction –Keep to the Rules!