Problem Solving with Decission Structure

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

CS101: Introduction to Computer programming
ALGORITHMS AND FLOWCHARTS
ALGORITHMS - PART 2 CONDITIONAL BRANCH CONTROL STRUCTURE
Program Flowchart, Pseudocode & Algorithm development
Understanding the Three Basic Structures
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture two Dr. Hamdy M. Mousa.
Chapter 3 IFTHENELSE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured.
Chapter 1 - An Introduction to Computers and Problem Solving
Lesson 5 - Decision Structure By: Dan Lunney
Chapter 2 - Problem Solving
Subject: Information Technology Grade: 10
ALGORITHMS AND FLOWCHARTS
Chapter 2 - Problem Solving
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
Copyright © 2012 Pearson Education, Inc. Chapter 6 Problem Solving with Decisions Problem Solving and Programming Concepts 9 th Edition By Maureen Sprankle.
Exam 3 Material Formulas, Proportions, Linear Inequalities
Algorithm & Flowchart.
ALGORITHMS AND FLOWCHARTS
Adapted from slides by Marie desJardins
Computer Programming 12 Lesson 2 - Organizing the Problem By Dan Lunney.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Chapter 1 General Problem Solving Concepts
Chapter 2 - Algorithms and Design
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
(4-2) Selection Structures in C H&K Chapter 4 Instructor - Andrew S. O’Fallon CptS 121 (September 16, 2015) Washington State University.
Problem Solving with Decisions
Programming Logic and Design, Second Edition, Comprehensive
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.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
COS120 Software Development Using C++ AUBG Fall semester 2010 Ref book: Problem Solving, Abstraction and Design Using C++ Authors: Frank Friedman, Elliot.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
Problem Solving with Decisions
1 Programming Tools Flowcharts Pseudocode Hierarchy Chart Direction of Numbered NYC Streets Algorithm Class Average Algorithm.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding the Three Basic Structures Structure: a basic unit of programming logic Any program.
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.
Concepts of Algorithms CSC-244 Unit Zero Pseudo code, Flowchart and Algorithm Master Prince Computer College Qassim University K.S.A.
Topics: Selection Statements. Processing Involving Selecting Instructions An instruction that allows deviation and selection to take place uses the ‘IF’
©Brooks/Cole, 2003 Chapter 8 Algorithms. ©Brooks/Cole, 2003 CONCEPTCONCEPT 8.1.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
Flowcharts C++ Lab. Algorithm An informal definition of an algorithm is: a step-by-step method for solving a problem or doing a task. Input data A step-by-step.
Chapter 2 Excel Fundamentals Logical IF (Decision) Statements Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
ALGORITHMS AND FLOWCHARTS. A typical programming task can be divided into two phases: Problem solving phase  produce an ordered sequence of steps that.
Introduction to Flowcharts
Lecture 2: Introduction to Programming EEE2108: 공학프로그래밍 서강대학교 전자공학과 2011 학년도 2 학기 - Algorithms and Flowcharts -
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
CHAPTER #7 Problem Solving with Loop. Overview Loop logical structure Incrementing Accumulating WHILE/WHILE-END FOR Nested loop Pointer Algorithmic instruction.
ALGORITHMS AND FLOWCHARTS
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Chapter 4: Decision Structures and Boolean Logic
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
2-1 Making Decisions Sample assignment statements
Structured Program
Understanding the Three Basic Structures
ALGORITHMS AND FLOWCHARTS
Structural Program Development: If, If-Else
Presentation transcript:

Problem Solving with Decission Structure Chapter #5

Overview Logical decision structure Instruction: IF/THEN/ELSE Logical application

Objectives Develop problems using the decision logic structure in conjunction with the sequential logic structure. Use problem-solving tools when developing a solution using the decision logic structure. Use nested decision instructions to develop a problem solution. Distinguish the different uses of straight-through, positive, and negative nested decision logic structures. Convert a positive decision logic structure to a negative decision logic structure.

