47
March 22, 2022 1 Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 1 Introduction to Computers and Programming

Covenant College October 13, 20151 Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 1 Introduction to Computers and Programming

Embed Size (px)

Citation preview

April 19, 2023 1

Laura Broussard, Ph.D.

Professor

COS 131: Computing for Engineers

Chapter 1

Introduction to Computers and Programming

April 19, 2023 2

Solid Start to COS131

• Use Syllabus!- Course Content- Requirements

• Questions?

Ch 1: Intro to Computers & Prog…

I. Background

II. History of Computer Architecture

III. Computing Systems Today

IV.Executing a MATLAB Program

V. Problem Solving

April 19, 2023 3

April 19, 2023 4

I. Background

• Advances in technology need 2 things:

– A visionary with a new idea

– Engineers who find or invent tools to make

it a reality.

April 19, 2023 5

I. Background

• Pace of change increasing

• Computer science!

• COS131 teaches the basics of computer programming using the programming language: MATLAB

April 19, 2023 6

I. Background

• Learning a programming language is like learning a foreign language.

• For a foreign language, you master:– Vocabulary (words)– Grammar (sentences, paragraphs)– Practice, practice, practice!

April 19, 2023 7

I. Background• Learning a programming language is like learning a

foreign language.

Foreign language Programming Language

Vocabulary Terminology, Key Words

Grammar Syntax of Commands

Practice Write Programs!

Ch 1: Intro to Computers & Prog…

I. Background

II. History of Computer Architecture

III. Computing Systems Today

IV.Executing a MATLAB Program

V. Problem Solving

April 19, 2023 8

April 19, 2023 9

II. A Brief History of Computing

• Three important “events” that define modern computing (Smith):

– The Difference Engine (1854)

– Colossus (1942-45)

– Von Neumann architecture (1945)

II. A Brief History of Computing

Charles Babbage, (1791-1871)

Cambridge University

Mathematician

Philosopher

Inventor

Mechanical Engineer

• Specific problem: Human calculation of log and trig tables gave too many errors.

• Babbage designed the Difference Engine to do accurate calculations

• The first computer– Decimal, programmable, mechanical

– Babbage didn’t build it (lack of funds)

• Babbage: a “father” of the computer

• Ada Lovelace: the first programmer

April 19, 2023 10

The Difference Engine - 1854

April 19, 2023 11

II. A Brief History of ComputingThe Difference Engine - 1854

Babbage’s Difference EngineScience Museum of London 1991 Implementation

• Babbage never built his DE

• 1991 - SM of L built one to original spec’s

• It worked!

April 19, 2023 12

II. A Brief History of Computing

The ColossiComputers - WW II

Max NewmanMathematician

Government Code & Cypher SchoolBletchley Park

Tommy FlowersEngineer

Post Office Research StationDoris HillSpecific Problem: In WWII, German U-boats

severely disrupted British shipping. Gt Britain needed to break German’s coded communications. Could do it, but too slow.

April 19, 2023 13

II. A Brief History of Computing

• Tommy Flowers & others addressed the speed issue by redesigning the method of inputting data (redesigned computer, too)

• Colossi: first computers to be– Electronic– Digital– Programmable

• Colossi solved it!

The Colossi Computers - WWII

A Colossus Mark 2 computer. (All Colossi used during World War II

were destroyed by 1961.)

http

://it-

scie

nce.

net/i

mag

es/s

hann

on.s

mal

l.jpg

14

II. A Brief History of ComputingModern Computer Architecture

Claude Shannon (1916-2001)

Mathematician,Electronic Engineer, &

Cryptologist

Two key ideas: 1.) Binary Encoding

MIT Master’s Thesis, 1937

Boolean Algebra: “1” or “0”An electrical application resolvesany logical/numerical problem

Foundation of:Digital circuit design theory & the digital computer

April 19, 2023 15

II. A Brief History of ComputingModern Computer Architecture

John Von Neumann(1903-1957)

Mathematician, polymath

Two key ideas: 1.) Binary Encoding 2.) “Von Neumann

Architecture

• Proposed* separating the CPU from the computer memory and the I/O devices.

• Allowed computers to solve amazing range of different problems

* “First Draft of a Report on the EDVAC” (June, 1945). His collaborators: J.P. Eckert &J. Mauchly wrote about it in 1943

April 19, 2023 16

II. A Brief History of Computing

• Same model since 1940’s inception

• Modern architecture separates: Central Processing Unit (CPU) Computer Memory Input/Output (I/O) devices.

• Binary Coding (1’s and 0’s).

Modern Computer Architecture

Ch 1: Intro to Computers & Prog…

I. Background

II. History of Computer Architecture

III. Computing Systems Today

IV.Executing a MATLAB Program

V. Problem Solving

April 19, 2023 17

April 19, 2023 18

III. Computing Systems Today

• Combination of hardware and software that solves problems

– Hardware – physical electronic equipment

– Software – the programs that describe the steps or instructions the computer hardware performs.

