0% found this document useful (0 votes)
3 views99 pages

Programming Fundamentals Overview

This document provides an introduction to programming fundamentals, focusing on expressions, operators, and the information processing cycle. It covers various types of expressions including arithmetic, string, boolean, and logical expressions, along with their operators and evaluation rules. Additionally, it discusses the conversion of algebraic expressions into programming expressions according to syntax rules.

Uploaded by

santinodote
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views99 pages

Programming Fundamentals Overview

This document provides an introduction to programming fundamentals, focusing on expressions, operators, and the information processing cycle. It covers various types of expressions including arithmetic, string, boolean, and logical expressions, along with their operators and evaluation rules. Additionally, it discusses the conversion of algebraic expressions into programming expressions according to syntax rules.

Uploaded by

santinodote
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MODULE 1

Introduction to
Programming
Fundamentals
CC 1101
1. Major Components of Computer
System
LESSON 2. Peopleware or Human Resources
FLOW 3. Information Processing Cycle
4. Elements of Computer Program
5. Statements or Commands
EXPRESSION
EXPRESSION

A particular concept in computer science in which a


number of variables or constants, and operators and
functions, are put together in a single statement that is
acted on by a particular programming language
OPERAND

An operand is a value or data that an operator acts on in


an expression.
OPERATOR

An operator is a symbol that performs a specific


operation (like addition, subtraction, multiplication,
etc.) on the operands.
ARITHMETIC
EXPRESSION
ARITHMETIC EXPRESSION

Arithmetic expression is sometimes called numeric


expression, consisting numeric constant or numeric
variable operands, separated by an arithmetic operator,
which yield a numeric value.
ARITHMETIC EXPRESSION
OPERATORS OPERATION TO BE DONE
+ ADDITION
- SUBTRACTION
* MULTIPLICATION
/ REAL DIVISION (RESULT IS REAL NUMBER)
DIV INTEGER DIVISION (RESULT IS AN INT NUMBER)
ARITHMETIC EXPRESSION
OPERATORS OPERATION TO BE DONE
MOD, % MODULUS DIVISION (EXTRACT THE REMAINDER)
^ , ** EXPONENTIATION (IN BASIC)
-- DECREMENT
++ INCREMENT
ARITHMETIC EXPRESSION
FORMAT
1. operand operator operand
2. operand operator operand operator operand…

EXAMPLE:
403 + 205

constant operand constant operand


operator
EXAMPLES:
A*B
variable operand variable operand
operator

constant operand

X/5+B
variable operand variable operand
operator
EXAMPLES OF
ARITHMETIC EXPRESSION

a) 25 div 5 b) 25 mod 5 b) 25 * 3

5 0 75

d) 250.0 / 80.0 e) 125 - 75 f) 50 + 80

3.125 50 130
DIV OR MOD
EXPRESSION
DIV AND / EXPRESSION

Div operator yields a truncated quotient (no floating


point or decimal number).

/ operator (with decimals) yields a complete quotient that


includes the decimal part (floating-point result).
MOD AND % EXPRESSION
In C Language: The % operator returns the remainder of integer
division, and the sign of the result follows the dividend (the first
number).
In Mathematics: The mod operator returns the modulus, which
is always a non-negative remainder of a division.
EXAMPLES:

EXPRESSION C-% EXPRESSION M - MOD


5%2 1 5 mod 2 1
-5 % 2 -1 -5 mod 2 1
5 % -2 1 5 mod -2 1
-5 % -2 -1 -5 mod -2 1
EXAMPLE OF DIV OPERATION

Solution:
a) 5 div 3 1 since 2 is no longer divisible by 3
1 3 5 so the operation stop having 1 as
3 the quotient.
2
EXAMPLE OF / OPERATION

Solution: Solution:
b) 25 / 4 6 c) 4 / 5 0

6.25 4 25 0.8 5 4
24 0
1 4
EXAMPLE OF MOD (%) OPERATION

