Applying enumeration and header file to calculator

The purpose of the following example is to how to use enumerations in a code that’s already familiar from Programming 1. There are three enumeration types declared:

  1. Specifying command line argument position
  2. Encoding error codes
  3. Encoding mathematical operations

In addition, there are a few “clever tricks” shown that have not been in the lab materials up to this point.

  1. Declaring an array of error texts and using enum values to declare and index them.
  2. Creating a structure array that contains both text and coded enum value pairs.

The example is provided to you in two variations

  1. The entire example is written in one code file. This is suitable to look at on week #2, when enum types are introduced
  2. The example divided into a code and header file. This is suitable for week #4. This is also very close to the minimum requirements of homework 1.
Single code fileHeader and code file

The following example contains two files. Both must be placed in the same directory. The name of the header is dependent on the #include  statement in calc_enum.h . It is a common practice to keep the header and source file name the same, but with a different extension.

The following has been transferred from the code file to the header file:

  • Comments that are directed for developers using the functions
  • Macros
  • Structure and enumeration declarations
  • Function prototypes (declarations)

Additionally, short comments intended for developers of that file were added to the code file and header guard was added to the header file to avoid multiple conflicting declarations.