47
Beginning Problem- Solving Concepts for the Computer Problem Solving and Programming Concepts by Sprankle and Hubbard

Problem Solving With Computers

Embed Size (px)

DESCRIPTION

Problem Solving With Computers

Citation preview

Page 1: Problem Solving With Computers

Beginning Problem-Solving Concepts for the ComputerProblem Solving and Programming Concepts by Sprankle and Hubbard

Page 2: Problem Solving With Computers

Overview

Constants and Variables

Data Types

How the Computer Stores Data

Functions

Operators

Expressions and EquationsBullet, etc

Page 3: Problem Solving With Computers

Objectives1. Differentiate between variables, constants.

2. Differentiate between character, numeric, and logical data types.

3. Identify operators, operands, resultants.

5. Identify, use functions

6. Identify, use operators according to placement in hierarchy chart.

7. Set up, evaluate expressions and equations using variables, constants, operators, and the hierarchy of operations.

Page 4: Problem Solving With Computers

Important Concepts to Learn

Page 5: Problem Solving With Computers

Constant

A specific alphabetical and/or numeric value that never changes during the processing of all the instructions in a solution.

Constants can be any type of data—numeric, alphabetical, or special symbols.

Page 6: Problem Solving With Computers

Variable

Value that can change Called as Identifiers in many languages The programmer uses a 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 a program

Page 7: Problem Solving With Computers
Page 8: Problem Solving With Computers

Rules for Naming and Using Variables Name a variable according to what it

represents Hours for hours worked PayRate for rate of pay

Do not use spaces in a variable name use HoursWorked instead of Hours Worked;

Start a variable name with a letter;

Page 9: Problem Solving With Computers

Rules for Naming and Using Variables Do not use a dash (or any other symbol that is

used as a mathematical operator) in a variable name. The computer will recognize these symbols as

mathematical operators, turn your variable into two or more variables, and treat your variable as a mathematical expression;

After you have introduced a variable name that represents a specific data item, this exact variable name must be used in all places where the data item is used;

Page 10: Problem Solving With Computers

Rules for Naming and Using Variables Be consistent when using upper- and lower-

case characters. In some languages HOURS is a different

variable name than Hours;

Use the naming convention specified by the company where you work.

Page 11: Problem Solving With Computers
Page 12: Problem Solving With Computers

Data Types

Data are unorganized facts. They go into the computer as input and are processed by the program.

What is returned to the user is output, or information. This information is printed in the form of reports.

Page 13: Problem Solving With Computers
Page 14: Problem Solving With Computers

The data the computer uses are of many different types.

The most common data types are numeric, character, and logical

Data Types

Page 15: Problem Solving With Computers

Numeric Data

Numeric is the only data type that can be used in numeric calculations.

The subtypes of numeric data include integers and real numbers. Integers are whole numbers, such as 5,297 or -376.

They can be positive or negative.

Real numbers, or floating point numbers, are whole numbers with decimal parts.

Page 16: Problem Solving With Computers

Numeric Data

Each data type has a data set, the set of symbols necessary to specify a datum as a particular data type.

A data set is the set of values that are allowed in a particular data type.

The data set for the numeric data type includes all base 10 numbers, the plus sign (+) and the negative sign (-).

Page 17: Problem Solving With Computers
Page 18: Problem Solving With Computers

Character Data—Alphanumeric Data The character data set, sometimes called

alphanumeric data set, consists of all single digit numbers, letters, and special characters available to the computer.

An upper case letter is considered a different character from a lower case letter.

Characters cannot be used for calculations even if they consist of only numbers.

Page 19: Problem Solving With Computers

Character Data—Alphanumeric Data When more than one character are put

together, the computer considers this item a string

Character and string data can be compared and arranged in alphabetical order in the following way.

Page 20: Problem Solving With Computers

Character Data—Alphanumeric Data Character data or string data can be joined

together with the + operator in an operation called concatenation. aa + bb = aabb Rose + Daisy = RoseDaisy

Page 21: Problem Solving With Computers

Logical Data

Logical data consist of two values in the data set: True or False Yes or No 1 or 2

Page 22: Problem Solving With Computers

Rules for Data Types

1.The data that define the value of a variable or a constant will most commonly be one of three data types: numeric, character, or logical.

2.The programmer designates the data type during the programming process. The computer then associates the variable name with the designated data type.

3.Data types cannot be mixed.

Page 23: Problem Solving With Computers

Rules for Data Types

4. Each of the data types uses what is called a data set.

5. Any numeric item that must be used in calculations resulting in a numeric result must be designated as numeric data type.

Page 24: Problem Solving With Computers
Page 25: Problem Solving With Computers

Functions

small sets of instructions that perform specific tasks and return values.

used as parts of instructions in a solution.

FunctionName(data)

Page 26: Problem Solving With Computers

Functions

Functions use data. The data is listed as part of the function and are called parameters.

Examples: square root function, Sqrt(N) The maximum function, Max(N1, N2,N3)

Page 27: Problem Solving With Computers

Classes of Functions

1. Mathematical functions. Often used in science and business, mathematical functions calculate such things as square root, absolute value, or a random number.

2. String functions. These are used to manipulate string variables.

3. Conversion functions. These functions are used to convert data from one data type to another.

Page 28: Problem Solving With Computers

Classes of Functions

4. Statistical functions. These functions are used to calculate things such as maximum values, minimum values, and so forth.

5. Utility functions. This class is very important in business programming because most reports require some use of utility functions.

Page 29: Problem Solving With Computers

Mathematical Function

Page 30: Problem Solving With Computers

String Function

Page 31: Problem Solving With Computers
Page 32: Problem Solving With Computers
Page 33: Problem Solving With Computers

Operators

Operators are the data connectors within expressions and equations.

They tell the computer how to process the data. Operands and Resultant

Operands are the data that the operator connects and processes.

The resultant is the answer that results when the operation is completed.

Page 34: Problem Solving With Computers

Mathematical operators

Include addition, subtraction, multiplication, division, integer division, modulo division, powers, and functions Integer Division - the resultant is the whole number

in the quotient. Modulo Division - the resultant is the whole number

remainder.

Page 35: Problem Solving With Computers

Operators and Their Computer Symbols

Page 36: Problem Solving With Computers

Relational operators

include the following: equal to, less than, greater than, less than or equal to, greater than or equal to, and not equal to.

A programmer uses relational operators to program decisions.

The resultant of a relational operation is logical data type True or False.

Relational operators are also used to control repetitive instructions called loops.

Page 37: Problem Solving With Computers

Operators and Their Computer Symbols

Page 38: Problem Solving With Computers

Logical operators

Logical operators are used to connect relational expressions (decision-making expressions) and to perform operations on logical data.

Page 39: Problem Solving With Computers

Logical operators

Page 40: Problem Solving With Computers

Logical operators

Page 41: Problem Solving With Computers

Operators and Their Computer Symbols

Page 42: Problem Solving With Computers

Expressions and Equations

An expression processes data, the operands, through the use of operators.

Length * Width

An equation stores the resultant of an expression in a memory location in the computer through the equal sign.

Area = Length * Width

Page 43: Problem Solving With Computers

Expressions and Equations

Page 44: Problem Solving With Computers

Evaluating a Mathematical Expression

5 * (X + Y) - 4 * Y>(Z + 6)

Where:

X = 2 Y = 3 Z = 6

Page 45: Problem Solving With Computers

Evaluating a Relational Expression

Page 46: Problem Solving With Computers

Evaluating a Logical Expression

Page 47: Problem Solving With Computers

Evaluating an Equation That Uses BothRelational and Logical Operators