Vous êtes sur la page 1sur 5

CMAM 401

INTRODUCTION, BASIC SYMBOLS AND Behind the scene in action


VARIABLES Computer programmers write computer
instructions in computer programming language. Just
Computer – an electronic device that can accept, as people speak their native dialect, programmers
process and store vast amount of data to produce write programs in different languages (ex. C++,
useful information. Visual Basic, Java and COBOL). No matter which
programming language the computer programmer
Computer system components: uses, the language has rules governing its
1) Input terminology and punctuation. These rules are called
2) Process the language syntax.
3) Output
Syntax – a rule that governs a programming
Blue print – the logic and ideas transformed into a language.
map of how computer should do things; It serves as
the basis of how a computer functions, and how Note: Every programming language is unique and
data are processed inside the computer. It is has their specific set of syntax.
implemented through software (instructions that
tells the computer what to do) and executed
through the interaction of different hardware When ideas are converted into a computer
devices (physical computer itself). program, it is sent to the CPU for processing.
However, the CPU cannot understand the code
Relationship of the components of a computer (computer program) and will not do anything because
system (Blue print): of language incompatibility. For the CPU to
understand the code, a language translator is needed.
Input Process Output
Compiler (Interpreter) – the language translator
software; its role is to transform the code into a
machine language (series of 1’s and 0’s to represent
Data – in computer system, it refers to numbers, ON and OFF states of the computer devices. It is also
alphabets and alphanumeric characters. the representation of the digital electronic charges
inside the computer).
Central Processing Unit (CPU) – a tiny square
piece of “integrated circuit attached on the mother Once the code is compiled, it changes its form
board that normally has a dimension of 1” x 1”, from computer program with strict syntax to a
though small in size, its functions in the computer readable machine language that can be interpreted by
system is enormous. It is the “brain” of the the CPU. CPU then executes the instructions and
computer. performs tasks.

Components of a Central Processing Unit: Computer program (code) – the lifeblood of a


1. Control unit (C.U.) – the command center of computer system; it is a fluid that runs through the
the processor. veins of the computer that tells what organ to
Three primary functions of a control unit: function and what action to perform. It is a set of
a. read and interpret instructions logical instructions given to a computer for data
b. direct flow of operations of computer and processing that is interpreted by a compiler to
hardware devices produce used information.
c. control the flow of instructions and data
Guide questions in planning and developing a
2. Register – a temporary storage microchip that program:
holds data during processing; located inside the 1) What is the problem?
CPU and has the same function that of a 2) What are the available data?
memory, specifically the type Random Access 3) What output information or data is needed?
Memory (R.A.M.) because of its volatile 4) When do you need the output?
character – data are lost once electric current is 5) What processing is needed to produce the output?
turned off; it just holds data temporarily for 6) What is the desired output?
processing. 7) Where should the output go?

3. Arithmetic and Logic Unit (A.L.U) – the most Flowchart – a modeling tool used to illustrate data,
significant component inside the CPU. It is the instructions, process, information and workflow by the
chief of operations of the computer. use of specialized symbols. It is a step-by-step
Two major operations of Arithmetic and Logic graphical representation of a solution.
Unit:
a. Mathematical operations (addition,
subtraction, multiplication and division)
b. Logical operations (comparisons of data
such as; greater than, less than, greater
than or equal to, and less than or equal to)

CMAM401- HANDOUT PAGE 1


Basic flowchart symbols: Other flowchart symbols:
Symbol Name Description Symbol Name Definition

Defines the Manual Denotes a


Terminal starting and operation manual
(interrupt) ending point of operation or
a flow chart one which
requires an
The preparation operator
Initialization (initialization)
(pre-defined of memory Magnetic An input or
process) space for data Tape output medium
processing or a means of
secondary
The inputting of storage
Input/Output data for
processing, and A printed
the printing out Document document or
of processed report. It is
data used to show
either input or
Manipulation of output
Process data
(logical (assignments On-line Represents
process) and keyboard terminals used
mathematical as input
computations)
Represents
Defines the data stored on
Flow lines logical Punched tape punched paper
sequence of the tape. May be
program. It either input or
points to the output
next symbol to
be performed On-line It is connected
storage directly to
On-page Connects to the computer and
1 connector flowchart to represents such
avoid spaghetti devices as disks
connection on and drums
the same page
Output
Connects the information is
Off-page flowchart on Display display on
A connector different page CRTs,
to avoid terminals,
spaghetti plotters, etc…
connection
Punched card An input of data
no yes Process on cards or an
Decision conditions using output of
relational information on
operators. Used cards
for trapping
and filtering Variables – a primary storage location that can
data assume different numeric or alphanumeric values. It
is also a memory space allocated by a computer user
for processing and storing data

