My First Program

In the previous sections, we discussed machine language and high-level languages and
showed a C++ program. Because a computer can understand only machine language,
you are ready to review the steps required to process a program written in C++.
Consider the following C++ program:
#include <iostream>
using namespace std;
int main()
{
cout << “My first C++ program.” << endl;
return 0;
}
At this point, you need not be too concerned with the details of this program. However,
if you run (execute) this program, it will display the following line on the screen:
My first C++ program.

//********************************************************
// This is a simple C++ program. It displays four lines
// of text, including the sum of two numbers.
//********************************************************
#include <iostream>
using namespace std;
int main()
{
int num;
num = 6;
cout << “My first C++ program.” << endl;
cout << “The sum of 2 and 3 = ” << 5 << endl;
cout << “7 + 8 = ” << 7 + 8 << endl;
cout << “Num = ” << num << endl;
return 0;
}
Sample Run: (When you compile and execute this program, the following four lines are
displayed on the screen.)
My first C++ program.
The sum of 2 and 3 = 5
7 + 8 = 15
Num = 6
These lines are displayed by the execution of the following three statements.
cout << “My first C++ program.” << endl;
cout << “The sum of 2 and 3 = ” << 5 << endl;
cout << “7 + 8 = ” << 7 + 8 << endl;
cout << “Num = ” << num << endl;