PF - 4
PF - 4
Fundamentals
4
2
Basic Components of C++ Program
4 The Evolution of Programming
Languages
Early computers were programmed in machine language
To calculate wages = rates * hours in machine language:
LOAD rate
MULT hour
STOR wages
7 The Evolution of Programming
Languages (cont'd.)
High-level languages include Basic, FORTRAN, COBOL, Pascal, C, C++, C#,
and Java
Compiler: Translates a program written in a high-level language to machine
language
The equation wages = rate • hours can be written in C++ as:
wages = rate * hours ;
8 Assembly & Machine Language
Assembly Language Machine Language
CALL PRINT
9 Equivalent C/C++ program
}
set memory[803] to 2 times memory[801] x = x*2;
put memory[803] in to memory[801] }
jump to instruction #3
Preprocessor
Preprocessor Disk program processes
Phases of C++ Programs: the code
4. Link Loader
5. Load .
Loader puts program
in memory
.
Disk
6. Execute
.
Primary memory
CPU takes each
instruction and
CPU executes it, possibly
storing new data
.
.
values as the program
. executes.
13 Compilers
Translate high-level language to machine
language
Check that the program obeys the rules
Source code
The original program in a high-level language
Object code
The translated version in machine language
14 Linkers and Loader
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 (of SDK)
into
The machine language program the CPU can run
Loader:
Loads executable program into main memory
The last step is to execute the program
Program Analysis Execution Coding Cycle
15
20 History of C and C++
History of C
Evolved from two other programming languages
BCPL and B: “Typeless” languages
Dennis Ritchie (Bell Lab): Added typing, other features
C is a programming language developed in the 1970's alongside the UNIX
operating system
C provides a comprehensive set of features for handling a wide variety of
applications, such as systems development and scientific computation
1989: ANSI standard/ ANSI/ISO 9899: 1990
21 History of C and C++
History of C++
Early 1980s: Bjarne Stroustrup (Bell Lab)
Provides capabilities for object-oriented programming
Objects: reusable software components
Object-oriented programs
C++ systems
Program-development environment
Integrated Development Environment (IDE)
Language
C++ Standard Library
C++ program names extensions
.cpp (C Plus Plus)
.c (C)
24 The C++ Standard Library
C/C++ programs consist of pieces/modules called functions
A programmer can create his own functions
Advantage: the programmer knows exactly how it works
Disadvantage: time consuming
Programmers will often use the C/C++ library functions
Use these as building blocks
Avoid re-inventing the wheel
If a pre-made function exists, generally best to use it rather than write
your own
Library functions carefully written, efficient, and portable
25 Programming Style
Temporary file
C++ (C++ program) C++
Preprocessor Compiler
Executable
C++ Program Program
36 Some common include statements
Basic I/O: iostream.h
Provides functionality of input and output
I/O manipulation: iomanip.h
Format’s the input and output
Standard Library: stdlib.h
Functions for memory allocation, process control, conversion
etc.
Time and Date support: time.h
Functionality of time manipulation
Mathematics support: math.h
Functionality of basic mathematical functions
37 C++ …
Explore simple data types
Discover how to use arithmetic operators
Examine how a program evaluates arithmetic
expressions
Learn what an assignment statement is and what it does
Become familiar with the string data type
Become familiar with the use of increment and
decrement operators
Explore how to properly structure a program, including
using comments to document a program
Learn how to write a C++ program
38 Testing and debugging
Bug
A logical 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.”
39 Testing and debugging
FINALLY! A Programmers Drinking Song! Woo! Hoo!
Thank you