Solution:
a) 5 mod 3 1 since 2 is no longer divisible by 3
2 3 5 the operation stops getting 2 as
3 the remainder.
2
EXAMPLE OF MOD OR % OPERATION

Solution: Solution:
b) 25 % 5 5 c) 4 % 5 0

0 5 25 4 5 4
25 0
0 4
MIXED ARITHMETIC
EXPRESSION
MIXED ARITHMETIC EXPRESSION
Mixed expression is an expression having several
operands and operators. Parenthesis can be used to
group a sequence or certain portion of an expression.
EXAMPLES OF MIXED
ARITHMETIC EXPRESSION

a) 8 + 4 – 3 b) 9 * ( 3 + 25 )

c) ( 5 ^ 2 + ( 35 – 30 ) % 3 ) mod 5
PRECEDENCE

Rules that determine the order in which operations are


performed in an expression, especially when multiple
operators are involved.
ORDER OF OPERATION
ACCORDING TO PRIORITY

() EXPRESSION IN PARENTHESIS Highest Priority


^ EXPONENTS
*, /, % MULTIPLICATION, DIVISON & MODULO
+, - ADDITION & SUBTRACTION Lowest Priority
PRECEDENCE

If you could notice *, /, % or div, and mod are of the same priority
as well as – and +. In this case the rule of left-to-right sequence
should be observed. Operator on the left side will be done first.

In any expression, operations inside parenthesis are done first. In


the case that parenthesis encloses mixed operations, order of
precedence is in effect.
PRECEDENCE

Nested parenthesis (a parenthesis inside another parenthesis) the


innermost parenthesis is evaluated first ahead of the outer
parenthesis.

In case parentheses are of equal priority (equal level) the left -to-
right sequence is also in effect.
EXAMPLES:

a) 10 + 25 * 2 b) 30 div 5 * 4

10 + 50 6 * 4

60 24

* has a higher div and * have the same priority,


priority than + left-to-right sequence is to be
followed
EXAMPLES:

c) 5 * 3 + 12 mod 5 – 2 ^ 2
5 * 3 + 12 mod 5 – 4 ^ has the higher priority then the
15 + 12 mod 5 – 4 * and mod where left-to-right
sequence is applied, + and – have
15 + 2 – 4 the lowest priority where left-to-
17 – 4 right will be done.
13
EXAMPLES:

d) ( 8 + 5 ) * 3
parenthesis has a higher priority
13 * 3 than * so + will be done first
since it is inside the parenthesis.

39
STRING
EXPRESSION
STRING EXPRESSION
An expression consisting of string constant or string
variable operands separated by a string operator which
yield a string value.
FORMAT OF STRING EXPRESSION
operand operator operand operator operand…

String Operator: + concatenation


CONCATENATION
A process or operation by which the value of the
second operand (right operand) is appended or
attached to the end of the first operand (left operand).

The + operator adds if operands are numeric type and


will concatenate if operands are string type.
EXAMPLES:

Note: Please remember that any data items enclosed in


a quotation mark are considered string or non-numeric.

a) “3” + “25” b) “Hello” + “James”

“325” “HelloJames”

25 is attached to 3 “James” is attached to


“Hello”
EXAMPLES OF INCORRECT EXPRESSIONS

Be aware that in any expressions with operands of different


types causes an error, a mismatch error in particular.

13 + “25” “Dog” + 20

first operand is first operand is a


numeric and the string and the second
second is string is numeric
BOOLEAN
EXPRESSION
BOOLEAN EXPRESSION
It is one that conforms to one of two given Boolean results,
commonly characterized as true or false.

It is either a relational or logical expression, which yield


either a TRUE or FALSE value.
RELATIONAL
EXPRESSION
RELATIONAL EXPRESSIONS
Boolean type of expression composed of numeric or string
constant or expression operands, separated by a relational
operator which yield either a TRUE or FALSE value.

