A Complete Guide to Programming in C++ part 15. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | chapter 7 Symbolic Constants and Macros This chapter introduces you to the definition of symbolic constants and macros illustrating their significance and use. In addition standard macros for character handling are introduced. 119 120 CHAPTER 7 SYMBOLIC CONSTANTS AND MACROS MACROS Sample program Creates a sine function table include iostream include iomanip include cmath using namespace std define PI define START define END PI define STEP PI define HEADER cout sine Function Table Lower limit Upper limit Step width n n int main HEADER Title Table Head cout setw 16 x setw 20 sin x n -------------------------------------------- fixed endl double x for x START x END STEP 2 x STEP cout setw 20 x setw 16 sin x endl cout endl endl return 0 Screen output Table for the Sine Function x sin x MACROS 121 C has a simple mechanism for naming constants or sequences of commands that is for defining macros. You simply use the preprocessor s define directive. Syntax define name substitutetext This defines a macro called name. The preprocessor replaces name with substitutetext throughout the subsequent program. For example in the program on the opposite page the name PI is replaced by the number throughout the program in the first phase of compilation. There is one exception to this general rule substitution does not take place within strings. For example the statement cout PI outputs only PI and not the numerical value of PI. Symbolic Constants Macros that are replaced by constants such as the PI macro are also known as symbolic constants. You should note that neither an equals sign nor a semicolon is used as these would become part of the substitute text. You can use any macros you have previously defined in subsequent define directives. The program opposite uses the symbolic constant PI to define other constants. More about Working with Macros Any preprocessor directive and this