• Survey these topics:A. Hardware C. Computer ConfigurationsB. Memory D. Software

April 19, 2023 19

III. Computing Systems TodayA. Computer Hardware

All computers have a similar internal organization:

April 19, 2023 20

III. Computing Systems TodayA. Computer Hardware (cont’d.)

– CPU (Central Processing Unit) has 2 parts:• Control Unit – manages the flow of data between modules• Arithmetic and Logic Unit (ALU) – performs arithmetic and logical operations

required by the software

– Data (information) handled by a computer is an important figure of merit

bit (from binary digit) is the basic amount* Smallest components of computer hold 1 bit of data – Binary Operation Bit value is 1 for 5 volts (on) (Today – it’s 3.5 volts.) Bit value is 0 for 0 volts (off)(* Coined by statistician John W. Tukey at Princeton University)

1 byte = 8 bits Size of ASCII character using preassigned binary code.

A word is a set of data consisting of 16, 32, 64, or more bits. A computer that handles 64-bit words can deal with more data at once than a 32-bit machine it’s faster.⇒

April 19, 2023 21

III. Computing Systems TodayA. Computer Hardware (cont’d.)

– Input and output (I/O) is done by moving data between the CPU and outside devices (users, other computers) Input – data and instructions coming in Output – the results coming from the computations made by the computer

– Data buses – an electronic “pathway” for transporting data between devices Multiple devices sending & receiving data on bus require a protocol to maintain order Today, devices “plug in” to the data bus (push in by hand) In old days, “hard-wire” in (solder)

April 19, 2023 22

III. Computing Systems TodayA. Computer Hardware

Fig. 1.5 Greater detail of internal computer organization

April 19, 2023 23

III. Computing Systems TodayB. Memory•One way to think about it: its form & how it is accessed solid state memory modules

• solid state circuitry directly connected to CPU• digital addresses to store data

mechanical memory• devices that moved a sensor past storage media like hard drives, optical disks (CDs, DVDs), etc• externally connected to I/O

•Primary or main memory is solid state and its addresses are directly accessible by the CPU. Fast and expensive•Secondary memory or storage is typically mechanical. Slower but greater capacity

April 19, 2023 24

III. Computing Systems TodayB. Memory

•Chart of memory sizes:

April 19, 2023 25

III. Computing Systems TodayB. Memory: more terminology

Note: Memory can have two meanings:1. Physical device that stores data2. The stored data

– Read Only Memory (ROM) – data that is permanent (semi-permanent?) or a device that holds such data

– BIOS (Basic Input/Output System) – a specialized form of ROM holding just enough instructions to get computer going

– Random Access Memory or RAM (primary memory) – the directly accessible high speed memory used to store the computer programs (instructions). Never enough of this

April 19, 2023 26

III. Computing Systems TodayB. Memory: more terms

– Cache – a small amount of fast memory used to store frequently-used data. Strategic use of cache memory improves performance.

– Virtual Memory – a data file on hard drive containing an image of everything you would like to have in RAM divided into pages. If the desired data is not in RAM, computer has to swap out for it, resulting in loss of performance

– Etcetera – An alphabet soup of more memory types and variations

April 19, 2023 27

III. Computing Systems TodayB. Memory A typical memory layout:

Stack – memory space given to programs to store local static data

Heap – remainder of RAM, accessible to all programs upon request

April 19, 2023 28

Computing Systems TodayC. Computer Configurations

– Embedded computers (special-purpose processors) – computers performing a single or very limited set of tasks repetitively; built into other equipment

– Personal computers (PC’s)– small, general purpose computer that run variety of programs

– Mainframes – large scale, powerful computers used in major business and research applications

– Supercomputers – ultra-large, fast computers used for very complex computing problems

April 19, 2023 29

III. Computing Systems TodayD. Software

– Contains the instructions the CPU uses to run programs

– Categories of software:• Operating systems (OS)• Applications• Language compilers & Programming Languages

– Relationship of hardware, software, & user (next slide)

April 19, 2023 30

III. Computing Systems TodayD. Software

April 19, 2023 31

III. Computing Systems TodayD. Software

– Operating Systems (OS) – manages the computer system as a whole. 3 OS’s used today

• UNIX (Linux, Redhat, Sun Solaris)• Windows (XP, Vista)• Macintosh (OS X)• Special purpose operating systemsUtilities – group of programs in the OS that perform special

functions such as virus protection, defragmentation, backup, etc.

– Drivers – small programs stored in main memory to support communication between external world and internal application programs via the CPU

April 19, 2023 32

III. Computing Systems TodayD. Software Applications / Software Tools: commercial

programs written to do a specific job

– Word processors (MS Word)

– Desktop publishing

– Spreadsheets (MS Excel, Lotus 1-2-3)

– Database Management (MS Access, Oracle)

– Computer-aided Design (CAD) – (Auto Cad)

Where does MATLAB fit?

April 19, 2023 33

III. Computing Systems TodayD. Software – Programming Language & Language Compiler: a software tool a programmer uses to express the logic for a computer to implement enables user to write a custom software tool