What is critical thinking? Q: What is the difference between a heuristic and algorithmic solution to a problem? The difference on algorithmic and heuristic solution is that algorithmic requires series of action, and heuristic is built on knowledge and experience

What is critical thinking? A: There are set of steps H: There are no set of steps H: Relies on experience A: Doesn’t rely on experience? What are the definitions of …? (Big no)

Motivations Decission Structure comes in many forms Logical operators are first key and most important

Logical Operations

Last week: Flowchart Diagram for the Sequential Structure

Decission Structure

Figure 6.1 Flowchart Diagram of the Decision Structure

Example : Single Condition Assume you are calculating pay at an hourly rate and overtime pay (over 40 hours) at 1.5 times the hourly rate The decision to calculate pay would be stated in the following way: If the hours are greater than 40, Then the pay is calculated for overtime, or Else the pay is calculated in the usual way

Figure 6.2 Single Condition—Two Possible Actions or Sets of Actions

Figure 6.4 Straight-Through Logic—Example 1

Task Implement this flowchart with C++

Multiple If/Then/Else Instructions There are three types of decision logic you will use to write algorithms for solutions consisting of more than one decision. These types of decision logic include straight through logic, positive logic, and negative logic.

Straight-through logic Straight-through logic means that all of the decisions are processed sequentially, one after the other. There is no Else part of the instructions; the False branch always goes to the next decision, and the True branch goes to the next decision after the instructions for the True branch have been processed.

Figure 6.5 Another Example of Straight-Through Logic—Example 2

Positive logic Positive logic allows the flow of the processing to continue through the module instead of processing succeeding decisions, once the resultant of a decision is True. Whenever the resultant is False (the Else part of the decision), another decision in the sequence is processed until the resultant is True, or there are no more decisions to process. At that time, the False branch processes the remaining instructions.

Negative logic Negative logic is similar to positive logic except that the flow of the processing continues through the module when the resultant of a decision is False. Whenever the resultant is True, another decision is processed until the resultant is False, or there are no more decisions to process. At that time, the True branch processes the remaining instructions. Negative logic is the hardest to use and understand.

Nested If/Then/Else instructions Decisions using positive and negative logic use nested If/Then/Else instructions Decisions using straight-through logic do not Nested If/Then/Else instructions are sets of instructions in which each level of a decision is embedded in a level before it; like nesting baskets, one goes inside the next.

Example : Nested If/Then/Else The decission is if PayType = “Hourly” then the resultant is True and the instruction set for the True is processed This decision says, Are the hours worked greater than 40? If the answer is “yes,” the pay is processed at the overtime rate.

Figure 6.3 Nested If/Then/Else Instructions

Task Implement this flowchart with C++

Example : Nested If/Then/Else Find the amount to charge people of varying ages for a concert ticket. When the person is under 16, the charge is $7; when the person is 65 or over, the charge is $5; all others are charged $10

Nested If/Then/Else vs. Straight-Through Logic

Task Implement this flowchart with C++

Figure 6.6 Positive Logic—Example 1

Figure 6.9 Negative Logic—Example 1

Figure 6.7 Positive Logic—Example 2

Figure 6.10 Negative Logic—Example 2

Figure 6.8 The Conditions in Figure 6.7 Set Up in a Different Way

Figure 6.11 The Conditions in Figure 6.10 Set Up in a Different Way

Figure 6.13 Four Ways to Design a Set of Conditions

Figure 6.13 Four Ways to Design a Set of Conditions

Figure 6.13 Four Ways to Design a Set of Conditions

Figure 6.13 Four Ways to Design a Set of Conditions

Four Ways to Design a Set of Conditions

Questions For what type of problems would you use the case logic structure?

Questions For which of the following would you use the case logic structure? State why or why not. The cost of a car given 10 models. The cost of a car given 7 ranges of the cost of cars. Population of a state given 50 states. Average temperature of a given month. Months having a given average temperature. Bonus given commission. Temperature zone given a city’s average temperature. Cost of books for a semester.

Problems Set up four different algorithms and flowcharts for calculating a student’s letter grade given the following (do not use straight-through logic):