General C++ Program Structure

General Structure: The following outline is not C++ code (the actual code follows in the example), it merely shows how the sections of a typical C++ program are organized.

header comments

includes

using directive

function signature {

    object (or variable) declarations

    statements

}

Example:

// The header comments go at

// the beginning of your code

// to tell the reader what its about

// in the include section, you get stuff for your program that other programmers wrote

// for example, in the statement below, we include code for input and output (i.e., io)#include <iostream>       

// the using directive allows us to use the program objects from the included code namespace std; 

// the most important function signature is the main program (where all programs start)int main () {

    // we typically put all variable declarations after the function signature

    // allowable variable types are:

    // int - an integer varaible

    // double - a real variable

    // char - a character (or symbol) varaible

    // bool - a "true" or "false" variable

    // string - a variable that is a collection (or string) of characters

 

    // many different types of statements follow, this is the "program" part of your code

    // statement 1

    // statement 2

    // .....

    // statement n

    // the last statement is most always a return

    return 0;

}