lecture1 introduction to computers and programming language

46
LECTURE 1 1 BITG 1113: Introduction To Computers And Programming Language LECTURE 1

Upload: ryan-ong

Post on 15-Nov-2014

118 views

Category:

Documents


2 download

DESCRIPTION

this is the basic of computer knowledge. please vote me.

TRANSCRIPT

Page 1: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 1

BITG 1113:

Introduction To Computers And Programming Language

LECTURE 1

Page 2: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 2

In this chapter, you will: • Learn about different types of computers • Explore the hardware and software components

of a computer system • Learn about the language of a computer • Learn about the evolution of programming

languages • Examine high-level programming languages

Objectives

Page 3: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 3

Objectives (cont.)

• Discover what a compiler is and what it does • Examine a C++ program • Explore how a C++ program is processed • Become aware of Standard C++ and ANSI/ISO

Standard C++

Page 4: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 4

Why Program?

• Computer – programmable machine designed to follow 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 programs; without programs, a computer cannot do anything

Page 5: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 5

Categories of Computers

• Mainframe computers

• Midsize computers

• Micro computers (personal computers)

Page 6: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 6

Computer is an electronic device, with two major components.

Computer

Hardware Software

Computer Components

Page 7: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 7

Main Hardware Component Categories:

1. Central Processing Unit (CPU)

2. Main Memory

3. Secondary Memory / Storage

4. Input Devices

5. Output Devices

Page 8: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 8

Main Hardware Component Categories

Page 9: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 9

Central Processing Unit (CPU)

Comprised of:– Control Unit

• Retrieves and decodes program instructions• Coordinates activities of all other parts of computer

– Arithmetic & Logic Unit• Hardware optimized for high-speed numeric

calculation• Hardware designed for true/false, yes/no decisions

Page 10: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 10

CPU Organization

Page 11: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 11

Main Memory

• It is volatile. Main memory is erased when program terminates or computer is turned off

• Also called Random Access Memory (RAM)

• Organized as follows:– bit: smallest piece of memory. Has values 0 (off,

false) or 1 (on, true)– byte: 8 consecutive bits. Bytes have addresses.

Page 12: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 12

Main Memory

• Addresses – Each byte in memory is identified by a unique number known as an address.

The number 149 is stored in the byte with the address 16, and the number 72 is stored at address 23.

Page 13: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 13

Main memory with some data

Main Memory

Page 14: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 14

Secondary Storage

• Non-volatile: data retained when program is not running or computer is turned off

• Comes in a variety of media:– magnetic: floppy disk, zip disk, hard drive– optical: CD-ROM– Flash drives, connected to the USB port

Page 15: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 15

Input Devices

• Devices that send information to the computer from outside

• Many devices can provide input:– Keyboard, mouse, scanner, digital camera,

microphone– Disk drives and CD-ROM (Secondary

storage)

Page 16: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 16

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 and printer– Floppy, zip disk drives, writable CD drives

(Secondary storage)

Page 17: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 17

Computer Software•Software: programs that do specific tasks.

• Software is divided into 2 categories

Software

System Software Application Software

Page 18: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 18

System Software• Related software that manages the system’s resources

and control the operations of the hardware.

• Normally supplied by the manufacturer of the computer.

• Consists of utility programs and operating aids that facilitate the use and performance of the computer.

• System programs take control of the computer, such as an operating system.

• Operating system are programs that manage the computer hardware and the programs that run on them. Examples: Windows, UNIX, Linux.

Page 19: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 19

Application Software• Programs that provide services to the user. • Designed to perform a specific task (such as

course registration or banking) OR a general-purpose task (such as word processing, eg. Ms Word).

• May be acquired by purchasing off-the-shelf or by designing for own purpose (custome made).

• Off-the-shelf : prewritten and ready to use.

• Custom made : written by in-house, consulting firm or software house.

Page 20: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 20

Where are the application and system software?

Page 21: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 21

Computing Environment

Personal Computing

Time-Sharing

Client / Server Computing

Internet Computing

Page 22: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 22

Personal computing environment

Page 23: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 23

Time-sharing environment

Page 24: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 24

The client/server environment

Page 25: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 25

• Digital signals are sequences of 0s and 1s • Machine language: language of a

