Chapter 1: Introduction To Chapter 1: Introduction To: Computers and Programming

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

9/14/2012

CHAPTER 1: INTRODUCTION TO COMPUTERS AND PROGRAMMING


Lizawati Binti Mi Yusuf
Faculty of Computer Science and Information Systems (FSKSM) Department of Modeling and Industrial Computing (PPI) N28-438-03 (Level 4) 07-55 32095 [email protected]

What is a program?
Computer: programmable machine
designed to follow instructions instructions.

Program: instructions in computer


memory to make it do something.

Programmer: person who writes


instructions (programs) to make computer perform a task

SO without programmers, no SO, programmers


programs

Without programs, a computer cannot


do anything

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

Memory Holds data and programs temporarily

PROCESSING
4

9/14/2012

Central Processing Unit (CPU)


The administrative section of the computer. coordinator. It is the computers coordinator It is responsible for supervising the operation of the other
sections.

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.

Arithmetic and Logic Unit


o

Hardware designed for true/false, yes/no decisions.


- Contains the decision mechanisms that allow the computer

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

Keyboard Mouse Scanner Digital camera Microphone

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

Programs and Programming Languages


A program is a set of instructions that the computer follows to
perform a task.

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

Programs and Programming Languages


Example algorithm for calculating gross pay:
o o o o o o

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

Types of Programming Language


Machine language
The only language the computer can understand. understand o In binary machine code (0s/1s) directly.
o

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

Rather than writing programs in machine language language,


programmers use programming languages.

14

9/14/2012

Some Well-known Programming Languages

15

From A High-level Program To An Executable File


Step 1: Create file containing the program with a text editor. Step 2: Run preprocessor to convert source file directives to

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

From A High-level Program To An Executable File


Source Code p Compiler Object Code

Preprocessor

Linker

Modified Source Code

Executable Code

17

Integrated Development Environments (IDEs)


An integrated development environment, or IDE, combine all
the tools needed to write, compile, and debug a program into a single software application application. Examples are Microsoft Visual C++, Borland C++ Builder, CodeWarrior, etc.

18

9/14/2012

What is a program made of?


Common elements in programming languages:
o o o o o o

Key W d K Words Programmer-Defined Identifiers Operators Punctuation Syntax Variables

19

Sample C Code

#include <stdio.h> int main (void) { printf (Hello, world\n"); return 0; }

20

10

9/14/2012

Input, Processing and Output


Three steps that a program typically performs:
o

Gather input data G th i td t


* From keyboard * From files on disk drives

Process the input data o Display the results as output * Send it to the screen * Write to a file
o

21

Procedural and object-oriented programming

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

You might also like