Software Engineering Table-driven methods General control issues.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
3 Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. Conditions can be formed using the.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Lecture 7 Flow of Control: Branching Statements COMP1681 / SE15 Introduction to Programming.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Chapter 5: Control Structures II (Repetition)
Nested if statements When one if/else structure is contained inside another if/else structure is called a nested if/else. if (grade > 60) if (grade > 70)
ECE122 L7: Conditional Statements February 20, 2007 ECE 122 Engineering Problem Solving with Java Lecture 7 Conditional Statements.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
C++ for Engineers and Scientists Third Edition
Boolean Expressions and If Flow of Control / Conditional Statements The if Statement Logical Operators The else Clause Block statements Nested if statements.
- Meeting 5 – Making Decision By: Felix Valentin, MBA.
CIS162AD - C# Decision Statements 04_decisions.ppt.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Decision Structures and Boolean Logic
Computer Science Selection Structures.
 Thursday: › Team Presentations › Risk Assessment and project plan due 11:55 pm  Friday: › Help on coding/testing  Monday: › HW 5 due, 11:55 pm.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Visual C# 2005 Decision Structures. Visual C# Objectives Understand decision making Learn how to make decisions using the if statement Learn how.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming Logic and Design, Second Edition, Comprehensive
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks.
Class 2Intro to Databases Goals of this class Include & Require in PHP Generating Random Numbers in PHP Arrays – Numerically Indexed and Associative Program.
CHAPTER 4: Selection Control Structure. Objectives  Use the relational comparison operators  Learn about AND logic  Learn about OR logic  Make selections.
Chapter 5 Logic; Got Any?. Flow of Control The order in which the computer executes statements in a program Control Structure A statement used to alter.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
1 2. Program Construction in Java. 2.4 Selection (decisions)
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Selection Statements Selection Switch Conditional.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
3. Controlling Program Flow Methods, parameters, and return values Boolean expressions Conditional branching Loops.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Java Programming Fifth Edition Chapter 5 Making Decisions.
Chapter 5: Making Decisions. Objectives Plan decision-making logic Make decisions with the if and if…else structures Use multiple statements in if and.
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
CPS120: Introduction to Computer Science Decision Making in Programs.
COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Conditional Statements Concepts Covered: Conditional Statements Serially Arranged.
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
Decision Statements, Short- Circuit Evaluation, Errors.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
Control structures in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Java Programming Fifth Edition
More on the Selection Structure
Sequence, Selection, Iteration The IF Statement
Control Structures Combine individual statements into a single logical unit with one entry point and one exit point. Used to regulate the flow of execution.
Data Types, Identifiers, and Expressions
Boolean Expressions and If
Topics The if Statement The if-else Statement Comparing Strings
Making Decisions in a Program
Topics The if Statement The if-else Statement Comparing Strings
Data Types, Identifiers, and Expressions
CMSC 202 Java Primer 2.
Visual Basic – Decision Statements
Selection Statements.
Associativity and Prescedence
Chapter 5: Selection Statement
Chapter 5 Decisions.
Compound Conditionals
Controlling Program Flow
Presentation transcript:

Software Engineering Table-driven methods General control issues

Table-driven methods A table-driven method is a schema to look up information in a table instead of using (possibly complicated) logical statements (if and case, for example).

Table-driven methods General considerations:  How to index the dimensions of a table, to avoid making it unnecessarily sparse and to make it easy to access.  What to store inside the table – data or actions.  How to declare a table in your language, so that it can accommodate its contents.

Table-driven methods Table organisation:  Direct access tables: dimensions represent meaningful values of variables. if (month = 1) { days = daysPerMonth(month - 1); days = 31; } else { daysPerMonth = if (month = 2) { days = 28; } else (...)

Table-driven methods Table organisation:  Indexed access tables: values point to indices that point to the table. value index value index

General control issues Boolean expressions: When appropriate, compare boolean values to true and false implicitly. Instead of: while (done == false)... while ((a>b) == true)... Give preference to: while (! done)... while ( a > b )...

General control issues Boolean expressions:  Simplify complicated expressions: Break complicated tests into partial tests with new boolean variables. Move complicated expressions into boolean functions. Use decision tables to replace complicated conditions.

General control issues Boolean expressions:  Form boolean expressions positively: “I ain't not no undummy.” Homer Simpson In if statements, convert negatives to positives and flip-flop the code in the if and else clauses. Use DeMorgan's laws to simplify boolean tests, e.g. prefer (A || B) to (!(!A && !B)).

General control issues Boolean expressions:  Use parentheses to clarify boolean expressions. Do not rely on the language's evaluation order. Use redundant parentheses if appropriate to make the expression more readable.  Write numeric expressions in number-line order, e.g. MIN <= i && i <= MAX, i < MIN || MAX < i.

General control issues Compound statements (blocks):  A compound statement is a collection of statements that are treated as a single statement for purposes of controlling the flow of a program. They are usually tagged by some language-specific symbol, e.g. {... }.

General control issues Compound statements (blocks):  Write pairs of braces together. Fill in the middle after you write both the opening and closing parts of a block.  Use braces to clarify conditionals. Use blocks to clarify your intentions regardless of whether the conde inside the block is 1 line or 20 lines long.

General control issues Simplifying deep nesting:  Deep nesting = more than three levels of nesting. Deep nesting should be avoided by restructuring the code.  Simplify a nested if by re-testing part of the condition.  Convert a nested if to a set of if-then- else's.  Convert a nested if to a case statement.

General control issues Simplifying deep nesting:  Factor deeply nested code into its own routine. Create specific routines for more internal tests, and leave general structure in root routine.  Entirely redesign deeply nested code.