Variables like humans need names to be identified.


Microsoft suggests a variable naming convention
called HUNGARIAN NOTATION.

Hungarian Notation – specifies a variable with both


the data type and its description. The first three
characters in this notation specify the data type and
the remaining characters are the description of the
variable.

CMAM401- HANDOUT PAGE 2


Basic data types Arithmetic operators
Date type Description Sample Operatio Symbol Sample Explanation
*integer Whole number 10 355 1590 n
54765 1 34000 Multiply the
**float or Integer with 3.1416 0.12 value of
double decimal 1.01 12.12 Multiplicati * A*B variable A to
numbers 99.99 0.04 on the value of
*character Alphabets and J W A * variable B
special & ? Divide the
characters value of
*string Combination of Sum age int_l Division / X/Y variable X by
characters A_total the value of
grand_total variable Y
*boolean Reply of the Add the value
compiler in the Values are of variable
program that is either 1 for YES Addition + Int1+int2 int1 to the
performed or 0 for NO value of int2
behind the Subtract the
scene value of
*used mostly by all programming languages Subtractio - A-B variable B
**C/C++, Java, Visual Basic and other n from the value
programming languages specific of variable A
***Note that the data types above are not the only Square the
data types used in programming. Other Exponenti ^ C^2 value of
programming language may have their own set of ation variable C
data types with specific descriptions that are not The value of
presented above. variable a is
Greater > a>b greater than
Sample variable names using Hungarian Notation than the value of
Variable Data type Description variable b
name The value of
IntSum Integer Sum variable X is
DblTax Double Tax Less than < X<Y less than the
FltRate Float Rate value of
ChrReply Character Reply variable Y
StrLname String Lname The value of
BooAns Boolean Ans variable int1 is
Equal to == Int1 = = int2 equal to the
value of
Variable name characteristics:
variable int2
1. Must be descriptive and significant to the data,
problem and its solution. It should be The value of
variable net is
descriptive enough to identify the process or
data referring to Not equal <> Net <>Gross not equal to
to the value of
2. Combinations of alphanumeric characters
(alphabet, numbers and special characters) can variable gross
be used as a variable name provided that it The value of
starts with an alphabet variable pay1
3. Although the length of variable name can have Greater >= Pay1>=Pay2 is greater than
256 characters, the lesser the number of than or or equal to the
characters the more efficient the program is equal to value of
Examples: variable pay2
Class_size Tuition Int1 Income The value of
Sum Char3 F_name Answer the variable
Net income L_name Total Grand_total Less than <= Age1 <= Age2 age1 is less
or equal to than or equal
Computer Operators: Processing data to the value of
variable age 2
The languages of computers need to be Exercises:
converted to a language that the CPU can Convert the following mathematical expression to its
understand. For the programmer to instruct computer expression:
computers to process mathematical computations
and logical operations, they would have to define Mathematical Computer expression
symbols that computers can understand. The expression
symbols presented are the generic symbols used by 1) 3xy
computers for processing. However, as you 3*x*y
progress to the different programming languages,
the mathematical and relational symbols may vary. 2) x2 + y2
(x*x) + (y*y)
Or x^2 + y^2

CMAM401- HANDOUT PAGE 3


3) 3x 2. Create a flowchart that will assign stored
Y3 (3*x)/(y*y*y) or value of C to both A and B, where A=15,
(3*x)/(y^3) B=10 and C=20

4) a2 + b2 3. Create a flowchart that will move the value of


cd [(a*a)+(b*b)]/(c*d) or A to B and B to C. The values of the variables
(a^2 + b^2) /(c*d) are: A=25; B=30 and C = 35

4. Create a flowchart that will arrange the values


Types of variables of A, B and C in ascending order where
variable A will get the lowest value and
The role of variables in programming is very variable C gets the highest value. The values
crucial. In the processing stage of a program, the of the variables are: A=15; B=10 and C=20
variables hold the data and information (whether it
will be stored in the memory or used for 5. Create a flowchart that will arrange the values
computation or printing processed data). The of A,B,C and D in highest to lowest order
challenging part in this stage is identifying who gets where variable A gets the highest value and
the processed data? This can be clarified by the variable D gets the lowest value. The values of
descriptions of the types of variables: the variables are: A=3; B=9; C=12 and D=6
 Destructive variable – variables that destroy