Examples: MATLAB, JAVA, C, FORTRAN, BASIC, …

Attributes of a programming language:– Power of the language (the scope of the logic in a line)– User-friendly (clarity to humans)– Portability (run on different types of computers)

April 19, 2023 34

III. Computing Systems TodayD. Software

– One way to “categorize” programming languages:

– Machine Language – most basic programming language, strings of 0’s and 1’s, tied closely to the CPU ,very hard to comprehend First Generation Language

– Assembly Language – next most basic language, one line of symbolic code yields one machine instruction, tied to CPU, difficult to comprehend Second Generation Language

– High-Level Languages – complex, one line of code yields many machine instructions, somewhat portable between processors

April 19, 2023 35

III. Computing Systems TodayD. Computer Software

•Another way to “categorize” – generation

– First Generation – machine language – Second Generation – assembly language – Third Generation – high level languages such as C, Basic, Fortran, Cobol, etc. – Fourth Generation – languages where the programming develops a diagram of the desired logic and steps and the language translates the diagram into a set of instructions for the computer to execute – Fifth Generation – natural languages; using the syntax of natural speech

D. Software The higher the language level closer the syntax to human⇒ speech

Machine language First Generation

Assembly language Second Generation

High-Level / Partially portable Third Generation C, FORTRAN, BASIC

High-Level / Completely portable Fourth Generation Ada, Java

MATLAB, Mathematica, Mathcad, Maple

Next-Level Fifth Generation IBM’s Watson?

April 19, 2023 36

III. Computing Systems Today

April 19, 2023 37

III. Computing Systems Today

The ASCII BinaryAssignment Matrix

D. Software

Ch 1: Intro to Computers & Prog…

I. Background

II. History of Computer Architecture

III. Computing Systems Today

IV.Executing a MATLAB Program

V. Problem Solving

April 19, 2023 38

April 19, 2023 39

IV. Executing a MATLAB Program

Flow diagram for executing a standard computing task

Compile and Assemble are similar operations: Compile takes a high-level language and translates to assembly or machine language. Assemble takes assembly language to machine language.

April 19, 2023 40

Steps for executing a standard computer program:– 1: Programmer writes set of instructions in target language (source code or program)– 2: Source Code is submitted to compiler that translates instructions into machine language (1’s and 0’s) (object code)– 3: Correct errors generated in Step 2 - compile (compile) time errors or bugs. Correcting errors is debugging.– 4: Searching all subprograms from libraries and collecting in one executable program is linking.– 5: A loader copies executable program into memory and ready for execution – unless new errors (execution,

runtime, logic errors or program bugs).

IV. Executing a MATLAB Program

April 19, 2023 41

IV. Excecuting a MATLAB Program

•MATLAB is an interpreted language – no compiler for translating instructions into machine code.

•MATLAB has interactive environment and can process – single instructions (calculator) or – sets of instructions called scripts, call m-files.

Executing a standard computer program:

Ch 1: Intro to Computers & Prog…

I. Background

II. History of Computer Architecture

III. Computing Systems Today

IV.Executing a MATLAB Program

V. Problem Solving

April 19, 2023 42

April 19, 2023 43

V. Problem Solving

• Strategy for computer problem-solving is to break the problem down into a series of subproblems (divide and conquer).

– State refers to the collection of data handed off from one subproblem solution to another.

• Strategy – work from both ends, the start and finish:

Two-pronged approach shown below:

April 19, 2023 44

V. Problem Solving

• Problem solving is the process of designing a solution for a problem.

• A skill mastered by experience – an “art”

• A general problem-solving technique:

1.) Understand the problem

2.) Devise a plan

3.) Carry out the plan, checking each step along the way.

4.) Look back and examine the solution. How to Solve It,

George Polya (mathematician)

April 19, 2023 45

Problem Solving - Example• For example, say you have a big collection of baseball cards and you want to find the names of the 10 “qualified” players with the highest lifetime batting averages. • To qualify, the players must have been in the league at least 5 years, had at least 100 plate appearances per year, and made fewer than 10 errors per year.

• The cards contain all the relevant information for each player. You just have to organize the cards to solve the problem.

April 19, 2023 46

Problem Solving - ExampleClearly there are a number of steps between the stack of cards and the

solution. In no particular order these are:

a. Write down the names of the players from some cards

b. Sort the stack of cards by the lifetime batting average

c. Select all players from the stack with 5 years or more in the league

d. Select all players from the stack with fewer than 10 errors per year

e. Select all players from the stack with over 100 plate appearances per year

f. Keep the first 10 players from the stack

April 19, 2023 47

Problem Solving - ExampleThe solution might be:

c. Select all players from the stack with 5 years or more in the league

d. Select all players from the stack with fewer than 10 errors per year

e. Select all players from the stack with over 100 plate appearances per year

b. Sort the stack of cards by the lifetime batting average

f. Keep the first 10 players from the stack

a. Write down the names of the players from these cards

In anyorder