Lecture 2: Developing Procedural Thinking (How to think like a programmer) BJ Furman 06FEB2012.

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

CS107: Introduction to Computer Science Lecture 2 Jan 29th.
1 Program Design Language (PDL) Slides by: Noppadon Kamolvilassatian Source: Code Complete by Steve McConnell, Chapter 4.
PSEUDOCODE & FLOW CHART
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 2 - Problem Solving
INTRODUCTION TO PROGRAMMING
ITEC113 Algorithms and Programming Techniques
Detailed Design Kenneth M. Anderson Lecture 21
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Program Flow Charting How to tackle the beginning stage a program design.
Chapter 2: Input, Processing, and Output
Lecture Notes 1/21/04 Program Design & Intro to Algorithms.
Computer Science 1620 Programming & Problem Solving.
Top-down Program Design Selim Aksoy Bilkent University Department of Computer Engineering
Programming Fundamentals (750113) Ch1. Problem Solving
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
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
The Program Design Phases
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
Programming.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Lecture 5: Developing Procedural Thinking (How to think like a programmer) B Burlingame 30 Sept 2015.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Chapter 1 Program design Objectives To describe the steps in the program development process To introduce the current program design methodology To introduce.
ITEC113 Algorithms and Programming Techniques
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
The Software Development Process
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
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.
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.
How Computers Solve Problems Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step.
Algorithms and Flowcharts
ICS 3UI - Introduction to Computer Science
Algorithms and Problem Solving
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Algorithm Algorithm is a step-by-step procedure or formula or set of instruction for solving a problem Its written in English language or natural language.
Algorithm and Ambiguity
Lecture 2: Introduction to Algorithms
COMS W1004 Introduction to Computer Science and Programming in Java
Unit# 9: Computer Program Development
Problem Solving Techniques
Program Control using Java - Theory
1) C program development 2) Selection structure
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Problem Solving Skill Area 305.1
Algorithm and Ambiguity
Algorithms and Problem Solving
Program Design Language (PDL)
Software Development Process
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
Programming Concepts and Database
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Basic Concepts of Algorithm
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Presentation transcript:

Lecture 2: Developing Procedural Thinking (How to think like a programmer) BJ Furman 06FEB2012

The Plan for Today Program design process Algorithms, decomposition, and step-wise refinement  Example Program design example

Learning Objectives List and describe the steps in designing a computational solution (computer program) to a problem Articulate what is meant by an algorithm Apply the steps to a particular problem

Program Design Process Define the problem List the inputs and outputs Design the solution algorithm Check the algorithm by hand Write the program code Test the program code

Program Design Process – step 1 Define the problem List the inputs and outputs Design the solution algorithm Check the algorithm by hand Write the program code Test the program code State the problem in a clear and concise manner Example Write a program to find the distance between two points P1P2 or P1P2 P1 P2 or Better Write a program to find the straight line distance between two points Is the problem statement okay?

Program Design Process – step 2 Define the problem List the inputs and outputs Design the solution algorithm Check the algorithm by hand Write the program code Test the program code Write a program to find the straight line distance between two points Inputs Outputs

Program Design Process – step 3 Define the problem List the inputs and outputs Design the solution algorithm Check the algorithm by hand Write the program code Test the program code DecomposeRefine Write a program to find the straight line distance between two points

Definition of an Algorithm An algorithm is a well-ordered collection of unambiguous and effectively computable operations, that when executed, produces a result and halts in a finite amount of time.  Well-ordered means the steps are in a clear order  Unambiguous means the operations described are understood by a computing agent without further simplification A computing agent is the thing that is supposed to carry out the algorithm  Effectively computable means the computing agent can actually carry out the operation This definition comes from, An Invitation to Computer Science (Gersting/Schneider) via (visited 19JUN2009)

Program Design Process – step 3,cont. Define the problem List the inputs and outputs Design the solution algorithm Check the algorithm by hand Write the program code Test the program code Two approaches are often used to help think through the steps to be carried out by the program code: 1. Pseudocode 2. Flow Charts We’ll use the pseudocode method first.

Pseudocode Pseudocode (also called Program Design Language, PDL) is English-like statements that precisely describe specific operations 1 :  Action statements  Focuses on the logic of the program  Avoids language-specific elements  Written at a level so that code can be generated almost automatically. Will likely need to refine in more and more detail 1 This definition comes from, McConnel, S. (1993). Code Complete, Microsoft Press, Redmond, WA, p. 54.

Pseudocode – First Pass 1. Prompt user to enter points 2. Get points from user 3. Calculate the straight line distance 4. Display distance to the monitor Write a program to find the straight line distance between two points Comments 1. High level – just the major steps 2. Focus on the logic

Pseudocode - Refinement 1. Start 2. Declare variables: X1, Y1, X2, Y2, D 3. Prompt user to enter X1 and Y1 4. Display X1 and Y1 to the monitor 5. Prompt user to enter X2 and Y2 6. Display X2 and Y2 to the monitor 7. Calculate the straight line distance, D 8. Display D to the monitor 9. Stop Write a program to find the straight line distance between two points Comments 1. Refine high level ideas down to computable actions What could still be refined?

Calculating the Distance, D Define the problem List the inputs and outputs Design the solution algorithm Check the algorithm by hand Write the program code Test the program code Write a program to find the straight line distance between two points P1 P2 X1 X2 Y1 Y2 D How do you find D? P1 P2 D X Y

Program Design Process – step 4 Define the problem List the inputs and outputs Design the solution algorithm Check the algorithm by hand Write the program code Test the program code Write a program to find the straight line distance between two points What values of Xi, Yi (where i=1, 2) would be good to test the algorithm with?

Program Design Process – step 5 Define the problem List the inputs and outputs Design the solution algorithm Check the algorithm by hand Write the program code Test the program code If you have refined your algorithm sufficiently, writing the code should proceed straightforwardly from it. If not, continue refining the algorithm until you can write the code directly from it. Your pseudocode can be turned into the comments for your code.

Program Code Note the structure of the program

Program Design Process – step 6 Define the problem List the inputs and outputs Design the solution algorithm Check the algorithm by hand Write the program code Test the program code Test your code with cases that you know the answer to. Try the ‘boundary’ cases to make sure your code works for them too.

Algorithm Practice Find the midpoint between two points

Algorithm – Items to Consider Is the problem statement clear and concise?  Could be better: “Find the midpoint on a line between two points What are the inputs?  X and Y coordinates of the two points: x1, y1 and x2, y2 What are the outputs?  The midpoint between the points: Xm, Ym

Algorithm – Items to Consider, cont. Solution algorithm  Point must be on the line  Midpoint means ‘halfway’ between the points Halfway in x and halfway in y  This should suggest a solution strategy P1 P2 X1 X2 Y1 Y2 M

Review

References