Professional Documents
Culture Documents
Deitel
& Deitel, “C++ How to Program”,
5th Edition (or any latest)
Robert
Lafore, “Object-Oriented
Programming in C++”, 3rd/4th Edition
Agenda
What is Programming
Why we do Programming
The Programming Process
History of C++ language
Compiler
Interpreter
Structure of C++ program
Hello World Program
Escape Sequences
Why we do Programming
4. Link Loader
Memory
6. Execute Primary
Memory
CPU
CPU takes each
instruction and
executes it, possibly
storing new data
..
.. values as the program 7
..
executes.
Compiler and Interpreter
Compiler Interpreter
Interpreter Takes Single instruction as input .
Compiler Takes Entire program as input No Intermediate Object Code is Generated
Intermediate Object Code is Generated Conditional Control Statements are Executes
Conditional Control Statements are Executes slower
faster Memory Requirement is Less
Memory Requirement : More Every time higher level program is converted
Program need not be compiled every time into lower level program
Errors are displayed after entire program is Errors are displayed for every instruction
checked interpreted (if any)
Example : C Compiler
Example : BASIC
Structure of C++ Program
Three main parts:
Preprocessor Directives
main() function
C++ statements
Preprocessor Directives
The instructors that are given to the compiler before the beginning of the
actual program are called preprocessor directives or compiler directives
Preprocessor Directives (cont.)
consists of instructions for the compiler
includes header files
starts with # sign
keyword: include
Header Files
C++ source file containing definitions of library functions
Added in a program
File name written in angle brackets < > or double quotes “ ”
Example: #include<iostream>, #include<fstream>
main() Function
Beginning of a C++ program
Every C++ program has a main function
main function is a unique function
When program executes control transfers to main function
Program is not compiled without a main function
Syntax:
main()
{
Program statements
}
C++ Statements
C++ statements are written under the main() function between curly braces
C++ statements end with a semicolon ;
C++ language is case sensitive
C++ language written in lower case
Keywords
include
using namespace std
main
int
cout
endl
Hello World Program
#include <iostream>
using namespace std;
int main()
{
cout<<“Hello World”;
return 0;
}
Escape Sequence
\a Alert alarm
\b Backspace e.g
cout<< “Hello World\b”;
Tab, e.g
\t
cout<<“Hello \tWorld”;
New line
\n
Comment e.g
//
\\cout<<“Hello World”;
Print double quotes e.g
\” cout<<“ \”Hello World\” ”;
Print Single quotes e.g
\’ cout<<“ \’Hello World\’ ”;