Electrical Engineering - Chapter 18: Miscellaneous Topics

Makes possible to accommodate many programmers working on same project More efficient to manage large amount of source code Can incorporate class libraries in separate files from independent vendors

ppt24 trang | Chia sẻ: thuongdt324 | Lượt xem: 410 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Electrical Engineering - Chapter 18: Miscellaneous Topics, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
Chapter 18 – Miscellaneous TopicsMultiple File ProgramsMakes possible to accommodate many programmers working on same projectMore efficient to manage large amount of source codeCan incorporate class libraries in separate files from independent vendorsLesson 18.1Using Header FilesHeader file is source code fileInserted into program source code before program compiledCan create own header filesOption of having separate files for class definitions, implementations, and mainPlaced in different header files and use #includeLesson 18.1Working With Header FilesCreating header fileSource code file with extension .hIncluding header files#include “name.h”Header file contentsPut each class definition and each class implementation in separate filesLesson 18.1Header File ContentsThree lines neededTwo at top and one at bottomMessages to preprocessor and not compiled#ifndef name_h#define name_hsource code#endifLesson 18.1Preprocessor Directives#ifdef True if identifier defined in previous preprocessor#if True block executed if constant expression following is true #else Forms false block for #if#endif Marks end of conditional inclusion#ifndef True if identifier NOT defined previously#elif Works similar to “else if”#undef Undefines previously defined identifier Lesson 18.1Another MethodMore efficient connecting files with IDEIntegrated Development EnvironmentSave correctly working files as object codeLink after all changes have been recompiledLesson 18.1Bitwise ManipulationsVery low-level operationsManipulate individual bits (1s and 0s)C++ provides bitwise operatorsSix operatorsBit valuesset if value is 1clear if value is 0Lesson 18.2Why Use Bitwise OperatorsTo control peripheralsTo use as flagsUse individual bits instead of integersFile encryptionArray handling for any array that has members with only two possible statesLesson 18.2Bitwise OperatorsAND &Inclusive OR |Exclusive OR ^Also called XORComplement ~ (unary operator)Right shift >>Left shift > 1 (address), num_bytes);Lesson 18.3Programmer-chosen output file object nameAddress of beginning of memory cells being written to fileNumber of bytes to be copied from memory to fileReading From a Binary Filein.ob.read (reinterpret_cast (address), num_bytes);Lesson 18.3Programmer-chosen input file object nameAddress of beginning of memory cells to which bytes are copiedNumber of bytes to be copied from file to memoryOperator that makes C++ interpret address to represent beginning of an array of charactersClosing the FileClose file after writingCan open later for reading againLesson 18.3outfile.close ( )SummaryBenefits of multiple file organizationHow to use header filesHow to use bitwise operatorsHow to work with binary files
Tài liệu liên quan