let-us-c++-yashwant-kanetkar.pdf - Google Drive

3 downloads 202 Views 424KB Size Report
let-us-c++-yashwant-kanetkar.pdf. let-us-c++-yashwant-kanetkar.pdf. Open. Extract. Open with. Sign In. Main menu. Displa
2. 2.1 2.2 2.3 2.4 2.5 2.6 2.7 3.

Primitive Types and Operators 17 Modulus Operator % ..................................................................... 17 Conversion Between Different Types in Calculation ........................... 17 Do Not Rely On the Precision of Float Numbers ................................ 17 Assignment Operators .................................................................. 17 Value of Assignment Expression ..................................................... 17 The Integer Value of Character ...................................................... 17 Logic Operators ........................................................................... 17 Control Structures

18

3.1 Control Structures ........................................................................ 18 3.2 if ................................................................................................ 18 3.3 if-else ......................................................................................... 18 3.4 Conditional Operator .................................................................... 18 3.5 while .......................................................................................... 18 3.6 for Loop ...................................................................................... 18 3.7 Avoid Modifying the Control Variable in the Loop Body ...................... 19 3.8 switch ......................................................................................... 19 3.9 do-while...................................................................................... 19 3.10 “break” and “continue” ................................................................. 19 4. 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 5.

Arrays

21

Declare and Initialize Array ........................................................... 21 Array Size Must Be Constant.......................................................... 21 Array Size ................................................................................... 21 Array and Pointer ......................................................................... 21 Pass Array to Function .................................................................. 22 Searching Array ........................................................................... 23 Multiple-Subscripted Array ............................................................ 23 String Handling Functions ............................................................. 23 Pointers and Strings 25

5.1 Pointer Declaration and Initialization............................................... 25 5.2 Casting Between Numeric Address and Pointer ................................ 25 5.3 Constant Pointer and Pointer to Constant ....................................... 25 5.4 Pass Pointer By Reference ............................................................. 25 5.5 Receive array with pointer ............................................................. 26 5.6 Pointer Expressions and Arithmetic ................................................. 26 5.7 Pointer Offset and Subscription ...................................................... 26 5.8 "sizeof" Operator.......................................................................... 27 5.9 Size of String and Character Array ................................................. 27 5.10 Function Pointer and Call Back Technique ........................................ 27 5.11 Array of Function Pointer and Menu-Driven System .......................... 29 5.12 Power and Flexibility of Pointers ..................................................... 29

6.

Class 32

6.1 Class .......................................................................................... 32 6.2 Methods of a Class ....................................................................... 32 6.3 Constructor ................................................................................. 32 6.4 Default Construcotr ...................................................................... 33 6.5 Copy Constructor ......................................................................... 33 6.6 Accessing Class Members .............................................................. 33 6.7 Typical Methods ........................................................................... 33 6.8 Avoid Repeating Code ................................................................... 34 6.9 When Constructors and Destructors are Called................................. 34 6.10 Default Memberwise Copy and Default Memberwise Assignment ........ 34 6.11 Pass-by-value and Copy Constructor .............................................. 34 6.12 Copy Constructor vs. Factory Method.............................................. 34 6.13 Various Places to use “const”: Use-A" and "Know-A" Relationship .......................... 49 8.5 Public, Protected and Private Inheritance ........................................ 49 8.6 Shrinking Inheritance ................................................................... 50 8.7 Methods That Are Not Inherited ..................................................... 50 8.8 Software Engineering with Inheritance ............................................ 50 8.9 Partial Assignment ....................................................................... 50 8.10 Sequence of Constructor Call in Inheritance .................................... 51 8.11 Default Constructor in Inheritance .................................................. 52 9. 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 10.

Polymorphism 53 Virtual Methods ............................................................................ 53 Polymorphism .............................................................................. 53 Dynamic and Static Binding ........................................................... 53 Abstract Base Class (ABC) ............................................................. 53 Virtual Destructor ......................................................................... 53 Hierarchy for Interface and Implementation .................................... 53 Base Class Idiom ......................................................................... 53 Apply Polymorphism on Operator > .................................. 54 Stream IO 55

10.1 Iostream Library Header Files ........................................................ 55 10.2 Stream IO Classes and Objects ...................................................... 55 10.3 Output the address of a pointer ..................................................... 55 10.4 Method put .................................................................................. 55 10.5 Stream Input ............................................................................... 55 10.6 Unformatted IO............................................................................ 56 10.7 Stream manipulators .................................................................... 56 10.8 Stream Error States ..................................................................... 58 11.

File Processing 59

11.1 c = "