or change its value after processing. This type of
variable is normally the temporary storage of INPUT/OUTPUT AND PROCESS APPLICATION
data during processing
 Constructive variable – variables that Input – the only way for the user to send data to the
maintains its value after being used in the computer for processing. It can be numeric value,
process. character or string.

Exercise: Suppose we have variables A and B and When the computer executes input
the values of A and B are 5 and 10, respectively. transaction, it expects data to be entered through the
What will happen if we have an instruction of A=B? keyboard. If none is typed in, the computer simply
waits for an input data, if no data was entered, the
Working with process symbols computer just wait for the user and gives no
response. To prevent this scenario, programmers
Basic things to remember in flowcharting: must develop the program in a way that it can
communicate to the user. For the program to
1. A flowchart always start communicate, it must have a descriptive statement to
with the instruction ask the user what to do and what type of data to
START/BEGIN … the only input.
start In the same manner, the output should also
guideline to remember in the
terminal symbol is the include a descriptive statement to communicate to
consistency of terminologies. the user the processed data to add meaning and
The organized way of writing value to it, and making it a “useful information”.
the instruction is to use pairs. Output instruction defines when and where to release
START–STOP or BEGIN-END the data in the program.

2. Initialization symbol is Sample instruction: Input an integer value 5 to


where you prepare the variable A and print the value
variables to be available for
use. When you initialize, you Input instruction using flowchart symbol:
are also allocating memory
space for your data storage. As 5
a rule, we always draw this
symbol to state the use of our Input
memory (A) 0

3. The processing symbol is A


only LIMITED to; assignment
of new value to the variables It is assumed that Integer A was initialized to 0 to
and mathematical allocate memory space. Executing the instruction,
computations integer 5 is stored to variable A destroying the
initialized value 0. Take note that the value was
4. Since we use START in the defined in the problem and in most cases the user
stop opening of our flowchart, for defines input values.
consistency, we should use
STOP to terminate
EXERCISES:
1. Create a flowchart that will store the value
of A to B, where A = 5
Output instruction using flowchart symbol:

CMAM401- HANDOUT PAGE 4


The mathematical formula given tells us to add the
values of the variables A and B to store the sum to
5 variable C.
Print (A) 5
Process instruction using flowchart symbol:
A ADD

If the Input symbol uses INPUT to accept data, the


output symbol uses PRINT to sent out data, whether C = A+B 4 6 10
the output data will be taken as an input to another
process or literally printed, the instruction that will A + B = C
be use to send out data is Print. The illustration clearly shows that the values of the
variables were added and stored to variable C. if we
In the instruction, integer 5 is sent out from would like to print the sum after processing we simply
variable A. Since we are sending out a number, we use the Output symbol as shown below:
simply say PRINT(VARIABLE NAME), in case we are
to send multiple data we say:

Print 4 6 10
(C)
A B C

Print(C,B,A) 6 4 2 10
A B C

Exercises:
1. Create a flowchart that will accept two
2, 4, 6 integers and print the sum

2. Create a flowchart that will accept a value for


radius and compute and print for the area of
In this illustration, we can clearly see that the the circle, where the formula for area is:
programmer defines the organization of the Area = ∏r2 ; the value of ∏ (Pi) is 3.1416
variables in sending out data by setting the order of
variables in the Print instruction as shown. As long 3. Create a flowchart that will accept the length
as the programmer knows the value of the of the base and height of a triangle and print
variables, the programmer can use his/her the area. The formula for computing the area
creativity in presenting output and in meeting of the triangle is: Area = ½ b*h; where b is
output requirements. the base and h is the height

 Learning Exercise1: Create a flowchart 4. Create a flowchart that will accept a


that will accept two integers and print the temperature in Fahrenheit and print its
inputted values. equivalent temperature in Celsius. The
formula for converting Fahrenheit to Celsius is
Examining the flowchart: C=5/9 (F-32); where F is the temperature in
To check if the solution meets the Fahrenheit
requirement before it is written to actual code,
programmer use a technique called SIMULATION. END OF LECTURE

Simulation – a process of executing the flowchart


in a step-by-step manner showing all the variables
used the execution of all instructions, and the
output on each step.

 Learning Exercise2: Create a simulation of


learning exercise1.

Process
Process symbol is the only area in the
program where all arithmetic computations take
place. Aside from the mathematical computation, it
can also perform an assignment. This occurs when a
variable needs to accept new data to meet the
required solution.

Sample instruction: Perform C=A+B where A=4


and B=6

CMAM401- HANDOUT PAGE 5

Vous aimerez peut-être aussi