Top Banner
Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators have been relatively commonplace since late 19 th century What is a computer? A mechanical or electronic device Stores, retrieves, manipulates large amounts of data (information) at high speed, with great accuracy Does not need human intervention Carries out instructions from a program
62

Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Dec 27, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Calculators are used to increase speed and accuracy of numerical computations

The abacus has roots dating back over 5,000 years

Mechanical calculators have been relatively commonplace since late 19th century

What is a computer?A mechanical or electronic device

Stores, retrieves, manipulates large amounts of data (information) at high speed, with great accuracy

Does not need human intervention

Carries out instructions from a program

Page 2: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Early Computers– 1945 – 1950’s: First generation computers

• used vacuum tubes to do internal switching needed for computations

• 1955: about 300 computers in the world built mostly by IBM and Remington Rand, based on vacuum tubes.

– Late 1950s: invention of the transistor was one of most important inventions of 20th Century

• computers based on the transistor are the first solid-state computers.

– Early 1960’s: DEC created the minicomputer (Servers) – about the size of a file cabinet.

• Used small packages of transistors called integrated circuits

– Mainframes, such as the IBM 360 are prominent in large companies and Universities.

Page 3: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

The Personal Computer– 1970s: The personal computer becomes

available with invention of the microchip– 1974: The microchip, along with the invention

of the microprocessor led to creation of first personal computer

– Bill Gates and Paul Allen founded Microsoft Corporation

– Stephen Wozniak and Steven Jobs founded Apple Computer, Inc.

Page 4: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Computers Today

• Currently:– PCs: 95% use Microsoft Windows operating

system with a huge array of available software– Minicomputers (servers) are still popular with

small business and universities.– Mainframes are in use at large corporations.– Supercomputers are very powerful and

specialized • Used for massive computing problems by big

corporations and government departments.

Page 5: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Components and Operations• Hardware: equipment, or devices

• Software: programs that contain instructions which tell the computer what to do – created by programmers

• Hardware and software: the two major

• components of any computer system

• Major operations in a computer:– Input– Processing– Output

Page 6: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Input devices: allow data to enter the computer– Mouse, keyboard, scanner

• Output devices: allow processed data to be exported out of the computer– Printer, monitor, speakers

• Processing: working on the data; such as:– Organizing data – Checking data for accuracy – Mathematical or other manipulations on data

• Central Processing Unit (CPU): hardware that performs the tasks

Page 7: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Programming language: • Special language (like French or German)

• Understood by the computer

• Tells the computer what to do

• Used by a programmer to write a program– Visual Basic, Java, C#, C++, COBOL

• Machine language: • Language of the computer

• Every “Programmer” language is converted to machine language

• Consists of bits on or off only

• Compiler or interpreter: • Software that translates programming languages to machine

language

Page 8: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Components of a computer

– Central Processing Unit (CPU)

– Internal memory• RAM (Random Access Memory)• ROM (Read Only Memory)

– Mass storage devices• Magnetic, optical, and solid-state

– Input devices such as keyboard and mouse– Output devices such as monitor and printer

Page 9: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Central Processing Unit (CPU)

• Often called the brain of the computer– Carries out program instructions ( in memory)– Performs arithmetic and logical operations

Arithmetic Logical Unit (ALU)– Controls other computer components

(operating system)

• Consists of millions of transistors on a single microchip that plug into the motherboard

Page 10: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Internal Memory

• ROM: read-only memory– Contains instructions used by computer

during startup– Cannot be altered by computer user

• RAM: random-access memory– Is a “scratch pad” for user as he or she works– Can be read from and written to– Operating System/Applications reside

Page 11: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Storage categories: internal and external

• Internal storage: – Main memory, random access memory (RAM)– Located inside the computer system– Volatile: contents are lost when power goes

down

• External storage:– Persistent: contents are relatively permanent– Floppy drive, hard drive, flash media, magnetic

tape– Located outside the computer system

Page 12: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Mass Storage Devices

• Magnetic storage– Hard disks, floppy disks, zip drives– Hard disks are internal, others are external

• Optical storage– CDs and DVDs

