Professional Documents
Culture Documents
PROGRAMMING
PROGRAM
set of step by step instruction that
directs the computer to do the task
you want it to do and to produce the
results wanted
organized list of instructions that
when executed, cause the computer
to behave in a predetermined
manner.
PROGRAMMING
designing or creating a set of
instruction to ask the computer to
carry out certain jobs, which normally
are very much faster than human
beings can do.
PROGRAMMING LANGUAGE
set of rules that provides a way of telling the
computer what to perform
set of commands that is formulated by the user
and executed by the computer
is an artificial language designed to express
computations that can be performed by a
machine, particularly a computer.
Can be used to create programs that can control
the behavior of a machine, to express
algorithms precisely or as a mode of human
communication.
WHY PROGRAMMING???
It helps us understand more the
computer which is a computing tool.
Lets you find out quickly whether we
like programming or not and whether
we have analytical turn of mind the
programmers need
PROGRAMMING PROCESS
DEFINING THE PROBLEM
Determine the requirement the program must
meet
Input data/requirements that are inputted.
Process the operation
Output shows the results
Planning the solution select the best method for solving
the problem
Algorithm
Flowcharting
Coding the Program
Prepare the set of instructions for the computer to execute.
The correct usage of programming language
Cont.
Testing the program perform
debugging and testing the program
Bugs error in programming
2 types of bugs
Syntax errors errors in spelling and
grammar
Semantic errors logical error/incorrect
solution
Documenting the program write up the full
specifications for other program users
ALGORITHM
procedure, recipe of a program, a finite set of instruction
A sequence of finite instructions, often used for calculation
and data processing
An algorithm about going to office
Go to work
Take a coffee break
Is it time to go home?
if yes, then go home
if no, then go to A
Is the Boss looking?
if yes, then do some work
if no, then go to B
Cont.
Changing, collecting and adding
subject
Fill out the required form.
Have it approved by the registration
office.
Present it to the accounting
Department for corresponding
adjustment fees.
Pay your additional fees at the
cahiers if any.
Cont.
area of a square
measure the width and the length of
the square
double the measure of the length
and the width of the square.
add the sum to get the total area of
square.
Cont.
interviewing a person
list down several questions you are going to ask
to ask to the interviewee
look for a place appropriate to the topic you
discuss.
contact a person you think might help you grant
this kind of interview
ask all the information you need to your
interviewee
thank the interviewee and offer him/her for a
treat.
Pseudocode
Fake code:
integer length, width, area
begin
input: length = 45 cm, width = 45
cm
print area
end
FLOWCHART
Graphical representation
Guidelines in Flowcharting:
1.
2.
3.
4.
SYMBOLS
input/Output Symbol (Parallelogram) represents
an instruction to an input or an output device.
Processing Symbol (Rectangle) represent a
group of program instructions that perform a
processing function such as arithmetic operation,
or to compare, sort, etc
Decision symbol (Diamond) denotes a point in
the program where more than one path can be
taken.
Terminal Symbol (Oval) used to designate
beginning and the end of the program
ge Connector (Small Circle) used to connect one part of a flowchart to another without drawing flow
Flowcharting
decisions
int sum
= 0, n1,
n2
Start
int sum =
0, n1=12,
n2=4
Input n1, n2
sum = n1+n2
sum = n1+n2
Display sum
Display sum
End
End
int grade
Input grade
no
Does
grade>=70
Display Failed
yes
Display Passed
End
Start
int yrLvl
Does
yrLvl=
1?
Display
freshmen
Does
yrLvl=
2?
Display
sophomore
Does
yrLvl=
3?
Display
Junior
Display
Senior
?
Does
yrLvl=
4?
Display
invalid
A
End
DATA TYPES
An attribute of data which tells the
computer (and the programmer)
something about what kind of data it
is made of
char used to hold American
standard code for information
interchanged.
float used to hold real numbers
double
int used to old integer quantities.
VARIABLE
A symbol or a name that stands for a
particular value in a program
Variables are assigned data types
that indicate what kind of data it will
store and the amount of memory it
will use.
Variables are dynamic.
Naming Variables
1. Variables must begin with a letter or an alphabet and
may be followed by combinations of alphanumeric
characters. Variable shout not begin with a number.
Example: Email, E_add123
2. Variable should be indicative of the value it holds.
example: User_1, User_2, num_1, num_2
3. Beware of using confusing letters or numbers such as zero
and the letter o.
4. Underscore is used to replace space.
Example: first_name, third_number
5. Uppercase and lowercase letters are read differently. A and
a may hold different data.
Example: A, a
VARIABLE DECLARATION
Before declaring variable, specify
first the data type of the variable(s)
Variables must be separated by
comma
All declarations must be terminated
by a semicolon (;)
EXAMPLE: int Y, e ,l;
float A,B,c;
char vowel, consonant;
KINDS OF VARIABLES
LOCAL VARIABLE
Variables that are declared inside a function.
. It can only be referenced by statements that are inside
the block in which the variables are declared.
main()
{
int a, b, c;
________:
________;
________;
}
local variables
GLOBAL VARIABLE
Global Variables are known throughout the entire program and
may be used by any piece of code.
CONSTANT
Constant is a data storage location
used by your program like variables
Constant is a data item whose value
cannot changed during the
programs execution.
2 ways of defining constants
1. # define pi 3.1416
Declared outside the main function
OPERATORS
An operator manipulates individual
data items and returns a result.
Operands or arguments - data items.
CLASSIFICATION OF
OPERATORS
MATHEMATICAL OR ARITHMETIC
OPERATORS
PerformsDEFINITION
mathematical
operator
on
OPERATOR
EXAMPLE
RESULT
values
and
variables. 5*3
*
multiplication
15
division
15/5
Addition
12+4
16
Subtraction
16-4
12
Modulus
12%5
Cont.
RELATIONAL OPERATORS
Operators that are used to compare two
values based on a certain condition. It
FUNCTION
OPERATOR
RESULT
yields a true
or falseEXAMPLE
result.
Greater than
>
9>4
Determine how
one value
relatesTrue
to
Less than
<
7<4
False
another
Equal to
==
12==12
True
Not equal to
!=
12!=12
False
Greater than
or equal to
>=
11>=3
True
Less than or
equal to
<=
3<=1
false
Cont.
LOGICAL OPERATORS
Operators that determine if a particular
condition is satisfied.
Three basic logical operators: AND, OR,
NOT
AND OPERATOR (&&)
Condition
1
Result
Also known
as Condition
Boolean 2multiplication,
meaning
all of theTrue
conditions mustTrue
be TRUE.
True
NoTrue
matter how many
False TRUE conditions
False are
there,
False if there is just
Trueone FALSE condition,
False
then
Falsethe result is FALSE.
False
False
OR OPERATOR (||)
It is known as the Boolean addition.
One TRUE condition is enough for the
Condition
1 be TRUE..
Condition 2
Result
result to
True
True
True
True
False
True
False
True
True
False
False
False
False
NOT False
True
ASSIGNMENT OPERATOR
OPERATO
R
OPERATIO
N
EXAMPLE
MEANING
Assign
value
a=12
a=12
+=
Add to
current
value
g+=h
g=g+h
-=
Subtract
from
current
g-=h
g=g-h
*=
multiply
current
g*=h
g=g*h
-=
Subtract
from
current
g-=h
g=g-h
Operation
Example
++
Increment
g++
--
decrement
g--
Meaning
g=g+1
g=g-1