Introduction to Functional Decomposition Intro to Computer Science CS 1510 Dr. Sarah Diesburg.

Slides:



Advertisements
Similar presentations
Problem Solving and Algorithm Design
Advertisements

1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Slides modified by Erin Chambers Problem Solving and Algorithm Design.
Algorithms Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Problem Solving and Algorithm Design
Chapter 6 Problem Solving and Algorithm Design. 6-2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 2 - Problem Solving
Algorithms and Problem Solving-1 Algorithms and Problem Solving Mainly based on Chapter 6: “Problem Solving and Algorithm Design” from the Book: “Computer.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Using Algorithms Copyright © 2008 by Helene G. Kershner.
Algorithms and Problem Solving
CS 206 Introduction to Computer Science II 10 / 13 / 2008 Instructor: Michael Eckmann.
Chapter 6 Problem Solving and Algorithm Design Nell Dale John Lewis.
Chapter 9 High-Level Programming Languages: C++. Chapter Goals Describe the expectations of high level languages Distinguish between functional design.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Top-Down Design and Modular Development
Invitation to Computer Science, Java Version, Second Edition.
Problem Solving and Algorithm Design. 2 Problem Solving Problem solving The act of finding a solution to a perplexing, distressing, vexing, or unsettled.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
1 Chapter-01 Programming Methodologies Procedural/Structured Design Objected-Oriented Design.
CS 1308 Computer Literacy and The Internet Software.
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
Algorithms CS139 – Aug 30, Problem Solving Your roommate, who is taking CS139, is in a panic. He is worried that he might lose his financial aid.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Top-Down Design and Modular Development. The process of developing methods for objects is mostly a process of developing algorithms; each method is an.
The Programming Process Define the problem* Make or buy software? Design the program * Code (write) the program Test (debug) the program Document the.
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
2. Program Development Intro Programming in C++ Computer Science Dept Va Tech August 2001 ©2001 Barnette ND & McQuain WD 1 Top-Down Design:A solution method.
1 CS161 Introduction to Computer Science Topic #9.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
CS 100 Introduction to Computing Seminar September 21, 2015.
CSI 1340 Introduction to Computer Science II Chapter 1 Software Engineering Principles.
Algorithms CS280 – 10/20/05. Announcement  Part 1 of project 2 due.  Read chapters 10, 7 for this unit  Tuesday we will also be in the classroom We.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
CS 206 Introduction to Computer Science II 10 / 10 / 2008 Instructor: Michael Eckmann.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
Problem Solving Intro to Computer Science CS1510 Dr. Sarah Diesburg 1.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Low-Level Programming Languages, Pseudocode and Testing Chapter 6.
More on Functions (Part 2)
Topic: Programming Languages and their Evolution + Intro to Scratch
More Functional Decomposition
Using Algorithms Copyright © 2008 by Helene G. Kershner.
And now for something completely different . . .
Introduction to Functional Decomposition
Using Algorithms Copyright © 2008 by Helene G. Kershner.
Intro to Nested Looping
More Functional Decomposition
Intro to Nested Looping
More Functional Decomposition
Open on the student drive
The Programming Process
Programming We have seen various examples of programming languages
More on Functions (Part 2)
More on Functions (Part 2)
Intro to Nested Looping
Thinking about programming
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Thinking about programming
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Nested Looping
More Functional Decomposition
Dale/Weems/Headington Program Input and the Software Design Process
Top-Down Design & JSP Skill Area Part D
More Functional Decomposition
Presentation transcript:

Introduction to Functional Decomposition Intro to Computer Science CS 1510 Dr. Sarah Diesburg

Programs are getting larger… Our programs are starting to get large enough that we can’t hold all the details of the implementation in our heads We need a toolset to help us break down large programming problems into smaller, more manageable sub-problems 2

Breaking up our programs When should break up our programs into small problems?  …before we try to write them! Why?  We can create re-usable, debuggable pieces that save us time This means that we should integrate this notion into our early design process 3

Functional Decompostion Functional decomposition* works to break up a large programming assignment into smaller sub-problems  Working from the abstract to the concrete This is also known as top-down design 4 * Special thanks to Dr. McCormick for the use of his materials from the book: Dale, Weems, and McCormick. Programming and Problem Solving with ADA 95.

Design Abstract step – a list of major steps in our solution Concrete step – algorithmic steps that can be translated directly into Python code  …or, the code of any programming language! 5

Design What is the easiest way to solve a problem? 6

Design What is the easiest way to solve a problem?  Give the problem to someone else and say “Solve it!” Since we need to solve our own problems, let’s see if we can break this down further… 7

Design We need to break down a solution from a series of very high-level abstract steps into concrete algorithmic steps that can be implemented in code Each of the major steps becomes an independent sub-problem that we can work on independently 8

Design Why would we want to do this?  It’s much easier to focus on one problem at a time.  Can get lost in large specifications without a plan 9

Design We can create a hierarchical solution tree that goes from the most abstract steps to the concrete steps Each level of the tree is a complete solution to the problem that is less abstract than the level above it  This is known as functional equivalence 10

Hierarchical Solution Tree Concrete steps are shaded 11

Modules Each box represents a module Modules are a self-contained collection of steps that solves a problem or subproblem  They can contain both concrete and abstract steps  Concrete steps are often written in pseudocode 12

Design Warm Up – mileage.py Dr. Mobile asks you to write a program that asks for the starting and ending mileage as well as the total gasoline consumed. It then calculates the MPG and prints a nice message regarding the MPG of the car.  Recall, mpg = (ending mileage – start mileage) / gas consumed It must also print out if the car can be legally driven as-is in California by 2016 (>= 35 MPG) 13

Mileage Solution Tree Level 0 Solve the Problem No steps are shaded, so these are all abstract steps (must be broken down more to solve in code 14 1.Get Data 2.Calculate MPG 3.Print Data

Mileage Solution Tree Level 1 Get Data All steps are shaded, so these are all concrete steps that we can translate directly into Python code 15 1.Ask for starting mileage 2.Ask for ending mileage 3.Ask for gas consumed

Get Data startMileage = int(input(“Please enter the starting mileage: “)) endMileage = int(input(“Please enter the ending mileage: “)) gasConsumed = int(input(“Please enter the gas consumed: “)) 16

Mileage Solution Tree Level 1 Calculate MPG This is a concrete step that we can translate directly into Python code 17 1.Mpg = (end-start)/gas consumed

Calculate MPG mpg = (endMileage – startMileage) / gasConsumed 18

Mileage Solution Tree Level 1 Print Data We still need to break down step 2 into something more concrete 19 1.Print mpg 2.Print if car can be driven in California

Mileage Solution Tree Level 2 Drive in California These are concrete 20 1.if mpg < 35: print cannot drive else print can drive

Print Data # Print mpg print(“The total mpg is: “, mpg) #Drive in California If mpg < 35: print(“Cannot drive in California.”) else print(“Can drive in California!”) 21

Total Table 22 1.Get Data 2.Calculate MPG 3.Print Data 1.Mpg = (end- start)/gas consumed 1.Print mpg 2.Print if car can be driven in California 1.Ask for starting mileage 2.Ask for ending mileage 3.Ask for gas consumed 1.if mpg < 35: print cannot drive else print can drive Level 0 Level 1 Level 2 Solve the Problem Get Data Calculate MPG Print Data Drive in California

Something cool Each module in our solution tree could be broken into a function How do we decide?  For now, let’s not divide up the input and print portions into their own functions Relatively easy to leave them as they are  That leaves the calculation and California portions… 23