Intro To C++ Programming and Computer Organization
Intro To C++ Programming and Computer Organization
Organization
and
C++ Programming
Overview
• Workstation
• Larger and more powerful than a PC
• Mainframe
• Still larger
• Requires support staff
• Shared by multiple users
Networks
• A number of computers connected to
share resources
• Share printers and other devices
• Share information
Computer Organization
Display 1.1
• Main Memory
Long list of memory locations
Each contains zeros and ones
Can change during program execution
• Binary Digit or Bit
A digit that can only be zero or one
• Byte
Each memory location has eight bits
• Address
Number that identifies a memory location
Larger Data Items
• Some data is too large for a single byte
• Most integers and real numbers are too large
• Address refers to the first byte
• Next few consecutive bytes can store the additional
bits for larger data
Display 1.2
Data or Code?
• ‘A’ may look like 01000001
• 65 may look like 01000001
• An instruction may look like 01000001
• How does the computer know the meaning
of 01000001?
• Interpretation depends on the current instruction
• Sequential Access
• Data is generally found by searching through
other items first
• More common in secondary memory
The Processor
• Typically called the CPU
• Central Processing Unit
• Follows program instructions
• Typical capabilities of CPU include:
add
subtract
multiply
divide
move data from location to location
Computer Software
• The operating system
• Allows us to communicate with the computer
• Is a program
• Allocates the computer’s resources
• Responds to user requests to run other programs
Display 1.3
High-level Languages
• Common programming languages include …
C C++ Java Pascal Visual Basic FORTRAN
COBOL Lisp Scheme Ada
• Source code
• the original program in a high level language
• Object code
• the translated version in machine language
Display 1.4
Linkers
• Some programs we use are already compiled
• Their object code is available for us to use
• For example: Input and output routines
• A Linker combines
• The object code for the programs we write
and
• The object code for the pre-compiled routines
into
The machine language program the CPU can run
Display 1.5
History Note
• First programmable computer
• Designed by Charles Babbage
• Began work in 1822
• Not completed in Babbage’s life time
• First programmer
• Ada Augusta, Countess of Lovelace
• Colleague of Babbage
Programming
and Problem Solving
• Algorithm
• A sequence of precise instructions which
leads to a solution
• Program
• An algorithm expressed in a language the computer
can understand
Display 1.6
Program Design
• Implementation Phase
• Result is the algorithm translated into a programming
language
Problem Solving Phase
• Inheritance
• Writing reusable code
• Objects can inherit characteristics from other objects
• Polymorphism
• A single name can have multiple meanings depending
on its context
Software Life Cycle
Introduction to C++
• Where did C++ come from?
• Derived from the C language
• C was derived from the B language
• B was derived from the BCPL language
•Program statement
total_peas = number_of_pods * peas_per_pod;
• Performs a computation
• ‘*’ is used for multiplication
• ‘=‘ causes total_peas to get a new value based on
the calculation shown on the right of the equal sign
Explanation of code (5/5)
• Program statement
cout << number_of_pods;
• Include Directives
#include <iostream>
• Tells compiler where to find information about items
used in the program
• iostream is a library containing definitions of cin and cout
Program Layout (3/3)
using namespace std;
• Tells the compiler to use names in iostream in
a “standard” way
Display 1.10
Testing and Debugging
• Bug
• A mistake in a program
• Debugging
• Eliminating mistakes in programs
• Term used when a moth caused a failed relay
on the Harvard Mark 1 computer. Grace Hopper
and other programmers taped the moth in logbook
stating:
“First actual case of a bug being found.”
Program Errors
• Syntax errors
• Violation of the grammar rules of the language
• Discovered by the compiler
• Error messages may not always show correct location of
errors
• Run-time errors
• Error conditions detected by the computer at run-time
• Logic errors
• Errors in the program’s algorithm
• Most difficult to diagnose
• Computer does not recognize an error
End…
Back Next
Display 1.1
Back Next
Display 1.2
Slid
Copyright © 2003 Pearson Education, Inc.
e 45
Back Next
Display 1.3
Slid
Copyright © 2003 Pearson Education, Inc.
e 49
Back Next
Display 1.7