Imperative Programming: Introduction To C++
Imperative Programming: Introduction To C++
Imperative Programming
Lecture 1.3
(Week 1, Lecture 3)
Chapter 2:
Introduction to C++
2
Chapter 2:
Introduction
to
C++
Topics to be discussed
2.1 The Parts of a C++ Program
4
2.1 The Parts of a C++ Program
// sample C++ program comment
#include <iostream> preprocessor directive
using namespace std;
which namespace to use
int main()
beginning of function named main
{ beginning of block for main
cout << "Hello, there!"; output statement
return 0; string literal
} Send 0 to operating system
end of block for main
Programming is
fun!
The \n Escape Sequence
• You can also use the \n escape sequence to start a new
line of output.
Programming is
fun!
The #include Directive
• Inserts the contents of another file into the program
• This is a preprocessor directive, not part of C++
language
#include <iostream>
using namespace std;
2.4 Variables
• Variable:
– a storage location in memory (one or more bytes)
149
z = x + y;
cout << "x + y = " << z
<< endl;
return 0;
}
Note the following:
For group 4:
– The content of slides 11 to 15 will be discussed in the next
lecture
For group 5:
– The content of slides 11 to 15 will be re-visited in the next
lecture
16