Sie sind auf Seite 1von 49

BTKR1343

Introduction To Computers And Programming Language

LECTURE 1

Objectives
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
LECTURE 1 2

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++

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
4

Categories of Computers
Supercomputers Mainframe computers Minicomputers Microcomputers (personal computers) Mobile computers

LECTURE 1

Computer Components
Computer is an electronic device, with two major components.
Computer Hardware Software

Computer Hardware
Hardware refers to the physical parts of the computer that have mass (they can be touched) Hardware for a typical computer system include the following components

LECTURE 1

Main Hardware Component Categories:


1. 2. 3. 4. 5. Central Processing Unit (CPU) Primary Storage or Main Memory Auxiliary or Secondary Storage Input Devices Output Devices

LECTURE 1

Main Hardware Component Categories

Central Processing Unit (CPU)


Brain of the computer 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

10

CPU Organization

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.

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.
LECTURE 1 13

Memory Cells
Address Contents
0 1 2 3 4 5 6 ... 999
14

-27.2 354 0.005 -26 H RTV 001 ... X 75.62

LECTURE 1

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
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)

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)

17

Computer Software
Software: refers to a program that resides and executes electronically on the hardware. Software is divided into 2 categories

Software

System Software

Application Software
18

System Software
Related software that manages the systems 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.
19

Application Software
Programs that provide services (problem solution) 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 (custom made). Off-the-shelf : General-purpose task. Prewritten and ready to use. Custom made: Specific task. Written by in-house, consulting firm or software house.
20

Where are the application and system software?

21

Computing Environment
Personal Computing

Time-Sharing
Client / Server Computing Internet Computing
22

Personal computing environment

LECTURE 1

23

Time-sharing environment

24

The client/server environment

25

The internet environment


Server Server Internet

Clients (Browser)

26

The Language of a Computer


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
27

28

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

29

Coding Schemes (cont.)


EBCDIC
Used by IBM 256 characters

Unicode
65536 characters Two bytes are needed to store a character

30

History Of Computer Languages

Computer language evolution The only language understood by a computer is machine language
31

History Of Computer Languages (cont.)


1.Machine Language
Computer only understand this language. Series of 1s and 0s (binary numbers), such as 1011010000000101 Difficult to write. Low level language

32

History Of Computer Languages (cont.)


Early computers were programmed in machine language To calculate wages = rates * hours in machine language:
100100 010001 100110 010010 100010 010011 //Load //Multiply //Store

33

History Of Computer Languages (cont.)


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

34

History Of Computer Languages (cont.)


Using assembly language instructions, wages = rates hours can be written as: LOAD rate MULT hour STOR wages

35

History Of Computer Languages (cont.)


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;
36

History Of Computer Languages (cont.)


4. Natural Language
Like our natural language (such as English, French, or Chinese) Its use is still quite limited.

37

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 (0s/1s) directly.
38

Some Well-Known High-Level Programming Languages

39

Example of a C++ Program


#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
40

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 (write program)-> execute by the computer.

41

From a High-level Program to an Executable Code

a)
b) c)

d)

There are 4 steps in the process : Create and edit file containing the program (source code) with a text editor. Run preprocessor to process the preprocessor directives (begin with #) Run compiler to: Check that the program obeys the rules Translate into machine language (object code) Run linker to connect hardware-specific code to machine instructions, producing an executable code. Steps bc are often performed by a single command or button click (compile using the compiler). Errors detected at any step will prevent execution of following steps. 42

From a High-level Program to an Executable Code


Programmer

Programmer

Code

Code

Executable Code

43

Program Development (cont.)


Loader:
Loads executable code/program into main memory

Execution:
The last step is to execute the program

44

45

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.

46

Integrated Development Environments (IDEs)

47

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
48

Professional Ethics for Computer Programmers


Privacy and Misuse of Data Computer Hacking Plagiarism and Software Piracy Misuse of a Computer Resource
-the end-

49