From the above example, you can see that 2/3 of the program is the two functions. Most C++ programs have several items before the function main. As in the example, they often are:
- Documentation Most programs have a comment area at the start of the program with a variety of comments pertinent to the program. Any line starting with two slashes // is a comment and the compiler software disregards everything from the // to the end of the line.
- include<iostream> This line of code inserts a file into the source code. The file contains necessary code to be able to do simple input and output.
- using namespace std The C++ compiler has an area where it keeps the identifier names used in a program organized and it is called a namespace. There is a namespace created in conjunction with the iostream file called: std. This line informs the compiler to use the namespace std where the identifier names in the iostream are established.
- Function prototypes have already been explained.
- We need some variables (storage areas) for this program to work. They are defined next.