Professional Documents
Culture Documents
Contents
Six Basic Computer Operations
Constants and variables
Local and global variables
Meaningful data names
Data types
Operators
Expressions and equations
Functions
Learning Outcome
Differentiate between constant data and variable data
with different data types.
Differentiate between variables and constants.
Differentiate between character, numeric and
logical data types.
Identify operators, operands, and resultants.
Identify and use operators according to their
precedence.
Set up and evaluate expressions and equations.
Understand and use pre-defined functions.
References:
Problem Solving and Programming Concepts (9th Edition) . Maureen Sprankle, Jim Hubbard, Pearson Education Limited 2012.
1
1/15/2017
4. A computer can assign a value to a 5. A computer can compare two variables and
variable or memory location select one or two alternate actions
There are three cases where you may write pseudocode An important computer operation available to the
to assign a value to a variable or memory location: programmer is the ability to compare two variables and
then, as a result of the comparison, select one of two
1. To give data an initial value in pseudocode, the alternate actions.
verbs Initialize or Set are used.
To represent this operation in pseudocode, special
2. To assign a value as a result of some processing the keywords are used: IF, THEN, and ELSE
symbols = is written.
2
1/15/2017
Local declaration
Variables declared in a certain function.
Visible only to the functions that contain them.
3
1/15/2017
4
1/15/2017
Data Types
1. Primitive Data Types
Data are unorganized facts.
A primitive data item is one containing a single
At the beginning of a program, the programmer must variable that is always treated as a unit.
clearly define the form or type of data to be collected
for the variables created. A data type consists of a set of data values and a set of
operations that can be performed on those values.
The data types can be:
Primitive Data Types, or The most common elementary data types are:
Composite Data Types integer * character * boolean
float * double
Variables declared as characters cannot be used for Mainly used as a control flag or a switch.
calculations. E.g. A+ 1 = ??? E.g.
One or more characters can be combined into a credit_ok = true
string. E.g. : a, abc, Hello World 123 !! cheque_cleared = Y
5
1/15/2017
float
A a M z k
1 5 7 8 0
+ = ( % $
6
1/15/2017
Operators
Data is connected with expressions and equations.
Operators tell computer how to process data.
Types of processing that can be done include:
Mathematical (standard mathematical operations)
Logical
to connect relational expressions
to perform operations on logical data
7
1/15/2017
+- Addition/subtraction left-to-right
|| Logical OR left-to-right
= Assignment right-to-left
+= -= Addition/subtraction assignment
*= /= Multiplication/division assignment
%= Modulus assignment
Equation
An equation stores the result of an expression in a
memory location through the equal (=) sign which is
called the assignment operator. E.g.
area = length * width
Examples: In C program:
Y + 3 is equal to X(Z + 5) Y + 3 == X * (Z + 5)
8
1/15/2017
Functions
Q: Why we need to have several functions in a program?
A: There are actually many reasons for creating more than
one functions in a program. As we learn along, you will
know the reasons behind this. But for the moment, just try
to imagine if is it better to have one person to do all the
jobs? Or have several people to split the jobs?
9
1/15/2017
10
1/15/2017
Summary
Six Basic Computer Operations
Constants and variables
Local and global variables
Meaningful data names
Data types
Operators
Expressions and equations
11