The General Format: operand operator operand…


THE RELATIONAL OPERATORS
ARE AS FOLLOWS:

OPERATORS MEANING
== EQUAL TO
> GREATER THAN
< LESS THAN
>= GREATER THAN OR EQUAL
<= LESS THAN OR EQUAL
<> NOT EQUAL TO
EXAMPLES:

a) “dog” < “cat” b) X + 5 > 25 mod 3

c) 5 == 4

d) 5 < > 30 e) 25 <= 30


EXAMPLES:

a) 5 > 3 Q: Is 5 greater than 3?

TRUE A: TRUE

b) 20 == 21 Q: Is 20 equal to 21?

FALSE A: FALSE
If operand is a variable, use the value
assigned to it for comparison.
RULES FOR
EVALUATING
If the operand is either a string or
RELATIONAL
EXPRESSIONS numeric expression, evaluate first the
said expressions to determine its final
value that will be used for comparison.
in the case of >= and <= operators, it is
considered to be TRUE if either one (1) of
RULES FOR them conforms with the condition or has
EVALUATING the answer TRUE if compared.
RELATIONAL
EXPRESSIONS if both operands are string type they are
related or compared through their ASCII
code value equivalent.
EXAMPLES:

Q: Is 5 greater or equal to 4?
a) 5 >= 4
Analysis: 5 may not be equal but it is
greater than 4.
TRUE
A: TRUE

b) 25 <= 25 Q: Is 25 less than or equal to 25?


Analysis: : 25 (1st operand) may not be
TRUE less than but it is equal 25 (2nd operand)
A: TRUE
EXAMPLES:
“Ana” <= “ana”

TRUE

Comparison: Therefore, "Ana" <= "ana" will evaluate to true in many


programming languages because:

"Ana" is compared to "ana" character by character.


Since "A" (65) is less than "a" (97), "Ana" is considered less than
or equal to "ana".
EXAMPLES:
“Hello” >= “Good”

TRUE

Comparison: Compare the strings character by character:

The first character of "Hello" is "H", and the first character of


"Good" is "G".
In ASCII, "H" has a value of 72, and "G" has a value of 71.

Result: Since "H" (72) is greater than "G" (71), "Hello" is considered
greater than "Good".
EXAMPLES:
“ANO” > “ANN”

TRUE

Both strings have "A" & "N" as the 1st & 2nd character, so they
are equal at this position as well.

Since "O" (ASCII value 79) is greater than "N" (ASCII value 78),
"ANO" is considered greater than "ANN".
LOGICAL
EXPRESSION
LOGICAL EXPRESSION
It is composed of one or more relational expressions
separated by a logical operator which yield either TRUE
or FALSE value.

The General Format:


relational expression operator relational expression...
THE LOGICAL OPERATORS
ARE AS FOLLOWS:

OPERATORS MEANING

! NOT

&& AND

|| OR
LOGICAL EXPRESSION

Only the NOT is allowed to be placed before the


relational expression operand. AND and OR operators
are always used in between relational expression.
Parenthesis can be added to signify priorities.
EXAMPLES OF
LOGICAL EXPRESSIONS

NOT 5 == 2 + 3

14 >= 5 AND 10 == 5

( “Hi” == “Hello” ) OR 25 mod 3 == 5 div 5


LOGICAL EXPRESSION
To evaluate logical expressions, relational expressions
must be evaluated first whether the said relational
expression is TRUE or FALSE. After evaluating relational
expression, logical operation is to be evaluated next
using the Truth Table as the basis of the final answer.
THE TRUTH TABLE FOR
NOT (!) OPERATOR

NOT (!) TRUE FALSE

NOT (!) FALSE TRUE


THE TRUTH TABLE FOR
AND (&&) OPERATOR

TRUE AND TRUE TRUE

TRUE AND FALSE FALSE

FALSE AND TRUE FALSE

