Topic 2 - Problem Solving Concepts For The Computer
Topic 2 - Problem Solving Concepts For The Computer
Coding Processing
•
Logical – Relational or logical processing
•
Repetitive – Repeating mathematical or logical instructions
DIFFICULTIES WITH
PROBLEM SOLVING
• Some people have not been taught how to solve problems.
• Fear to make wrong decisions.
• One or more steps are completed inadequately when going through
the problem-solving process.
• Problem not defined correctly or not understood properly.
• Insufficient list of alternatives.
• Too hasty when selecting a suitable solution.
• Focus too much on details before getting the general idea in place.
• Incorrectly or haphazardly evaluate the solution.
DIFFICULTIES WITH PROBLEM
SOLVING USING COMPUTERS
• Greatest challenge: Writing the instructions
• A computer needs detailed steps to complete a task.
• Without a proper sequence of steps, a computer cannot produce
desired results.
• Remember, a computer cannot think on its own.
CONSTANTS AND
VARIABLES
• Constants
and variables are used by a computer to solve problems.
• Constant
• A specific alphabetical or numeric value that never changes during
the processing of instructions in a solution.
• Can be any type of data.
• A constant can be given a name.
• Once a constant has been assigned a value it cannot be
changed during the execution of a program.
• Example: The value of is 3.14159 and cannot be changed.
Function Classes
OPERATORS
• Operators are the data connectors within expressions and equations.
• Operators tell a computer how to process data and what type of
processing needs to be done.
• Mathematical
• Logical
• Relational
1+1=2
MATHEMATICAL
OPERATORS
• Examples:
RELATIONAL OPERATORS
• Relational operators compare two operands and make a decision.
• The resultant of relational operators is logical data: TRUE or
FALSE
LOGICAL OPERATORS
• Connect relational expressions.
• Perform operations on logical data.
• Operators: NOT, AND, OR
• Operands and resultants are both logical data.
• Example:
• Relational Operation: Object = “Pokemon” Resultant: TRUE
• Relational Operation: Color = “Yellow” Resultant: TRUE
• Relational Operation: Type = “Electric” Resultant: TRUE
• Logical Operation:
(Object = “Pokemon”) AND (Color = “Yellow” ) AND (Type
= “Electric”)
Resultant: TRUE
Summary of Logical Operations
• Find the resultants:
• 5+4
• True OR False
• 5<8
• 10<3
• “Bob” = “Brad”
• True AND False
• “Brad” <> “Billy”
HIERARCHY OF
OPERATIONS
• Note the following expression:
• 1+2/3*5>2*5+4/3
• How would you evaluate the expression?
• All operators have a hierarchy which decides which operations
take precedence (comes first).
HIERARCHY OF
OPERATIONS (CONT.)
Operator Order of Operand Data Resultant Data
Operations Type Type
1. Parenthesis ()
2. Functions
Mathematical 3. Power Numeric Numeric
4. \, Modulo (MOD) Numeric Numeric
• 1+4/2*5>2*5+18/3
ANSWER
• 1+4/2*5>2*5+18/3
• Based on hierarchy of operations:
• 4/2*5 = 10
• 2*5 = 10
• 18/3 = 6
• 1+10>10+6
• 11>16
• Resultant: FALSE
TRUTH TABLE
• A
table that shows all the possible resultants of a logical
expression.
• The number of possible resultants for n variables is .
• Example:
• NOT A OR B will have resultants.
A B NOT A NOT A OR B
TRUE TRUE FALSE TRUE
TRUE FALSE FALSE FALSE
FALSE TRUE TRUE TRUE
FALSE FALSE TRUE TRUE
EXPRESSIONS AND
EQUATIONS
• Expression
• Translate a real life situation into a mathematical equation.
• Never stores resultant data for later use.
• E.g.
Length * Width
• Equation
• Stores resultant data of an expression in a memory location.
• Also known as assignment statements, because the resultant is
assigned to a variable.
• In an equation, “=“ refers to an assignment.
• E.g.
Area = Length * Width
EXPRESSIONS AND
EQUATIONS (CONT.)
Expressions Equations
A and B are numeric, character, or string. A and B are numeric, character, or string.
The resultant is logical and is not stored. C is logical.
The resultant is stored in C.