Programming Lecture 3
Programming Lecture 3
Programming
Lecture 3
INTRODUCTION TO C++
Dr. Badria Nabil
Programming
2
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
C++ History
3
4
Typical C++ Development Environment
C++ programs normally undergo six phases
Edit
◼ Programmer writes program (and stores source code on disk)
Preprocess
◼ Perform certain manipulations before compilation (#)( like calling for libraries
of functions)
Compile
◼ Compiler translates C++ programs into machine languages
Link
◼ Link object code with missing functions and data
Load
◼ Transfer executable image to memory
Execute
◼ Execute the program one instruction at a time 5
6
C++ program Development Environment
7
Garbage In Garbage Out (GIGO)
8
1.4
9
Types of errors in programming
10
Single-line comment
◼ Begin with //
◼ Example
◼ // This is a text-printing program.
Multi-line comment
◼ Start with /*
◼ End with */
#include <filename>
Compiler directive
Processed by preprocessor before compiling
Begin with #
return statement
Oneof several means to exit a function
When used at the end of main
◼ Thevalue 0 indicates the program terminated successfully
◼ Example
◼ return 0;
18
Output
19
“Connected” to screen
Defined in input/output stream header file
<iostream>
The stream insertion operator is <<
White space
Blank lines, space characters and tabs
Used to make programs easier to read
24
Reserved Words (Keywords)
Have special meaning in C++
Cannot be used for other purposes
The Hello world program
When learning a new language, the first program people
usually write is one that display the message of “ Hello World”
return 0;
}
Assignment 2
27