Chapter 1: Introduction To Chapter 1: Introduction To: Computers and Programming
Chapter 1: Introduction To Chapter 1: Introduction To: Computers and Programming
Chapter 1: Introduction To Chapter 1: Introduction To: Computers and Programming
What is a program?
Computer: programmable machine
designed to follow instructions instructions.
9/14/2012
Computer Components
Computer Components
SECONDARY STRORAGE
Stores data and programs Central Processing Unit (CPU) Executes computer instructions Control Unit Arithmetic & Logic Unit (ALU)
INPUT
Sends data to the central processing i unit (CPU)
OUTPUT
Makes processed information i f ti available
PROCESSING
4
9/14/2012
Control Unit
o o
Retrieves and decodes program instructions. Coordinates activities of all other parts of computer. Hardware optimized for high-speed numeric calculation.
- Responsible for performing calculations.
Main Memory
Stores instructions and data that are to be processed by the
computer. It is volatile. Main memory is erased when program terminates or volatile computer is turned off. Also called Random Access Memory (RAM). Each byte in memory is identified by a unique number known as an address. Organized as follows:
Information is stored in bits or binary digits. Bit: Smallest piece of memory. Has values 0 (off, false) or 1 (on, true) o Byte: 8 consecutive bits. Bytes have addresses.
o o
o
6
The number 149 is stored in the byte (10010101) with the address 16, and the number 72 (01001000) is stored at address 23.
9/14/2012
Secondary Storage
It is non-volatile. Data retained when program is not running
or computer is turned off. Comes in a variety of media:
o
Magnetic disc: floppy disk, zip disk, hard drive o Optical disc: CD-ROM, DVD-ROM o Flash drives, connected to the USB port: pen drive
Input Devices
Devices that send information to the computer from outside. Many devices can provide input:
o o o o o
9/14/2012
Output Devices
Output is information sent from a computer program to the
outside world.
The output is sent to an output device Many devices can be used for output:
Computer monitor o Printer o Speaker o Plotter
o
Software
Programs that run on a computer. Categories of software:
o
Operating system: programs that manage the computer hardware and the programs that run on them. Examples: Windows, UNIX, Linux.
Application software: programs that provide services to the user user. Examples: word processing, games, programs to solve specific problems.
10
9/14/2012
Programming language: a language used to write programs We start with an algorithm, which is a set of well-defined steps. Example algorithm for calculating the average of 3 numbers:
o o o o o o
Step 1: Determine the first number; call it A Step 2: Determine the second number; call it B Step 3: D t St 3 Determine th third number; call it C i the thi d b ll Step 4: Find the sum of A,B and C; call it X Step 5: Divide X by 3; call it the RESULT Step 6: Present the RESULT
11
Step 1: Display a message on the screen asking "How many hours did you work?" Step 2: Wait for the user to enter the number of hours worked. Once the user enters a number, store it in memory. Step 3: Display a message on the screen asking "How much do you get paid per hour?" Step 4: Wait for the user to enter an hourly pay rate. Once the user enters a number, store it in memory. Step 5: Multiply the number of hours by the amount paid per hour, and store the result in memory. Step 6: Display a message on the screen that tells the amount of money earned. The message must include the result of the calculation performed in Step 5.
12
9/14/2012
Assembly language
One level above machine language. A low level language that is processor dependent. o Each CPU has its own assembly language.
o
High-level language
Closer to human language A language that language. people can read, write, and understand. o High level programming languages are not processor dependent. o A program written in a high-level language must be translated into a language that can be understood by a computer before it can be run.
o
13
Machine language
Although the previous algorithm defines the steps for
calculating the gross pay, it is not ready to be executed on the computer. The computer only executes machine language instructions. Machine language instructions are binary numbers, such as 1011010000000101
14
9/14/2012
15
source code program statements. Step 3: Run compiler to convert source program into machine instructions. Step 4: Run linker to connect hardware-specific code to machine instructions, producing an executable file.
Steps (2) to (4) are often performed by a single command or button click click. o Errors detected at any step will prevent execution of following steps.
o
16
9/14/2012
Preprocessor
Linker
Executable Code
17
18
9/14/2012
19
Sample C Code
20
10
9/14/2012
Process the input data o Display the results as output * Send it to the screen * Write to a file
o
21
Procedural programming
o o
Focus iis on the process. Procedures/functions are written to process data. Focus is on objects, which contain data and the means to manipulate the data. Messages sent to objects to perform operations.
Object-Oriented programming
o
22
11