Title: CIS 103 - Computer Programming Logic
1CIS 103 - Computer Programming Logic
- Programming Concepts
- Overview
- prepared by Jack Wilson
- Cerritos College
2Topics
- 1.1 Programs
- 1.2 Modules1.3 Algorithms1.4 Statements1.5 Synt
ax Semantics1.6 Logic Planning Tools
1.7 Control Structures 1.8 Memory Concepts - 1.9 Data Types
31.1 Programs
- A program contains one or more modules.
- Some 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
41.2 Modules
- A module is a collection of statements that
performs a specific task within a program. - Module is a generic term. Programming languages
uses different names for modules. Examples
include - function C, C, VisualBasic
- method Java
- subprocedure VisualBasic
51.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
- get a number
- multiply the number by itself
- return this value
61.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 - Input
- Output
- Declaration
- Assignment
- Processing
- Compiler / Pre-Processor Directives
71.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?.
81.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 - Sequence
- Selection
- Repetition
91.6 Control Structures
Sequence Structure A single statement
or multiple statements executed
sequentially, one after another.
Example 2
Example 1
101.6 Control Structures
true
false
Selection Structure Asks a question and based on
the answer ( true or false ) one of possibly 2
paths of execution is taken.
Example 1 One path of execution
true
false
Example 2 Two paths of execution
111.6 Control Structures
Repetition Structure Asks a question and based
on the answer ( true or false ) executes a
statement. Continues to execute the statement
as long as the question evaluates to yes. A
repetition structure is usually called a "loop".
true
false
Example 1 Pre-test loop
true
false
Example 2 Post-test loop
121.7 Logic Planning Tools
- Pseudocode
- Flowchart
- IPO ( Input - Process Output ) Chart
- Structure Chart
- Decision Tree/Table
- Printer Spacing Chart
- Screen Layout Chart
- Record Layout Form text file
- Table Definition database file
131.8 Memory Concepts
- Memory is measured in bytes ( MB / GB / TB )
- A byte is 8 bits ( binary digits )
- Every byte is assigned a unique address in
memory - Data types use one or more bytes to store
information - There are different formats for storing different
types of data. Characters are stored quite
differently than are real numbers or dates.
141.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.Examples - int count boolean finished Dim name As
String - 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.
151.9 Data Types
Programs work with data ( information stored in
locations in memory ).There are many different
categories of data.
- Numeric
- integer numbers
- real numbers
- Text
- a single character value
- a "string" of characters
- Boolean
- True
- False
- Currency
- Date/Time
- Object
Every language has a 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 Currency
Java int long float double char String boolean not supported
C int long float double char char string bool not supported
VisualBasic Integer Long Single Double Char String Boolean Decimal