• Solid-state storage– Flash drives plug into a USB port

Page 13: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Software• System Software

– Control system resources– Operating systems – Windows, DOS, Linux, UNIX, dll,

utilities, drivers

• Application Software – Interract with a user– Word Processors (MS Word)– Database Managers (Access)– Spreadsheets (Excel)– Photo Editors– Web browsers, email programs (Netscape)

Page 14: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

What is Programming?

• A program is a list of instructions that is executed by a computer to accomplish a particular task.

• Creating those instructions is programming by a programmer

Page 15: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Coding the program:– Select the programming language– Write the instructions

• Using software to translate the program into machine language:– Programmers write instructions in English-like

high-level languages– Compilers or interpreters change the programs

into low-level machine language that can be executed

– Syntax errors are identified by the compiler or interpreter

Page 16: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Programming Languages– Machine Languages

• 0110110111110111 0000000100000000 0000000100000000

– Assembly Languages• One programmer instruction converted to 1 machine level

instruction• ADD A,B

– High-level Languages• Looks more like English words and algebraic expressions• Examples of high level languages• Programmer instruction converted to many machine level

» ADA BASIC

» C++ FORTRAN

» COBOL Java

» Pascal Visual Basic

Page 17: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Programmer written computer code

Translator (Interpreter) Program

(browser)

Compiler Assembler

Many machine Language Instructions

One Machine Language Instruction

Execute

.exe file

Programmer written computer code

Execute

FUNCTIONBrowsersnetscapeMS ExplorerJavascriptPHPASP

MS Word, Windows XP, MS Excel, Vista, MS Explorer

Machine Language Generation

Page 18: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Writing Programs

• To write a program in a high-level language, you need:– Appropriate software– A text editor to type and edit program

statements– A debugger to help find errors in program

code– A compiler or interpreter to translate the

program into machine language

Page 19: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Error Types

• Logic errors are more difficult to locate than syntax errors

Syntax: the rules governing word usage and punctuation in the language(format, recipe, formula)

Page 20: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• A program must be free of syntax errors to be run, or executed, on a computer

• The program will not compile or be translated• A message will point out the offending instruction

• To function properly, the logic must be correct

• The program will still execute• The output may be incorrect• The program may exit prematurely• The program may ABEND (Abnormal Termination)• The program may execute with no errors/problems

Page 21: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Logic

• A program must be free of syntax errors to be run, or executed, on a computer

• To function properly, the logic must be correct• What’s wrong with this logic for making a cake?

Page 22: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Programming Process

• Seven programming phases:– Define the Problem– Outline the Solution– Develop the Outline into an Algorithm– Test the Algorithm for Correctness– Code the Algorithm in a specific language– Run the program on the computer– Document and maintain the program

Page 23: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Define the Problem: – May be the most difficult phase– Users may not be able to articulate their needs

well– User needs may be changing frequently– Programmers may have to learn the user’s

functional job tasks– Failure to understand the problem is the major

cause of most project failures– If this is not correct – the rest of the

project cannot be correct

Page 24: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Outline the Solution:– Plan the high-order steps that the program will

take– Walk through the logic before coding by desk-

checking the logic

Page 25: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Develop the Outline into an Algorithm:– Use tools such as flowcharts and pseudocode– Flowchart: a pictorial representation of the

logic steps– Pseudocode: English-like representation of the

logic

Page 26: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Test the Algorithm for Correctness:– Walk through the logic before coding by desk-

checking the logic– Make corrections to the Flowchart/Pseudocode

as needed

Page 27: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Code the algorithm in a specific language:– Select the programming language– Write the instructions

• Using software to translate the program into machine language:– Programmers write instructions in English-like high-level

languages– Compilers or interpreters change the programs into low-

level machine language that can be executed– Syntax errors are identified by the compiler or

interpreter

Page 28: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Run the program on the computer:– Test for Syntax errors (when compiling)– Test for logic errors by using selected data

Page 29: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Document and maintain the program:– Create user documentation– Create technical documentation– Create documentation library– Monitor processing and outputs

Page 30: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Syntax Error Cycle

