Uploaded by Oliver Bartz

Intro To Programming -- C++

advertisement
What is programming?
What are computer languages and
how have they evolved?
What is the basic process of
programming, including the tools
involved?
A step-by-step set of instructions
to accomplish a task.
Example: Make KoolAid
- Fill jug with water
- Add KoolAid mix
- Stir
- Pour from jug into cups
A step-by-step set of instructions
to accomplish a task
expressed in a Computer
Language
Machine Language
- Consists of binary codes for very
simplistic commands
Ex: 1001 (move), 1100 (add)
- Codes differ by CPU model
- Is the only language a CPU can
follow
- Using ML Requires detailed
knowledge of the CPU/hardware.
Machine Language
ENIAC being
programmed
Univ of Penn, 1940’s
(photo: U.S. Army)
Assembly Language
- Consists of text codes for very
simplistic commands
Ex: ADD, SUB, MOVE
- Codes differ by CPU model
- 1-to-1 translation to Machine
Language
- Using Assembly requires detailed
knowledge of the CPU/hardware
High Level Language
- Consists of text codes for more
complex expressions
- Codes standardized across CPU models
- 1-to-Many translation to Machine
Language
- Does not require detailed knowledge
of the CPU/hardware.
ML vs ASSM vs HLL
Assembler:
Machine Lang:
MOV @065 to CPU:R1
10010001 01000001
MOV @066 to CPU:R2
10010010 01000010
ADD
01010000
MOV CPU:REG3 to @067
10100010 01000011
High Level Language:
x=a+b
Early High Level Languages
Fortran (FORMula TRANSlation)
- by IBM, 1950’s
- Number cruncher for
mathematicians, scientists and
engineers.
- Ex: A = 3.1415926 * R * R;
- Very poor at manipulating “pretty”
output and large volumes of data.
Early High Level Languages
COBOL (COmmon Business
Oriented Language)
- by committee, funded by DoD, 1960
- For business/management apps: does
“pretty” and handles large volumes of
data easily.
- Very English-Like. Ex:
ADD SUBTOTAL TO TAX GIVING TOTAL.
High Level Languages
C
- by Dennis Ritchie (AT&T), 1972
- Combines ease-of-use of a HLL with
the “power” of Assembly
- Used to write efficient systems
software (Unix Operating System)
Efficiency
Accomplishing a task using the least
amount of resources.
In Programming, “resources” are:
- Time (number of instructions executed)
- Space (amount of memory required)
High Level Languages
C++
- By Bjarne Stroustrup (AT&T), 1983
- Enhancement of C: major items:
- Object-Oriented Programming
- Extensibility: programmers can add
new features to the language itself.
Today: one of the most common languages.
Tools, Files and Errors
Software Tools
Editor – used to write the program in a HLL.
Compiler – translates program in a HLL into
Machine (or other low level) Language
Linker – combines Object Files into an
Executable.
Loader – copies an Executable into memory and
starts program execution.
Software Tools
Integrated Development Environment (IDE)
Combines the editor, compiler, linker, loader and
often other helpful tools into one programming
tool.
Example: Microsoft Visual Studio IDE
Files
Source – a text file containing a program written
in a HLL
Object – part of a program translated in Machine
Language
Executable – a complete program in Machine
Language
Errors
Syntax (aka Compiler) – found in the Source,
these are violations of the rules for writing
programs in the HLL.
Link – the linker is unable to link the object files
into an executable. Typical errors indicate
something is missing or the parts (objects) do
not “fit” together as expected.
Errors
Load – the loader is unable to copy the
executable into memory and start execution.
Typical errors include “not enough memory” or
“not a trusted program” (virus protection).
Run-Time – occurs during execution. Typical
errors include “division by 0”, “file not found”,
“memory access violation”. Execution halts
when a RTE occurs; normally called a “program
crash” and may not have an error message.
Errors
Logic (Semantic) – when there is no error from
the perspective of the computer, but rather the
program does something unexpected by the user.
Example: The program prints:
The area of a square with a length of 3m is 6m2
Errors
Bug
informal name for a Logic (or Run-Time) Error
- Programming is writing instructions for a
computer to follow.
- Various languages have been invented over
the years to assist programmers.
- While variations exist, there is a basic
process for writing code in a HLL and
translating it into ML, including use of a
basic set of tools.
Term
Definition
Algorithm
A step-by-step set of instructions to accomplish a task
Program
A step-by-step set of instructions to accomplish a task expressed in a
computer language.
Machine Language
Binary computer language that differs by CPU model…the only language a
computer can follow.
Assembly Language
Language made up of simple text codes for simplistic instructions. It differs by
CPU model and has a 1-to-1 translation of commands into Machine Language.
High Level Language Language made up of more complex and human-language-like codes with a 1to-many translation of commands into Machine Language.
FORTRAN
Early language used to solve mathematical/scientific/engineering problems.
COBOL
Early language used for business data processing.
C
Language combining the functionality of a HLL with that of Asssembly, used to
write Systems Software.
Term
Definition
C++
An enhancement of the C language providing support for Object-Oriented
Programming and language Extensibility.
Extensibility
The ability of a programmer to extend an existing language with new
features.
Editor
Software tool that allows a programmer to write a program in a HLL.
Compiler
Software tool that translates a program in a HLL into Machine Language.
Linker
Software tool that combines Object Files into a single Executable.
Loader
Software tool that copies an Executable into memory and initiates program
execution.
Source File
Text file that contains a program written in a HLL.
Object File
File that contains instructions in Machine Language, but is not a complete
program.
Executable File
File that contains instructions in Machine Language that is a complete
program.
Term
Definition
Syntax Error
Violation of a HLL rule in a Source File, discovered by the Compiler
Compiler Error
(same as Syntax Error)
Link Error
Error meaning the Linker is unable to combine Object Files into an Executable
Load Error
Error meaning the Loader is unable to copy an Executable into memory and
initiate program execution.
Run-Time Error
Error that occurs while a program is executing, causing the program to halt.
Logic Error
Unexpected output/behavior of a program when there is no other type of
error.
Semantic Error
(same as Logic Error)
Bug
Informal word meaning Logic (or Run-Time) Error
Download