FALSE AND FALSE FALSE

It only become TRUE if both the operands are true – the


rest are false.
THE TRUTH TABLE FOR
OR (||) OPERATOR

TRUE OR TRUE TRUE

TRUE OR FALSE TRUE

FALSE OR TRUE TRUE

FALSE OR FALSE FALSE

It only become FALSE if both the operands are false – the


rest are true.
EXAMPLES OF LOGICAL
EXPRESSION EVALUATION:

1) Y > 50 OR Name == “Johnny”


Assuming that:
X=5
Y = 35 FALSE OR FALSE
Name = “John”
FALSE

Relational and arithmetic expressions are evaluated first before all


logical operations. To get the final answer, follow the Truth Table
EXAMPLES OF LOGICAL
EXPRESSION EVALUATION:

Assuming that: X = 5 , Y = 35 , Name = “John”

2) X + Y == Y + X AND 5 == 35 mod 15

40 40 AND 5 == 5

TRUE TRUE

TRUE
MIXED LOGICAL
EXPRESSION
ORDER OF OPERATION
ACCORDING TO PRIORITY

() PARENTHESIS Highest Precedence


! NOT
&& AND
|| OR Lowest Precedence
EXAMPLE MIXED LOGICAL
EXPRESSION EVALUATION:

5 mod 3 == 2 AND (25 >= 25 OR 5 < 7 )

2 == 2 AND TRUE OR TRUE

TRUE AND TRUE

TRUE
EXAMPLE MIXED LOGICAL
EXPRESSION EVALUATION:

If A = 1 , B = 10 , C = 50

A == 1 OR A == 2 OR A == 3
C div 5 == B AND B * 5 == C OR C div C == A
CONVERSION OF ALGEBRAIC
EXPRESSION INTO A
PROGRAM EXPRESSION
CONVERSION OF ALGEBRAIC
EXPRESSION INTO A PROGRAM
EXPRESSION:

In programming, mostly, if not all, algebraic expressions do


not normally operate when used as it is in a program.
EXAMPLES

XY + 2 100 – 5 * 2
ABC 5

A X
3+6 +
X+B 1
(6–2)(8+5)
2
CONVERSION OF ALGEBRAIC
EXPRESSION INTO A PROGRAM
EXPRESSION:

In any programming language, these examples will not be


evaluated, instead they will be considered as invalid or incorrect.
They need to be converted into a programming format in
accordance with the syntax rule of a computer language being
used.
In this manual, having used the pseudo – programming language,
only the following symbols and elements must be included in an
expression. They are:

( ) PARENTHESIS
*, /, MOD, DIV, +, -, ^ OPERATORS
CONSTANTS (STRING OR NUMERIC) OPERANDS
VARIABLE (STRING OR NUMERIC) OPERANDS
CONVERSION EXAMPLE:

Algebraic Program Expression

XY + 2
( X * Y + 2 ) / ( A * B * C)
ABC

100 – 5 * 2
( 100 – 5 * 2 ) / 5
5
CONVERSION EXAMPLE:

Algebraic Program Expression

3+6
(3 + 6 ) / (( 6 – 2 ) * ( 8 + 5 ))
(6–2)(8+5)

A X
+
X+B 1 A/(X+B)+X/(1/2)
2
FORMULATION OF NUMERIC
EXPRESSIONS:
FORMULATION OF NUMERIC
EXPRESSIONS:
Constructing numeric expressions from algebraic formulas is
straightforward, but converting them into a program requires
careful consideration. Programmers often need to create
numeric expressions, which is a key part of their job.
Typically, these expressions are derived from the problem
statement itself.
EXAMPLES:
Statement 1:
Perimeter of an isosceles triangle is equals two times the
length of one of the equal sides plus the length of the base.
Note: Keywords to use in the expression are underlined

Constructed numeric expression:

P – perimeter
P=2*S+B S – sides
B – base
EXAMPLES:

