Source File Organization

A number of people have asked where/how they should organize a C++ source file. I suggest that you use the following style. It is a top-down style that is used fairly frequently by many programmers/textbook authors. Please remember that many programs are composed of multiple files.
// file name, e.g., Org.cpp

// header/other pertinent information 


   //  "System" includes
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <math.h>

   //  "User-defined" includes
#include "org.h"

   //  Local definitions/types

   //  Prototypes
void Func1();
int  Func2( int n );

   //  main
int main()
{
   ....     //  main program
}

   //  function definitions
void Func1()
{
   ....     //  statements

   return;  //  optional
}


int  Func2( int n )
{
   int iVal;

   ....     //  statements

   return iVal;
}

Home