problem solving with computers

Post on 12-Jan-2016

23 Views

Category:

Documents

6 Downloads

Preview:

Click to see full reader

DESCRIPTION

Problem Solving With Computers

TRANSCRIPT

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

Overview

Constants and Variables

Data Types

How the Computer Stores Data

Functions

Operators

Expressions and EquationsBullet, etc

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.

Important Concepts to Learn

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.

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

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;

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;

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.

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.

The data the computer uses are of many different types.

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

Data Types

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.

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 (-).

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.

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.

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

Logical Data

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

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.

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.

Functions

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

used as parts of instructions in a solution.

FunctionName(data)

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)

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.

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.

Mathematical Function

String Function

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.

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.

Operators and Their Computer Symbols

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.

Operators and Their Computer Symbols

Logical operators

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

Logical operators

Logical operators

Operators and Their Computer Symbols

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

Expressions and Equations

Evaluating a Mathematical Expression

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

Where:

X = 2 Y = 3 Z = 6

Evaluating a Relational Expression

Evaluating a Logical Expression

Evaluating an Equation That Uses BothRelational and Logical Operators

top related