LN 2
LN 2
A variable
• may change during processing.
• A programmer must give a name to each variable value used in a solution.
• The computer sets up a specific memory location to hold the value of each
variable name found in a program.
• Variables can be any data type.
Naming Convention
• Firstly, it allows several programmers to work on the same project without
the problem of conflicting variable names.
• Logical data consist of two values in the data set—the words True and
False.
• These are used in making yes-or-no decisions.
• For example, logical data type might be used to check someone’s
credit record; True would mean her credit is okay, and
False would mean it’s not okay.
HOW THE COMPUTER STORES THE DATA
FunctionName(data)
• The value of the function is returned.
• Functions use data. The data is listed as part of the function and are
called parameters.
• Sqrt(N): This function will calculate the square root of N.
• Sqrt is the name of the function.
• N is the data needed to calculate the square root and, therefore, it is the
parameter.
• Parameters are surrounded by parentheses.
• The maximum function, Max(N1, N2,N3), will find which of three
numbers is the largest. Max is the name of the function. N1, N2 and
N3 are parameters.
OPERATORS
• Operators are the data connectors within expressions and equations.
They tell the computer how to process the data.
• They also tell the computer what type of processing (mathematical, logical,
or whatever) needs to be done.
• The types of operators used in calculations and problem solving include
mathematical, relational, and logical operators.
• Mathematical operators include addition, subtraction, multiplication,
division,Binteger division, modulo division, powers, and functions. The
computer has a symbol for each of them
RELATIONAL OPERATORS:
LOGICAL OPERATORS:
OR EXAMPLE:
For example, when a store might require a driver’s license or a check-cashing card on file for a
customer to cash a check.
• When the customer has a driver’s license, the check can be cashed. When she has a check-
cashing card, the check can be cashed.
• The expression is written as License OR Card.
AND EXAMPLE:
• when a store requires a customer to have both a driver’s license and a check-cashing card to cash
a check.
• The expression is written as License AND Card.
NOT EXAMPLE:
• The resultant of the NOT operator changes an operand from True to False, or from False to True.
• A programmer uses the NOT operator to change an operand to the opposite value.
• The processing of the operands
(as directed by the operators) always starts
with the innermost parentheses and works
outward, and processes from left to right.
• An equation stores the resultant of an
expression in a memory location in the
computer through the equal sign.
Area=Length*Width
Example:
Evaluating a Mathematical Expression
EXAMPLE: Assume the programmer has written the expression
References: PROBLEM SOLVING & PROGRAMMING CONCEPTS, Maureen Sprankle, Jim Hubbard, 9th Ed., Pearson Education Limited, 2012