Page 31: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Testing the program:– Execute it with sample data and check results– Identify logic errors and correct them– Choose test data carefully to exercise all branches of

the logic

• Putting the program into production– Do this after testing is complete and all known errors

have been corrected– May require coordination with other related activities

or software

Page 32: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Variable: a memory location whose contents can vary; also called an identifier

• Each programming language has it own rules for naming identifiers, including:– Legal characters– Maximum length– Use of upper or lower case

• Variable name must be a single word, but can be formed from several words– rate, interestRate, interest_rate

• Constant: value does not change– Values that do not change while the program is running– Have identifiers, and can be used like variables for calculations,

but cannot be assigned new values

• Literal: is use of data itself (ex: pi – 3.1474)

Page 33: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Data Types

• Basic data types:– Text– Numeric

• Numeric data – stored by numeric variables

• Text data – stored by string, text, or character variables –

– surrounded by “ “ (ie. “color”)

Page 34: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Types of Data• Numeric Data

– Integer data (whole numbers)• 10 25 -45 0

– Real (Floating point) data (numbers that have a decimal point)

• 23.5 -5.0

– Note: 5 and 5.0 are stored differently in a computer even though they have the same value. The first, 5 is an Integer but the second, 5.0 is a Real number.

• Character data (alphanumerics)– All the characters you can type at the keyboard– The type is String or Character

Page 35: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Numeric data types:

– Integer: whole numbers only

– Floating-point: fractional numeric values with decimal points

Page 36: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Numeric Data– Integer data (whole numbers)

• 10 25 -45 0

– Real (Floating point) data (numbers that have a decimal point)

• 23.5 -5.0

– Note: 5 and 5.0 are stored differently in a computer even though they have the same value. The first, 5 is an Integer but the second, 5.0 is a Real number.

• Character data (alphanumerics)– All the characters you can type at the keyboard– The type is String or Character

Page 37: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Concatenation

• Concatenation takes two strings and joins them to create a string result

• The concatenation operator is symbolized, in pseudocode, with a + sign

• Example: if:• String1 = “yellow” and String2 = “duckie” • then the statement:• Set MyFriend = String1 + String2 • results in: • MyFriend = “yellow duckie”

Page 38: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

– 1 bit (0 or 1)– 4 bits = nibble– 1 byte = 8 bits = 2 nibbles

• Is the storage for one character

– 1 word = 4 bytes– 1 K = 1 KB = 1 kilobyte = 1,0240 bytes = 210 bytes

• Kilo = 1,000 : 1 KB = 1,000 bytes

– 1 Meg = 1 megabyte (MB) = 1 million = 1024 KB – 1 GB = 1 gigabyte (GB) = 1024 MB = 1,000,000,000– Many people approximate to steps of 1000, not 1024

Binary Machine Language –

all data types consist of 1s and 0s

Page 39: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Data Groupings: File– Character: single symbol (letter, number,

special symbol) • “A”, “7”, “$”

– Field: group of characters forming a single data item• “Smith”

– Record: a group of related fields• Customer record containing name and

address fields

– File: a group of related records• Customer file, containing all customer records

Page 40: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Data Groupings: Database– Character: single symbol (letter, number,

special symbol) • “A”, “7”, “$”

– Field: group of characters forming a single data item

• “Smith”

– Table: a group of related fields• Customer record containing name and address fields

– Database: collection of related tables, that serve the information needs of the organization

Page 41: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Using Flowchart Symbols and Pseudocode Statements

• Flowchart: pictorial representation of the logic

• Pseudocode: English-like representation of the logic– Example:

Page 42: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Flowchart input symbol:

Page 43: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Flowchart processing symbol

Page 44: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Flowchart output symbol:

Page 45: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Flowlines: – Connect the steps – Show the sequence of statements– Have arrows to show the direction

• Terminal symbol (start/stop symbol): – Shows the start and end points of the

statements– Lozenge shape

Page 46: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Flowchart vs. Psuedocode

Page 47: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Back-pointing arrows show statements that will be repeated

Page 48: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Infinite loop: a sequence of statements that repeats forever with no escape

