tools for structured and object oriented design - simple sequence control structures

24
Simple Sequence Control Structure Tools for Structured and Object-Oriented Design

Upload: andrew-carts

Post on 19-Feb-2016

26 views

Category:

Documents


0 download

DESCRIPTION

Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

TRANSCRIPT

Page 1: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Simple Sequence Control Structure

Tools for Structured and Object-Oriented Design

Page 2: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Objectives• Define an algorithm• Name the characteristics of an algorithm• Name the four parts, in order, of a data hierarchy• Identify, and use in program flowchart and system

flowchart• Identify, and use in program design, the terminal

interrupt, general I/O, and process program flowcharting symbol

• Identify, and use in program design, variables, constants, and assignment statements.

Page 3: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Objective (continued)

• Distinguish between input and output, and explain why input and output steps are needed in program design

• Performa procedure execution of a simple algorithm

Page 4: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Algorithm?

• What is an algorithm? (al´g&-rith-&m) (n.) – A formula or set of steps for solving a particular

problem. – To be an algorithm, a set of rules must be

unambiguous and have a clear stopping point. – Algorithms can be expressed in any language,

from natural languages like English or French to programming languages like FORTRAN.

• What are the characteristics of an algorithm?

Page 5: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Understanding Unstructured Spaghetti Code

• The popular name for snarled program statements is spaghetti code

• The reason for the name should be obvious—the code is as confusing to read as following one noodle through a plate of spaghetti

Page 6: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Understanding the Simple Sequence Structures

• A structure is a basic unit of programming logic; each structure is a sequence, selection, or loop

• The first of these structures is a sequence, as shown in Figure 2-3

• With a sequence structure, you perform an action or event, and then you perform the next action, in order

Page 7: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Wake up Algorithm

Page 8: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Understanding the Data Hierarchy

• When data is stored for use on computer systems, it is often stored in a data hierarchy, where the smallest usable unit of data is the character

• Characters are letters, numbers, and special symbols, such as “A”, “7”, and “$”

• A field is a single data item, such as lastName, streetAddress, or annualSalary

Page 9: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Understanding the Data Hierarchy (continued)

• Records are groups of fields that go together for some logical reason

• Files are groups of records that go together for some logical reason

• A database holds a group of files, often called tables, that together serve the information needs of an organization

• Database software establishes and maintains relationships between fields in these tables, so that users can write questions called queries

Page 10: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Data Hierarchy

Page 11: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

System vs. ProgramFlowchart

• System Flowchart– Illustrating the basic inputs, processes, and

outputs of the computer system.• Program Flowchart

– Step by step logic of the program

Page 12: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

System Flowchart

Page 13: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Program Flowchart

Page 14: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

System vs. Program

Page 15: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Flowchart Form

Page 16: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Using and Naming Variables

• Variables are memory locations, whose contents can vary or differ over time

• Sometimes, inputNumber can hold a 2 and calculatedAnswer will hold a 4; at other times, inputNumber can hold a 6 and calculatedAnswer will hold a 12

• A variable name is also called an identifier

Page 17: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Using and Naming Variables (continued)

• Variable names used here follow only two rules:

1. Must be one word

2. Have some appropriate meaning

Page 18: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Assigning Values to Variables

• When you create a flowchart or pseudocode for a program that doubles numbers, you can include the statement compute caclulatedAnswer as inputNumber times 2

• This statement incorporates two actions:– First, the computer computes the arithmetic value

of inputNumber times 2– Second, the computed value is stored in the calculatedAnswer memory location

Page 19: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Assigning Values to Variables (continued)

• Most programming languages allow a shorthand expression for assignment statements such as compute caculatedAnswer as inputNumber times 2

• The shorthand takes the form calculatedAnswer = inputNumber * 2

• The equal sign is the assignment operator, which always requires the name of a memory location on its left side—the location where the result will be stored

Page 20: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Understanding Data Types

• Computers deal with two basic types of data—character and numeric

• When you use a specific numeric value, such as 43, within a program, you write it using the digits and no quotation marks

• A specific numeric value is often called a numeric constant because it does not change—a 43 always has the value 43

• When you use a specific character value, or string of characters, such as “Chris” you enclose the string, or character constant, within quotation marks

Page 21: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Understanding Data Types (continued)

• Most computer languages allow at least two distinct types of variables:– One holds a number, often called a numeric

variable– Others hold letters of the alphabet and various

special characters such as punctuation marks, and are called character, text, or string variables, depending on the language being used

Page 22: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Understanding Data Types (continued)

• Some languages allow for several types of numeric data

• Languages such as Pascal, C++, C#, and Java distinguish between integer (whole number) numeric variables and floating-point (fractional) numeric variables containing a decimal point

Page 23: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Flowchart Template

Page 24: Tools for Structured and Object Oriented Design - Simple Sequence Control Structures

Graphical User InterfaceGUI