TAILIEUCHUNG - A Complete Guide to Programming in C++ part 15

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

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.