cis 103 - computer programming logic
Post on 06-Feb-2016
73 Views
Preview:
DESCRIPTION
TRANSCRIPT
Property of Jack Wilson, Cerritos College 1
CIS 103 - Computer Programming Logic
Programming Concepts Overview
prepared by Jack WilsonCerritos 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
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
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
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
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()
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?“.
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)
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
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.
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.
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)
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
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.
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
Programming Concepts Overview Property of Jack Wilson, Cerritos College16
x.Xx Program Translation
Translators Assembler Compiler Interpreter
JIT compilation
Programming Concepts Overview Property of Jack Wilson, Cerritos College17
Identifiers
Programming Concepts Overview Property of Jack Wilson, Cerritos College18
Expressions and Statements
Programming Concepts Overview Property of Jack Wilson, Cerritos College19
Object-Oriented Programming
Programming Concepts Overview Property of Jack Wilson, Cerritos College20
Procedural Programming
Programming Concepts Overview Property of Jack Wilson, Cerritos College21
Event-Driven Programming
Programming Concepts Overview Property of Jack Wilson, Cerritos College22
Reserved Words
Programming Concepts Overview Property of Jack Wilson, Cerritos College23
Operators
Mathematical (arithmetic) Relational (boolean) Logical
Programming Concepts Overview Property of Jack Wilson, Cerritos College24
Operator Precedence and Associativity
Programming Concepts Overview Property of Jack Wilson, Cerritos College25
File Input
Programming Concepts Overview Property of Jack Wilson, Cerritos College26
File Output
Programming Concepts Overview Property of Jack Wilson, Cerritos College27
Program Development
Programming Concepts Overview Property of Jack Wilson, Cerritos College28
Making Decisions
Programming Concepts Overview Property of Jack Wilson, Cerritos College29
Looping
Programming Concepts Overview Property of Jack Wilson, Cerritos College30
Working with Strings
Programming Concepts Overview Property of Jack Wilson, Cerritos College31
Arrays
Programming Concepts Overview Property of Jack Wilson, Cerritos College32
Classes
Programming Concepts Overview Property of Jack Wilson, Cerritos College33
Class Diagrams
Programming Concepts Overview Property of Jack Wilson, Cerritos College34
Formatted Output
top related