• Avoid infinite loops by testing for a predetermined value that means “stop processing”

• Decision: testing a value• Flowchart decision symbol: a diamond

shape, with two flowlines, one for Yes and one for No

Page 49: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Sentinel value (or dummy value)– Does not represent real data– Signal to stop– Can be used with input from files or from users

• End-of-file (EOF) marker: – Code stored in the file that marks the end of the data– Usually used instead of a sentinel value for file input

Page 50: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Flowchart connector symbol:– Marks a logic transfer to another location in the

flowchart– Transfer location can be on the same page or on

another page– On-page symbol: a circle with a number or

letter to identify the matching transfer location

– Off-page symbol: a square with a pointed bottom, containing page number and a number of letter to identify the matching transfer location

Page 51: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.
Page 52: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Assignment statement: – Assigns a value to a variable– Variable must appear on the left side, value on the

right side of the assignment operator– Right side may be an expression that will be evaluated

before storing the value in the variable

• Assignment operator: the equal sign (=) in most languages

• Variable: – Memory location: has an address and a value– Value (contents) is used for various operations

Page 53: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Arithmetic Operations

• + Addition 2 + 3 = 5

• - Subtraction 7 – 3 = 4

• * Multiplication 5 * 4 =20

• / Division 12 / 3 = 4

• ^ Exponentiation 2 ^ 3 = 8

• % Modulus 14 % 3 = 2

Page 54: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Hierarchy of Operations

• 1st: perform operations inside parentheses (from inside out if more than one)

• 2nd: perform exponentiation

• 3rd: do multiplications, divisions, and modulus from left to right (if there are more than one)

• 4th: do additions and subtractions from left to right (if there are more than one)

Page 55: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Example of Hierarchy of Operations

• 3 * (6 + 2) / 12 – (7 – 5) ^ 2 * 3 = ?

• ( ) first: = 3 * 8 / 12 – 2 ^ 2 * 3

• ^ next: = 3 * 8 / 12 – 4 * 3

• Leftmost * next: = 24 / 12 – 4 * 3

• Division next: = 2 – 4 * 3

• Multiply next: = 2 – 12

• Subtract last: = -10

Page 56: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Relational Operators• Relational operators are the symbols used

in the condition to be evaluated in If statements:

• = equal to• <> not equal to• < less than• > greater than• <= less than or equal to• >= greater than or equal to

Page 57: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Comparison vs. Assignment Operators• The equals sign (=) in this text may have two different

meanings. The difference is very significant. • As an assignment operator, the equals sign sets the

value of an expression on the right side to the variable on the left side.

• As a comparison operator, the equals sign asks the question, “Is the value of the variable on the left side the same as the value of the expression, number, or variable on the right side?”

• Many programming languages distinguish between these two operators as follows:

• a single equals sign (=) signifies the assignment operator• a double equals sign (==) signifies the comparison

operator• This is demonstrated in the examples that follow in the

next slides.

Page 58: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Logical Operators

• Logical operators are used to connect simple conditions into a more complex condition called a compound condition.

• AND OR NOT

Page 59: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Hierarchy of OperationsType Operator Order Performed

Arithmetic operations

are performed first, in order shown

( )

^

* / %

+ -

1st parentheses

2nd exponentiation

3rd: multiplication, division, modulus

4th: addition, subtraction

Relational operations

are performed second

= <> < <= > >=

All relational operators have equal precedence

Logical operations

are performed last, in the order shown

NOT

AND

OR

1st: NOT

2nd: AND

3rd: OR

Page 60: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

• Two major programming techniques:– Procedural programming– Object-oriented programming

• Procedural programming: focuses on the procedures that programmers create

• Object-oriented programming: focuses on objects that represent real-world things and their attributes and behaviors

• Both techniques employ reusable program modules

Page 61: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.

Annotate the Output

• If the output consists of numbers or any data that has no explanatory text with it, you should annotate your output – this means to add some text so the user knows what the output means.

Page 62: Calculators are used to increase speed and accuracy of numerical computations The abacus has roots dating back over 5,000 years Mechanical calculators.