property of jack wilson, cerritos college1 cis 103 - computer programming logic programming concepts...

34
Property of Jack Wilson, Cerritos College 1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Upload: clementine-jones

Post on 28-Dec-2015

224 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Property of Jack Wilson, Cerritos College 1

CIS 103 - Computer Programming Logic

Programming Concepts Overview

prepared by Jack WilsonCerritos College

Page 2: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College2

Topics

1.1 Programs

1.2 Modules1.3 Algorithms1.4 Statements1.5 Syntax & Semantics1.6 Logic Planning Tools 1.7 Control Structures 1.8 Memory Concepts

1.9 Data Types

Page 3: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College3

1.1 Programs

A program contains one or more modules.

Many languages require a module with a special name, such as "main" for a program to be created.

Programs are often also referred to as applications or more generally as software.

Program

module

module

Page 4: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College4

1.2 Modules

A module is a collection of statements that perform a specific task within a program.

Module is a generic term. The most commonly used terms are listed below.

function C, C++, Python method Java

Page 5: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College5

1.3 Algorithms

An algorithm is the name given to the logic that is developed and used to code the statements in a module.

Implementation of the algorithm in a module (function):

double square ( double number ){ return number * number;}

Algorithm to square a number:

1. get a number

2. multiply the number by itself

3. return this value

Page 6: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College6

1.4 Statements

A statement is the name given to a high level language instruction.

Programs are written using a variety of different types of statements. Examples include: Declaration int count Assignment count = 0 Input get(number) Output put(“Grand Total is “ + total) Module Invocation printHeadings()

Page 7: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College7

1.5 Syntax & Semantics

Syntax refers to the rules of a language that must be followed to construct a valid statement. Statements are constructed using the following components:

reserved words ( aka keywords ) identifiers operators literals punctuation symbols

Semantics refers to the meaning of a statement. It addresses the question "What does the statement do?“.

Page 8: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College8

1.6 Control Structures

A control Structure determines the flow of execution for statements executing in a module.

There are 3 control structures that are used in all programming languages:

1. Sequence 2. Selection 3. Repetition (aka Iteration)

Page 9: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College9

1.6 Control Structures

Sequence Structure

A sequence structure performs a single task without asking any questions or repeating anything. • declare a variable• assign a value to a variable• input a value• output a value• call a function• return a value from a function• stop program execution

Page 10: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College10

1.6 Control Structures

Selection Structure

Asks a question (called a condition) and based on the answer ( true or false ) follows a path of execution.

In example 2, only one of the paths of execution would be followed.

The diamond symbol represents a condition that evaluates to true or false.

Example 1 – One path of execution

Example 2 – Two paths of execution

truefalse

false true

The rectangle

represents a structure.

Page 11: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College11

1.6 Control Structures

Repetition Structure

Asks a question (called the condition) and based on the answer ( true or false ) executes a statement or exits the structure.

Continues to execute the statement as long as the condition evaluates to yes.

A repetition structure is often called a "loop".

Example 1: Pre-test loop

Example 2: Post-test loop

true

false

false

true

The rectangle represents a statement.

The diamond represents a condition.

Page 12: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College12

1.7 Logic Planning Tools

Pseudocode Flowchart Hierarchy Chart Printer/Screen Spacing Chart File Description (record layout chart)

Page 13: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College13

1.8 Memory Concepts

Memory is measured in bytes ( KB / MB / GB / TB )

A byte is 8 bits ( binary digits )

Every byte in RAM memory is assigned a unique address

Data types use one or more bytes to store information

integer – 4 bytes real number – 8 bytes

Page 14: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College14

1.8 Memory Concepts

To avoid having to reference a specific location in memory to access a piece

of data, variable names are used instead of addresses. To use a variable in

a program, you must declare the variable by giving it a name and a data

type.

[ RAPTOR does not require us to do this ]

Examples:

int count boolean finished string name

When a program is executed, a symbol table ( think of it as a data dictionary

in memory ) is created that maps the name of a variable to the location in

memory where the data is being stored.

Page 15: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College15

1.9 Data Types

Numeric integer numbers real numbers

Text a single character value a "string" of characters

Boolean True False

Programs work with data ( information stored in locations in memory ).There are many different categories of data.

Every language has specific keywords which are used to specify a data type. Not all data types are supported in all languages.

Here are some examples:

Language Numeric Text Boolean

Java intlongfloatdouble

charString

boolean

C++ intlongfloatdouble

charstring

bool

Page 16: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College16

x.Xx Program Translation

Translators Assembler Compiler Interpreter

JIT compilation

Page 17: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College17

Identifiers

Page 18: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College18

Expressions and Statements

Page 19: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College19

Object-Oriented Programming

Page 20: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College20

Procedural Programming

Page 21: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College21

Event-Driven Programming

Page 22: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College22

Reserved Words

Page 23: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College23

Operators

Mathematical (arithmetic) Relational (boolean) Logical

Page 24: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College24

Operator Precedence and Associativity

Page 25: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College25

File Input

Page 26: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College26

File Output

Page 27: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College27

Program Development

Page 28: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College28

Making Decisions

Page 29: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College29

Looping

Page 30: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College30

Working with Strings

Page 31: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College31

Arrays

Page 32: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College32

Classes

Page 33: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College33

Class Diagrams

Page 34: Property of Jack Wilson, Cerritos College1 CIS 103 - Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College

Programming Concepts Overview Property of Jack Wilson, Cerritos College34

Formatted Output