Introduction to Computers and Programming

Download Report

Transcript Introduction to Computers and Programming

Introduction to Computers
and Programming
What are humankind’s
greatest inventions?
What are humankind’s
greatest inventions?






The wheel?
Fire?
Light bulb?
Disneyland?
Microscope?
Television?
The invention of the computer


1945 – Eckert & Mauchly built ENIAC
(Electronic Numerical Integrator &
Calculator) at Penn
1951 – E&M built UNIVAC I for
Remington-Rand

Which became Sperry

Which merged with Burroughs


Which became Unisys
1953 – IBM entered the market
The invention of the computer

PCs





Altair
Imsai
Apple, Atari, Commodore (in West Chester,
PA), Sinclair
Finally IBM PC (w/out windows & mouse)
MAC (w/ windows & mouse)
What is a computer?


Computers are devices for manipulating
information.
Computers operate under the control of
a changeable program.
What is a computer?
INPUT
PROCESSING
(information)
OUTPUT
(information)
MEMORY
Functional View of a Computer
Output Devices
CPU
Input Devices
Main
Memory
Secondary Memory
Hardware Basics

The central processing unit (CPU) is the
“brain” of a computer.


The CPU carries out all the basic operations
on the data.
The CPU communicates with the main
memory
Number of processors (cores)





1 – uni
2 – dual
4 – quad
…
Multi/parallel
Hardware Basics

Memory stores programs and data.



CPU can only directly access information
stored in main memory (RAM or Random
Access Memory).
Main memory is fast, but volatile, i.e. when
the power is interrupted, the contents of
memory are lost.
Secondary memory provides more
permanent storage: magnetic (hard drive,
floppy), optical (CD, DVD)
Hardware Basics

Input devices


Information is passed to the computer
through keyboards, mice, etc.
Output devices

Processed information is presented to the
user through the monitor, printer, etc.
Computer Size
ENIAC then…
ENIAC today…
Computational Power

Intel Pentium 4:



6 instructions/clock cycle
3.4 GHz = 3.4 billion clock cycles/second
ENIAC: 5000 instructions /second
What computers understand

Very very little!!


They really only know about numbers
More accurate: computers are used to
encode numbers


Voltage on wire: 1
No voltage: 0
Bits & bytes






Bit = 0 or 1
Byte = 8 bits
K (kilo) byte = 2^10 = 1024 ~= 1000
bytes
M (mega) byte = 10^6 bytes
G (giga) byte = 10^9 bytes
T (tera) byte = 10^12 bytes
Byte



Everything a computer is working with
is encoded in bytes!
JPEG pictures, Excel spreadsheets,
annoying Web pop-up adds, everything!
Using the binary number system, a byte
can be interpreted as a decimal number
Base 2 vs. base 10

Numbers in base 10


908110 = 9x103 + 0x102 + 8x101 + 1x100
10112 = ? in base 10
What is a computer program?

A detailed, step-by-step set of
instructions telling a computer what to
do.



Computational recipe
If we change the program, the
computer performs a different set of
actions or a different task.
The machine stays the same, but the
program changes!
Program Power

Software (programs) rule the hardware
(the physical machine).

The process of creating this software is
called programming.
What is Computer Science?

It is not the study of computers!
“Computers are to computer science
what telescopes are to astronomy.” –
E. Dijkstra
What is Computer Science


This question is really, “What can be
computed?”
Exploration of problem solving using
computers

Design a solution by developing an algorithm



Algorithm: step-by-step description of a process.
break down complicated problems into simple
steps that the computer can understand
Robust, time and space efficient solutions
Why learn to program?
Programming Languages

Programs are expressed in a precise,
unambiguous way using programming
languages.



Are like code to the computer
Every structure in programming language
has a precise form, called its syntax
Every structure in programming language
has a precise meaning, called its semantics.
Programming languages
Programming developments

Machine code
http://chortle.ccsu.edu/java5/Notes/chap04/ch04_4.html

Assembly Language



Easier to write, debug, and update
http://www.erg.abdn.ac.uk/users/gorry/eg2069/assembly.html
High level languages
 Strive to be machine independent
 Easier to learn and use
 1954 – FORTRAN
 1961 – COBOL
 Then ALGOL, LISP, BASIC
 1970 – Pascal
 1980’s – C
 1990’s – C++, Java
 And many, many others.
Programming Languages

Eamample of an Assembly Language
program:
Add two numbers:




Load the number from memory location
2001 into the CPU
Load the number from memory location
2002 into the CPU
Add the two numbers in the CPU
Store the result into location 2003
Programming Languages

High-level language
c=a+b
High level languges (HLL)





Not directly understood by the
computer
Humanly readable
Requires the use of a compiler
Compilers convert programs written in a
high-level language into the machine
language of some computer.
Compiler is a program


Input = code written in a HLL
Output = machine code
Let’s make it clear..

A program is a description of a process
(recipe) in a particular programming
language that achieves some task


Could be small, e.g. one that implements a
calculator
Or huge: e.g. a program that your bank
uses to track all of its accounts.
Algorithm

A description of a process apart from
any programming language



Can be implemented in any programming
language
Can be written in English,
but pseudo-code is better! between
English and a programming language
http://www.unf.edu/~broggio/cop2221/2221pseu.htm
Types of software
1.
2.
3.
OS (operating system)
Programming environment/tools
Applications
Operating Systems (OS)


An OS is a program that manages the
computer hardware (e.g. scheduling of
resources like CPU, storage, etc.)
Acts as an intermediary between the
computer user and the computer hardware.





Windows
Linux
Unix
Mac OS
Many others
Programming
environments/tools

Tools (examples)




emacs (an editor)
vi (an editor)
g++ (a compiler)
gdb (a debugger)
Programming
environments/tools

IDE’s (integrated development
environment)


Consist of: editor, compiler or interpreter,
debugger, linker
Examples: jGrasp, Ready, Visual C++,
Visual BASIC, JBuilder, and many others
Applications









Computer games
Word processors
Graphics packages
Virtual reality software
Web browsers
Presentation
Database
Spreadsheet
And many others.
Program development


Our programming language is Java.
The IDE we will use is jGrasp.



Editor is used to type in program text (it is
not a word processor; don’t use a word
processor).
Compiler (syntax errors)
Run/execute (semantic errors)
Next time

Java