You are on page 1of 14

1

Chapter 1 – Introduction to Computers


Outline:

1.1 Introduction
1.2 Computers: Hardware and Software
1.3 Computer Organization
1.4 Machine Languages, Assembly Languages
and High-Level Languages
1.5 Typical C++ Development Environment
1.6 C++ Keywords

 2003 Prentice Hall, Inc. All rights reserved.


2

1.1 Introduction

• Computer
– Device capable of performing computations and making logical
decisions
• Computer programs
– Sets of instructions that control computer’s processing of data

 2003 Prentice Hall, Inc. All rights reserved.


3

1.2 Computers: Hardware and Software

• Hardware
– Various devices comprising computer
• Keyboard, screen, mouse, disk, memory, CD-ROM, …
• Software
– Instructions to command computer to perform actions and make
decisions

 2003 Prentice Hall, Inc. All rights reserved.


4

1.3 Computer Organization

• Six logical units of a computer


1. Input unit
• Obtains information from input devices
– Keyboard, mouse, microphone, scanner, networks, …
2. Output unit
• Places information on output devices after it was processed by the
computer
– Screen, printer, networks, …
3. Memory unit
• Rapid access, relatively low capacity memory
• Retains information from input unit to be available for processing
• Retains processed information until placed on output devices

 2003 Prentice Hall, Inc. All rights reserved.


5

1.3 Computer Organization

• Six logical units of a computer


4. ALU: Arithmetic and Logic Unit
• Performs arithmetic calculations and logic decisions
5. CPU: Central Processing Unit
• Supervises and coordinates other sections of computer
6. Secondary Storage Unit
• Long-term, high-capacity storage device
• Storage devices hold inactive programs or data
– Disks, Diskette, Zip, CD_ROM, USB, …
• Longer to access than primary memory RAM
• Less expensive per unit than primary memory

 2003 Prentice Hall, Inc. All rights reserved.


6
1.4 Machine Languages, Assembly Languages,
and High-level Languages
• Three types of computer languages
1. Machine language
• It is the only language that the computer directly understands
• We refer to it as the “Natural language” of computer
• Consist of strings of 0s and 1s
• It instructs the computer to perform elementary operations
– One operation at a time
• It is a cumbersome language for humans
• Example:
+10100011011
+10010100111
+11000110100

 2003 Prentice Hall, Inc. All rights reserved.


7
1.4 Machine Languages, Assembly Languages,
and High-level Languages
2. Assembly language
• It uses English-like abbreviations that represent elementary
computer operations, such as:
– LOAD, MOV, STORE, MULT, CMP, ADD, SUB
• It is clearer to humans than machine language
• Assembly is incomprehensible to computers
– They need a translator program called assembler; which
converts them into machine language to be executed
• Example:
LOAD BASE_PAY
ADD OVER_PAY
STORE GROSS_PAY

 2003 Prentice Hall, Inc. All rights reserved.


8
1.4 Machine Languages, Assembly Languages,
and High-level Languages
3. High-level languages
• Similar to everyday English, and uses common mathematical
notations
• Single statements accomplish significant tasks
– Assembly language requires many instructions to accomplish
simple tasks
• It requires a translator program called compiler, in order to
convert the code into machine language
• Example:
grossPay = basePay + overTimePay

 2003 Prentice Hall, Inc. All rights reserved.


9

1.5 Typical C++ Development Environment

• C++ systems generally consist of several parts:


– Program-development environment
– Language
– C++ Standard Library
• The C++ Programs typically go through six phases to
be executed
1. Edit
2. Preprocess
3. Compile
4. Link
5. Load
6. Execute

 2003 Prentice Hall, Inc. All rights reserved.


10

1.5 Typical C++ Development Environment


Program is created in the
Editor Disk editor and stored on disk
Phases of C++ Programs:
Preprocessor Disk Preprocessor program
processes the code
1. Edit Compiler creates object
Compiler Disk code and stores it on disk
2. Preprocess
Linker links the object
Linker Disk code with the libraries,
3. Compile creates a.out/exe file
Primary
Memory and stores it on disk
4. Link Loader

Loader puts program


5. Load Disk ..
in memory
..
..

6. Execute Primary
Memory
CPU
CPU takes each
instruction and executes
it, possibly storing
..
..
new data values as the
.. program executes

 2003 Prentice Hall, Inc. All rights reserved.


11

1.5 Typical C++ Development Environment

• Edit
– This phase is accomplished with an editor program
– Using a text editor, programmers create a C++ program, make
the necessary changes, and save it on disk
– A C++ program file name ends with .cpp, .cxx, or .C extension
• Preprocess
– Before the Compiler’s translation phase begins, a Preprocessor
program is executed automatically
– Preprocessor directives indicate certain manipulations to be
performed on the source program before compilation, such as
file inclusion, text replacement

 2003 Prentice Hall, Inc. All rights reserved.


12

1.5 Typical C++ Development Environment

• Compile
– The compiler is a program that translates a High-Level Language
(Source Code) into a machine language (Object Code)
– Following to preprocessing phase, the compiler program checks
for syntax error
• Errors in syntax or punctuation
– It points to the error to be corrected
– Once corrected, the source program should be compiled again
• Link
– When all errors are corrected, linkage editor program performs
the final step for a program to become executable

 2003 Prentice Hall, Inc. All rights reserved.


13

1.5 Typical C++ Development Environment

• Load
– Before a program is executed, it must be first placed in memory
– This is done by the loader, which takes the executable image
from disk and transfers it to the memory
• Execute
– Finally the computer, under the control of the CPU, executes the
program one instruction at a time
• Notes
– Each of the preceding phases can fail because of various errors
– Translating a program into executable code does not mean that it
will run correctly. We have:
• Logic error
• Run-time error, like dividing by 0
 2003 Prentice Hall, Inc. All rights reserved.
14

1.6 C++ Keywords

• C++ keywords cannot be used as identifiers or variables names


C++ Ke ywo rd s
Keywords common to the C and C++ programming languages
auto break case char const
continue default do double else
enum extern float for goto
if int long register return
short signed sizeof static struct
switch typedef union unsigned void
volatile while
C++ only keywords
asm bool catch class const_cast
delete dynamic_cast explicit false friend
inline mutable namespace new operator
private protected public reinterpret_cast
static_cast template this throw true
try typeid typename using virtual
wchar_t

 2003 Prentice Hall, Inc. All rights reserved.

You might also like