Đang chuẩn bị liên kết để tải về tài liệu:
Algorithms and Data Structures in C part 4

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

To test out the derivation for calculating the 2’s complement of a number derived in Section 1.1.3 a program to calculate the negative of a number is shown in Code List 1.7. | 10 10 To test out the derivation for calculating the 2 s complement of a number derived in Section 1.1.3 a program to calculate the negative of a number is shown in Code List 1.7. The output of the program is shown in Code List 1.8. Problem 1.11 investigates the output of the program. Code List 1.7 Testing the Binary Operators in C Code List 1.8 Output of Program in Code List 1.7 A program demonstrating one of the most important uses of the OR operator is shown in Code List 1.9. The output of the program is shown in Code List 1.10. Figure 1.1 demonstrates the value of x for the program. The eight attributes are packed into one character. The character field can hold 256 28 combinations handling all combinations of each attribute taking on the value ON or OFF. This is the most common use of the OR operators. For a more detailed example consider the file operation command for opening a file. The file definitions are defined in iostream.h by BORLAND C as shown in Table 1.7. Figure 1.1 Packing Attributes into One Character Code List 1.9 Bit Operators Code List 1.10 Output of Program in Code List 1.9 Table 1.7 Fields for File Operations in C Source enum open_mode in 0x01 open for reading out 0x02 open for writing ate 0x04 seek to eof upon original open app 0x08 append mode all additions at eof trunc 0x10 truncate file if already exists nocreate 0x20 open fails if file doesn t exist noreplace 0x40 open fails if file already exists binary 0x80 binary not text file A program illustrating another use is shown in Code List 1.11. If the program executes correctly the output file test.dat is created with the string This is a test placed in it. The file test.dat is opened for writing with ios out and for truncation with ios trunc. The two modes are presented together to the ofstream constructor with the use of the or function. Code List 1.11 Simple File I O Previous Table of Contents Next Copyright CRC Press LLC Algorithms and Data Structures in C by Alan Parker CRC Press CRC .

TÀI LIỆU LIÊN QUAN