Chapter 6 Problem Solving and Algorithm Design. 2 Phase Interactions.

Slides:



Advertisements
Similar presentations
Low-Level Programming Languages and Pseudocode
Advertisements

1 Algorithms Algorithm A set of unambiguous instructions for solving a problem or subproblem in a finite amount of time using a finite amount of data Why.
Low-Level Programming Languages and Pseudocode Chapter 6.
Slides modified by Erin Chambers Problem Solving and Algorithm Design.
Programming Dr. Abraham Most slides are from your textbook.
Low-Level Programming Languages and Pseudocode Chapter 6.
Chapter 6 Problem Solving and Algorithm Design. 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
Computer Science 101 Overview of Algorithms. Example: Make Pancakes Prepare batter Beat 2 eggs Add 1 tablespoon of brown sugar Add 1 cup of milk Add 2.
Program Design and Development
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Problem Solving and Algorithm Design
Slides modified by Erin Chambers Problem Solving and Algorithm Design, part 2.
DCT 1123 Problem Solving & Algorithms
Presented by Joaquin Vila Prepared by Sally Scott ACS 168 Problem Solving Using the Computer Week 12 Boolean Expressions, Switches, For-Loops Chapter 7.
Low-Level Programming Languages and Pseudocode
C HANGES (P ROG 600 – 58 T ) AP Computer Science 2010 By: Chia-Hsuan Wu.
Exponents and Scientific Notation
University of Texas Pan AmDr. John P. Abraham Information Technology Computer Architecture Dr. John P. Abraham.
An ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time Let's examine the four parts of this.
Quiz # 2 Chapters 4, 5, & 6.
How Computers Work Dr. John P. Abraham Professor UTPA.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Primitive Types, Strings, and Console I/O Chapter 2.1 Variables and Values Declaration of Variables Primitive Types Assignment Statement Arithmetic Operators.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
Chapter 6 Problem Solving and Algorithm Design. 2 Problem Solving Problem solving The act of finding a solution to a perplexing, distressing, vexing,
Chapter 6 Problem Solving and Algorithm Design. 2 Chapter Goals Apply top-down design methodology to develop an algorithm to solve a problem Define the.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
Penny Nickel Dime Penny Nickel Dime Quarter Half Dollar.
Counting Coins. The Basics Quarter 25 cents Dime 10 cents.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Procedural Programming. Programming Process 1.Understand the problem 2.Outline a general solution 3.Decompose the general solution into manageable component.
Chapter Algorithms 3.2 The Growth of Functions 3.3 Complexity of Algorithms 3.4 The Integers and Division 3.5 Primes and Greatest Common Divisors.
Name the United States Coins Count the Pennies 10 ¢
Advanced Program Design. Review  Step 1: Problem analysis and specification –Specification description of the problem’s inputs and output –Analysis generalize.
1 Lecture 3 Control Structures else/if and while.
© 2010 Pearson Prentice Hall. All rights reserved. CHAPTER 5 Number Theory and the Real Number System.
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
Dividing Decimals by a Whole Number 3.6 ÷ 3.
Using Recursion to Convert Number to Other Number Bases Data Structures in Java with JUnit ©Rick Mercer.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
Chapter 6 Problem Solving and Algorithm Design. 2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
Quiz1 Question  Add Binary Numbers a) b) c) d) e) none
Low-Level Programming Languages, Pseudocode and Testing Chapter 6.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
Algorithms 09/04/13. Algorithm Step-by-step process for solving a problem. Often described in pseudocode language. Unambiguous, Executable and Terminating.
Introduction to Computer Programming
System Calls & Arithmetic
Program design Program Design Process has 2 phases:
ALGORITHMS AND FLOWCHARTS
while Repetition Structure
Lesson 111: Three Statements of Equality
Chapter R Prealgebra Review Decimal Notation.
CHAPTER 2 & 3: Pseudocode and Developing and Algorithm
Chapter 4: Algorithm Design
Week 7- 2nd 6 Weeks.
Applying Exponent Rules: Scientific Notation
Name the United States Coins
Problem Solving and Algorithm Design
Chapter 4: Algorithm Design
Programming We have seen various examples of programming languages
Chapter 2 Control Structures.
Dividing a whole number to get decimal
COMPUTING.
Presentation transcript:

Chapter 6 Problem Solving and Algorithm Design

2 Phase Interactions

3 Pseudocode While ( the quotient is not zero ) Divide the decimal number by the new base Make the remainder the next digit to the left in the answer Replace the original decimal number with the quotient

4 Following an Algorithm Figure 6.4 A recipe for Hollandaise sauce

5 Following an Algorithm Algorithm for preparing a Hollandaise sauce If concerned about cholesterol Put butter substitute in a pot Else Put butter in a pot Turn on burner Put pot on the burner While (NOT bubbling) Leave pot on the burner Put other ingredients in the blender Turn on blender While (more in pot) Pour contents into lender in slow steam Turn off blender

6 Following Pseudocode What is 93 in base 8? 93/8 gives 11 remainder 5 11/8 gives 1 remainder 3 1/ 8 gives 0 remainder 1 answer While ( the quotient is not zero ) Divide the decimal number by the new base Make the remainder the next digit to the left in the answer Replace the original decimal number with the quotient

7 Pseudocode for Complete Computer Solution Write "Enter the new base" Read newBase Write "Enter the number to be converted" Read decimalNumber Set quotient to 1 While (quotient is not zero) Set quotient to decimalNumber DIV newBase Set remainder to decimalNumber REM newBase Make the remainder the next digit to the left in the answer Set decimalNumber to quotient Write "The answer is " Write answer

8 Following Pseudocode

9 Pseudocode Functionality Variables Names of places to store values quotient, decimalNumber, newBase Assignment Storing the value of an expression into a variable Set quotient to 64 quotient <-- 64 quotient <-- 6 *

10 Pseudocode Functionality Output Printing a value on an output device Write, Print Input Getting values from the outside word and storing them into variables Get, Read

11 Pseudocode Functionality Repetition Repeating a series of statements Set count to 1 While ( count < 10) Write "Enter an integer number" Read aNumber Write "You entered " + aNumber Set count to count + 1

12 Pseudocode Functionality Selection Making a choice to execute or skip a statement (or group of statements) Read number If (number < 0) Write number + " is less than zero." or Write "Enter a positive number." Read number If (number < 0) Write number + " is less than zero." Write "You didn't follow instructions."

13 Pseudocode Functionality Selection Choose to execute one statement (or group of statements) or another statement (or group of statements) If ( age < 12 ) Write "Pay children's rate" Write "You get a free box of popcorn" else If ( age < 65 ) Write "Pay regular rate" else Write "Pay senior citizens rate"

14 Pseudocode Example Write "How many pairs of values are to be entered?" Read numberOfPairs Set numberRead to 0 While (numberRead < numberOfPairs) Write "Enter two values separated by a blank; press return" Read number1 Read number2 If (number1 < number2) Print number1 + " " + number2 Else Print number2 + " " number1 Increment numberRead

What do you think? Some people feel new algorithms are discovered and others feel that new algorithms are created. What do you think? What conclusions about ownership and rights can be made based upon the differing perspectives? 15

Problem Solving Develop an algorithm that would return the fewest coins in change from a purchase of under one dollar (include pennies, nickels, dimes, quarters). 16