General Problem Solving Concepts
General Problem Solving Concepts
´Logical
´Problems involving relational or logical processing
´Repetitive
´Problems involving repeating a set of mathematical
and/or logical instructions.
14 Fundamental Concepts
´The building blocks of equations and
expressions
´Constants
´Variables
´Operators
´Functions (predefined—more about user-defined
functions later)
15 Constants
´A value
´a specific alphabetical and/or numeric value
´Does not change during the processing of all the
instructions in a solution
´Can be of any data type
´Numeric, alphabetical or special symbols
´Examples
´3, 5, 10, “Mulder”, “Scully”, “+”, “-”, “/”
´Note: “” indicates datum rather than variable name
16 Constants
´In some programming languages, constants can
be named
´Provides protection to the constant value and other
areas of the program.
´Cannot be changed once given initial value
´Note: no spaces allowed within names
´Examples
´ SALES_TAX_RATE = 6
Constant name are
´ COMMISSION_RATE = 6 usually in
ALL CAPS
17 Variables
´The name references the memory or storage
location where the value is stored
´May change during processing
´May be of any data type
´A name is assigned to each variable used in a
solution.
´ Examples
´ Age, LastName, Address, PayRate
18 Rules for Naming Variables
´ the name should be ´ Use appropriate naming
meaningful convention
´ Use PayRate not x or y or z ´ Be consistent!
´ Do not use spaces ´ Some languages are case sensitive
21
22 Numeric Types
´Includes all types of numbers
´Natural Numbers - The set of positive (counting) numbers
´ Ex. {1,2,3,4,5,…}
´User-defined
´ More about these later
29 Functions
´Benefits
´Reduces the amount of code that needs to be written,
thus reducing errors of repetition
´Shortens the development time
´Improves readability
30 Function Parameters
COP1000 McManus
32 Operands, Resultants
& Operators
´Operands ´Operators
´The data that the operator ´The data connectors within
connects and processes expressions and equations.
´Resultant ´Two types of operations
´The answer that results when ´Unary
the operation is executed ´ Negation
´Binary
´ Addition, Subtraction, Multiplication,
Floating Point Division and Integer
Division
33 Operator Types
´Mathematical
´+, -, *, /
´//, Mod {Integer Division & Modulo}
´^, {Exponentiation}
´Relational
´<, >, <=, >=, =, <>
´Logical
´And, Or, Not
34 The Boolean Data Type
´Perform comparisons
´Ex. If Y > Z then ...
= equal
<> not equal
< less than
> greater than
<= less than or equal to
>= greater than or equal to
36 Logical (Boolean) Operators
A= B= then A AND B
True True True
True False False
False True False
False False False
38 The OR Operator
A= B= then A OR B
True True True
True False True
False True True
False False False
39 The NOT Operator
A= NOT A
True False
False True
40 Hierarchy of Operations
´Expressions
´Process the data and the operands, through the use
of the operators
´Does not store the resultant (answer)
´Examples
´Price * SalesTaxRate
´(Hours – 40) * Wage * 1.5
´Height * Width
43
Equations
Understand requirements:
1. The given data
2. The required results
3. The processing that is required in the problem
4. A list of solution alternatives
Flowchart Symbols
Flowchart Symbols
Flowchart Symbols
Figure 3.9 Flowchart Symbols
The Algorithms and Flowcharts for the
Payroll Problem
The Algorithms and Flowcharts for the
Payroll Problem
The Algorithms and Flowcharts for the
Payroll Problem
The Algorithms and Flowcharts for the
Payroll Problem
Order of Execution of Instructions
Problem Analysis Chart
Problem Analysis Chart for the Payroll
Problem
The IPO(input-processing-output) Chart
The IPO Chart for the Payroll Problem