computer • Binary digit (bit):

– The digit 0 or 1

• Binary code: – A sequence of 0s and 1s

• Byte: – A sequence of eight bits

The Language of a Computer

Page 26: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 26

Page 27: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 27

Coding Schemes

• ASCII (American Standard Code for Information Interchange) – 128 characters – A is encoded as 1000001 (66th character) – 3 is encoded as 0110011

Page 28: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 28

Coding Schemes (cont.)

• EBCDIC – Used by IBM – 256 characters

• Unicode – 65536 characters – Two bytes are needed to store a character

Page 29: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 29

History Of Computer Languages

Computer language evolution

The only language understood by a computer is machine language

Page 30: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 30

1.Machine Language

• Computer only understand this language.• Series of 1’s and 0’s (binary numbers), such as

1011010000000101• Difficult to write.• Low level language

History Of Computer Languages (cont.)

Page 31: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 31

• Early computers were programmed in machine language

• To calculate wages = rates * hours in machine language: 100100 010001 //Load

100110 010010 //Multiply

100010 010011 //Store

History Of Computer Languages (cont.)

Page 32: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 32

2. Symbolic/Assembly Language • Unique to particular computer.• Use mnemonics symbols. E.g. “MUL” –Multiply• Easier to understand.

History Of Computer Languages (cont.)

Page 33: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 33

• Using assembly language instructions, wages = rates • hours

can be written as:

LOAD rate

MULT hour

STOR wages

History Of Computer Languages (cont.)

Page 34: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 34

3. High-Level Language• Portable to many different computers.• Instruction are coded • Eg. COBOL (Business), FORTRAN (Scientific), BASIC,

Pascal, C, C++, C#, Java etc.• Programmers use this to write programs.• Compiler: translates a program written in a high-level

language machine language • The equation wages = rate x hours can be written

in C++ as: wages = rate * hours;

History Of Computer Languages (cont.)

Page 35: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 35

4. Natural Language

• Like our natural language (such as English, French, or Chinese)

• Its use is still quite limited.

History Of Computer Languages (cont.)

Page 36: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 36

Programs and Programming Languages

• Types of languages:

– High-level: closer to human language

– Low-level: used for communication with computer hardware directly. Often written in binary machine code (0’s/1’s) directly.

Page 37: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 37

Some Well-Known High-Level Programming Languages

Page 38: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 38

#include <iostream> using namespace std; int main() { cout << "My first C++ program." << endl; cout << "The sum of 2 and 3 = " << 5 << endl; cout << "7 + 8 = " << 7 + 8 << endl; return 0; } Sample Run: My first C++ program. The sum of 2 and 3 = 5 7 + 8 = 15

Example of a C++ Program

Page 39: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 39

Program Development• A computer understands a program only if

the program is coded in its machine language.

• Programmer have to write the program and turn it into an executable (machine language) code.

• Programmer have to understand the problem -> break into actions-> execute by the computer.

Page 40: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 40

From a High-level Program to an Executable Code

• There are 4 steps in the process : a) Create and edit file containing the program with a text editor.b) Run preprocessor to process the preprocessor directives (begin with

#)c) Run compiler to:

• Check that the program obeys the rules • Translate into machine language (object code)

d) Run linker to connect hardware-specific code to machine instructions, producing an executable code.

• Steps b–d are often performed by a single command or button click.• Errors detected at any step will prevent execution of following steps.

Page 41: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 41Executable Code

Code

Code

Programmer

From a High-level Program to an Executable Code

Page 42: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 42

Loader: – Loads executable code/program into main

memory

Execution:– The last step is to execute the program

Program Development (cont.)

Page 43: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 43

Page 44: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 44

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.

• Examples are Microsoft Visual C++, Borland C++ Builder, CodeWarrior, etc.

Page 45: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 45

Integrated Development Environments (IDEs)

Page 46: Lecture1 Introduction to Computers and Programming Language

LECTURE 1 46

ANSI/ISO Standard C++

• C++ evolved from C

• C++ designed by Bjarne Stroustrup at Bell Laboratories in early 1980s

• C++ programs were not always portable from one compiler to another

• In mid-1998, ANSI/ISO C++ language standards were approved