Statement 2:
The surface area of a circle equals PI multiplied by the square
of the radius.

Constructed numeric expression:


AREA = 3.1416 * R ^ 2
or AREA = 3.1416 * ( R*R )
EXAMPLES:

Statement 3:
The circumference of a circle is equals pi times the
diameter.

Constructed numeric expression:


Circumference = 3.1416 * diameter
MULTI-LINED EXPRESSION
MULTI-LINED EXPRESSION

A multi-lined expression in computer programming refers to


an expression that spans multiple lines of code. This is often
done for readability or to fit within line length limits. Multi-
lined expressions are commonly seen in complex
calculations, conditionals, or function calls.
EXAMPLE OF MULTI-LINED EXPRESSION
Payroll Calculation:

Gross_Pay = Basic_ Pay + Allowance + Overtime


SSS = Gross_Pay * 0.02
WTax = Gross_Pay * 0.04
PhilHealth = 75
Total_Deduction = SSS + WTax + Phil health
Net_Pay = Gross_Pay – Total_Deduction
FORMULATION OF BOOLEAN
EXPRESSION
FORMULATION OF BOOLEAN
EXPRESSION:
Involves creating logical statements that can evaluate to
either true or false. These expressions are fundamental in
decision-making processes within a program.

These are typically composed of variables, constants,


and logical operators such as AND, OR, and NOT.
EXAMPLES:
Statement 1:
Applicant’s age is at most 30 years old.
Expression:
AGE <= 30
Explanation:
In the statement above, age of the applicant is use to be
compared to 30. The word “at most” simply notes that 30 should
be the highest age but it can be less, thus <= (less than or equal
to) was used.
EXAMPLES:

Statement 2:
Number of pupils in the room is either 30 or 40.
Expression:
Pupils == 30 OR Pupils == 40

Explanation:
Pupils’ number can be either 30 OR 40. OR operator was use
because of the word “either” in the statement.
EXAMPLES:

Statement 3:
Players’ age is from 20 to 25, inclusive.
Expression:
AGE >= 20 AND AGE <= 25
Explanation:
AGE should be from 20 to 25, “inclusive” word suggest that the
lower limit 20 and the upper limit 25 should be included in the
parameter.
EXAMPLES:

Statement 4:
X is either 6, 8 or 10
Expression:
X = 6 OR X = 8 OR X = 10
EXAMPLES:

Statement 5:
X is between 100 and 200, exclusive except 120, 140 and 160.
Expression:
( X > 100 AND X < 200 ) AND ( X < > 120 AND X < > 140 AND X < > 160 )
or
( X > 100 AND X < 200 ) AND NOT ( X == 120 OR X == 140 OR X == 160)
EXAMPLES:

Statement 6:
Sum of A and B is at most 100
Expression:
A + B <= 100
STATEMENTS OR
COMMANDS
STATEMENTS OR COMMANDS

Statements are keywords that perform a predefined


process that computer can understand. Each statement
follows a syntax rule or format on how they should be used
for them to function properly.
STATEMENTS OR COMMANDS

A statement successfully generates machine language


instructions that a computer can understand when the program
is interpreted or compiled. Each statement in a high-level
language corresponds to several machine language instructions.
Thus, a programmer can write program more quickly.
STATEMENTS OR COMMANDS

Statements are classified according to their


applications such as:
INPUT STATEMENT

Commands that are use to enter data through input


devices.
ASSIGNMENT STATEMENT

Statements that assign value to a variable used in a


program code.
OUTPUT STATEMENT

Commands that display information from the memory of the


computer to the output devices.
CONDITIONAL STATEMENTS

These are selective statements that control a program flow


depending on the condition given.
LOOP STATEMENTS

Commands used to repeat or iterate certain sequence or


group of instructions.
THANK YOU!
DO YOU HAVE ANY QUESTIONS?

You might also like