Vous êtes sur la page 1sur 32

c  


 
 
 

2  
Class Objectives

‡ Learn about the evolution of programming


languages.

‡ Write and process your first C++ program

2
cntroduction
Elements of a Computer System

‡ Hardware
± CPU
± Main memory
± Secondary storage
± cnput/output devices

‡ Software

3
CPU (Central Processing Unit)

‡ CU (control unit):
± Fetches and decodes instructions
± Controls flow of information in and out of MM
± Controls operation of internal CPU components
‡ PC (program counter): points to next instruction to
be executed

4
CPU (Central Processing Unit)
(continued)
‡ c (instruction register): holds instruction currently
being executed
‡ ALU (arithmetic logic unit): carries out all arithmetic
and logical operations

cntroduction to C++ Programming: Brief Edition 5


cntroduction to C++ Programming: Brief Edition 6
Main Memory

‡ Directly connected to the CPU


‡ All programs must be loaded into main memory
before they can be executed
‡ All data must be brought into main memory before
it can be manipulated
‡ When computer power is turned off, everything in
main memory is lost

cntroduction to C++ Programming: Brief Edition 7


Main Memory (continued)

cntroduction to C++ Programming: Brief Edition 8


Secondary Storage

‡ Secondary storage: device that stores information


permanently
‡ Examples of secondary storage:
± Hard disks
± Flash drives
± Floppy disks
± Zip disks
± CD- OMs
± Tapes

cntroduction to C++ Programming: Brief Edition 9


cnput/Output Devices

‡ cnput devices feed data and programs into


computers
± Examples
‡ Keyboard, mouse, secondary storage
‡ Output devices display results
± Examples
‡ Monitor, printer, secondary storage

`
Software

‡ Software: programs that do specific tasks


‡ Examples
± Word processors, Operating systems, Spreadsheets

‡ The Program is a sequence of instructions.

‡ Without software, the computer is useless

‡ All software is written in programming languages


‡ C++ is a programming language
``
The Language of a Computer

‡ Digital signals are sequences of s and `s


‡ Machine language: language of a computer
‡ Binary digit (bit):
± The digit or `
‡ Binary code:
± A sequence of s and `s
‡ Byte:
± A sequence of eight bits

`2
`3
The Evolution of Programming
Languages

‡ Early computers were programmed in machine


language
‡ To calculate h  
 in
machine language you may need to write:
 

  
 


`4
Assembly Language

‡ Assembly language instructions are mnemonic


‡ Assembler: translates a program written in
assembly language into machine language

`5
Assembly Language (continued)
‡ Using assembly language instructions, h 
 
 can be written as:

 


 h 

`6
High-Level Languages

High-level languages include Basic, FO T AN,


COBOL, Pascal, C, C++, C#, and Java.

The equation h  


is written in
C++ as:
h  


‡ Compiler: translates a program written in a high-


level language to machine language

`7
Your first C++ Program

w 
 


 
 

 


  
  

 
       
 
       

   
!

  :
ï

!""
 #$
`8
Processing a C++ Program

`9
High-Level Languages

‡ Programming language: a set of rules (syntax),


symbols, and special words used to construct
programs.

‡ Syntax: rules that specify which statements


(instructions) are legal

‡ Semantic rule: meaning of the instruction

2
Your first C++ Program

‡ Save the program in a file with extension .CPP

‡ Preceding program consists of a function  #


± Heading: #  #%&

‡ 


   

 



 
 

2`
Comments

‡ Comments are for the reader, not the compiler


‡ Two types
± Single line
  !""
 $
'  #
($

± Multiple line

)
 ##  
#  #

* #$


22
Output
‡ The syntax of
 and ++ is:

± Called an output statement

‡ „     

‡ ¢        


     screen

23
Output
‡ A manipulator is used to format the output
± Example: # causes insertion point to move to
beginning of next line
Special Symbols

‡ Special symbols

Arithmetic operators: +, - , *, /

Punctuation: ;

// , /*, << , { } , ( )

25
Preprocessor Directives
 #   +
 , : preprocessor directive

‡ Preprocessor directives are commands supplied to


the preprocessor

‡ All preprocessor commands begin with #

‡ No semicolon at the end of these commands

26
Preprocessor Directives

‡ Syntax to include a header file is:

‡ For example:

#   +
 ,

± Causes the preprocessor to include the header file



  in the program so we could use
 and
#     

27
Preprocessor Directives

‡ Many functions and symbols needed in a C++


program are provided in a collection of libraries.

‡ Every library has a name and is referred to by a


header file.

‡ Each header file has specifications to some


functions Ex:
<cmath>, <iostream>

28
#   and Using
 in a
Program
 ##   
allows you to use
 and # without the prefix
--
%--
.--#&

‡ To use
.# in a program, use the
following two statements:
#   +
 ,
##   

29
eserved Words (Keywords)
‡ eserved words, keywords, or word symbols
± cnclude:
 '#  
 #
 #  
 #
 (

 
/
 

#
 *

  #
3
A C++ Program2

 
 
  
A string

Causes cursor to move to


beginning of next line
An arithmetic expression

3`
Sections covered from the book

You are able now to skim chapter and scan most of


chapter `

32

Vous aimerez peut-être aussi