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

The example is provided to you in three variations, suitable for different times in the course

  1. Calculator basic is suitable for week #2. It only adds enumerations.
  2. Calculator + struct is suitable for week #3. It adds a struct that matches together the expected character symbols to the expected enumerated values, that allows for nicer matching using a loop and a predefined lookup table.
  3. Calculator + header is suitable for week #4. It takes the previous code and divides it into two files – a header and code file. This is also very close to the minimum requirements of homework 1.
Calculator basicCalculator + structCalculator + header

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.