Wrox Press C++ Tutorial
In this last example, we distributed the code among several files for the first time. Not only is this common practice with C++ applications generally, but often it is essential. The sheer volume of code involved in even the simplest program necessitates dividing it into workable chunks.
As we discussed in the previous section, there are basically two kinds of source code file in a C++ program, .h files and .cpp files. This is illustrated in this diagram:

First of all, there's the executable code, which corresponds to the definitions of the functions that make up the program. Second, there are definitions of various kinds that are necessary for the executable code to compile correctly. These are global constants and variables, data types, including classes, structures, and unions and function prototypes. The executable source code is stored in files with the extension .cpp, and the definitions are stored in files with the extension .h.
From time to time, you might want to use code from existing files in a new project. In this case you only have to add the .cpp files to the project, which you can do by using the Project | Add To Project menu option, or by right-clicking in the editor window displaying a .cpp file and selecting from the pop-up menu to add the file to your project. You don't need to add .h files to your project, although you can if you want them to be shown in FileView immediately. The code from .h files will be added at the beginning of the .cpp files that require them as a result of the #include directives that you specify. You need #include directives for header files containing standard library functions and other standard definitions, as well as for your own header files. Visual C++ automatically keeps track of all these files, and enables you to view them in FileView. As you saw in the last example, you can also view the class definitions and global constants and variables in ClassView.
As we've already said, for classes of any complexity, it's usual to store the class definition in a .h file with a filename based on the class name, and to store the implementation of the function members of the class that are defined outside the class definition in a .cpp file with the same name. On this basis, the definition of our Box class appeared in a file with the name Box.h. Similarly, the class implementation was stored in the file Box.cpp. We didn't follow this convention in the earlier examples in the chapter because the examples were very short, and it was easier to reference the examples with names derived from the chapter number and the sequence number of the example within the chapter.
Segmenting a C++ program into .h and .cpp files is a very convenient approach, as it makes it easy for you to find the definition or implementation of any class, particularly if you're working in a development environment that doesn't have all the tools that Visual C++ provides. As long as you know the class name, you can go directly to the file you want. This isn't a rigid rule, however. It's sometimes useful to group the definitions of a set of closely-related classes together in a single file and assemble their implementations similarly. However you choose to structure your files, the ClassView will still display all the individual classes, as well as all the members of each class, as you can see here:

Here, you can see the details of the classes and globals for the last example. Double-clicking on any of the entries in the tree will take you directly to the relevant source code.