- The computer has to be told how to process data.
- This task is accomplished through the use of operators in high level languages
- Operators are data connectors within expressions and equations
- The type of operator used in problem solving are mathematical, relational, and logical.
- The operand and the resultant are two concepts related to the operator
- Operands are the data that the operator connects and processes.
- The resultant is the answer that results when the operation is completed. For example 5 + 7
Mathematical Operators:
+, -, /, *, \, MOD, ^
Relational Operators:
<, >, ==, !=, <=, >=
- Operands of relational operators can either be numeric or character, however, they must be of the same type.
- The resultant of relational operation is of logical data type (i.e. either True or False).
Logical Operators:
AND, OR, NOT
- Logical operators are used to connect relational expressions and to perform operations on logical data.
Operator Precedence:
- ()
- Function calls
- NOT, Unary –
- ^ (power)
- /, *, \, MOD
- +, –
- <, <=, >, >=
- ==, !=
- AND
- OR
- =
The data the computer uses are of many different types.
Computer must be told about the data type of each variable or constant.
Numeric Data
- Includes all types of numbers. The subtypes of numeric data type are Integer and Real
- Integers are whole numbers
- Real numbers or floating point numbers are whole numbers plus decimal parts
- A real number can be represented in scientific notation such as 2.5E5 or 3.2E-3. No commas are used.
Character Data
- The character data set consists of all single digit numbers, letters and special characters, available to the computer – placed within quotation marks.
- An uppercase letter is considered different from a lowercase letter.
- When more than one character is put together, the computer considers this item as a string.
- Character and string data are compared and arranged in alphabetical order.
- The computer gives each character a number (ASCII Codes). The numbers are compared to see which is larger and are then arranged in ascending order.
- Upper case letters are given a smaller value than a lowercase letter.
Logical Data
- Consists of only two values – true and false.
- They are used in making yes-or-no decisions.
- For example, to check the credit record.
Data:
- Constants and Variables
- Data
used in problem solving
Constants:
- A constant is a
specific alphabetical and/or numerical value that never changes during the
processing of all the instructions in the solution
- Constants
can be any type of data – numeric, alphabetical, etc.
- In
many programming languages and applications constants can be named
- In
this case, the constant is given a location in memory and a name
- Once
the constant is given a value, it cannot be changed during the execution of the
program, e.g., the value of PI.
- The
only way to change the value of a constant is to change the program.
- Many
name conventions stipulate that named constants be given names containing ALL
CAPITAL LETTERS in order to easily distinguish them from variables.
Variables:
- The
value of a variable may change during processing
- In
many languages variables are called identifiers since the name identifies what
the value represents
- The
programmer uses variable name as a reference name for a specific value of the
variable
- The
computer sets up a specific memory location to hold the value of each variable
name found in the program
- The variable name should be consistent
with what the value of the variable represents.
Rules for naming the variables:
- Name
the variable according to what it represents
- Do
not use spaces in the variable names
- Start
a variable name with a letter
- Do
not use hyphens or special symbols except underscore
- Be
consistent when using upper and lowercase letters
- Use
the exact variable name when referencing that variable in any part of the
program
- Use
the exact variable name when referencing that variable in any part of the
program
- Use
the naming conventions specified by the organization where you work, e.g. all
uppercase letters for constants and first uppercase letter for every word used
in variable name.