Principles of Programming
Principles of Programming
introduction
What is programming?
Assembly languages:
A language which use mnemonics for instructions
Mnemonics:
alphabetic abbreviations for instructions
Lempogo Forgor © 2011. All Rights
Reserved
Programming Languages
(continued)
Assembler:
program that converts assembly language
instructions into machine code
High-level languages:
Instructions resemble English language
Require an interpreter or compiler to convert
high-level language to machine code
Interpreter:
translates high-level instructions line-by-line as
the program runs
Compiler:
translates entire program into machine code
before running the program
Lempogo Forgor © 2011. All Rights
Reserved
Level of Programming
language
When choosing a programming language to
make a project, many different considerations
can be taken. First, one must decide what is
known as the level of the programming
language
Identify input
What information will the computer need to
know to print, display, or store the output
items?
Output?
Annual Commission
Output?
New Pay
Flowchart
Uses standardized symbols to
visually depict an algorithm
Lempogo Forgor © 2011. All Rights
Reserved
Step 2 – Plan Algorithm One
Input?
Annual Sales
Commission Rate
Output?
Annual Commission
algorithm
1. enter the annual sales and commission
rate
2. calculate the annual commission by
multiplying the annual sales by the
commission rate Lempogo Forgor © 2011. All Rights
Reserved
Step 2 – Plan the Algorithm
(continued)
Flowchart symbols
Oval: start/stop symbol
Parallelogram: input/output symbol
Rectangle: process symbol
Flowlines
Connect symbols
Processing item:
intermediate value that algorithm uses when
processing input into output
Lempogo Forgor © 2011. All Rights
Reserved
Lempogo Forgor © 2011. All Rights
Lempogo Forgor © 2011. All Rights
Reserved
Lempogo Forgor © 2011. All Rights
Reserved
Lempogo Forgor © 2011. All Rights
Reserved
Algorithm
Desk-checking (hand-tracing)
Programmer reviews algorithm while seated
at his or her desk
Valid data
Data that algorithm is expecting user to
enter
Invalid data
Data that algorithm is not expecting user to
enter
Lempogo Forgor © 2011. All Rights
Reserved
Lempogo Forgor © 2011. All Rights
Reserved
Lempogo Forgor © 2011. All Rights
Reserved
Algorithm
In mathematics, computing, linguistics, and related
subjects, an algorithm is an effective method for
solving a problem using a finite sequence of
instructions.
if <condition>
do stuff;
else
do other stuff;
while <condition>
do stuff;
variables
Variables And Data types
In computer programming, a variable is an identifier
(usually a letter, word, or phrase) that is linked to a value
stored in the system's memory or an expression that can
be evaluated.
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
.
Identifiers
A valid identifier is a sequence of one or
more letters, digits or underscore
characters (_).
For example:
int a;
float mynumber;
Declaration of variables
These are two valid declarations of
variables.
int MyAccountBalance;
Scope of variables
All the variables that we intend to use in a
program must have been declared with its
type specifier in an earlier point in the code,
like we did in the previous code at the
beginning of the body of the function main
when we declared that a, b, and result were of
type int.