Programming in C++
(Object Oriented Programming Using C++)
By
Dr.P.Rizwan Ahmed, MCA., M.Sc.,M.A, M.Phil., Ph.D,
Head of the Department
Department of Computer Applications &
Post Graduate Dept. of Information Technology
Mazharul Uloom College, Ambur - 635 802
Vellore Dist. Tamil Nadu.
CONTENTS
Preface
Acknowledgement
Chapter 1 Principles of Object Oriented Programming
1.1 Object Oriented Programming (OOP)
1.2 Procedure Oriented Programming (POP
1.2.1 Features of procedure oriented Programming:
1.2.2 Difference between Procedure Oriented Programming and Object Oriented
Programming
1.3 Object Oriented Programming Paradigm
1.4 Features of Object Oriented Programming
1.5 Key Concepts of Object Oriented Programming
1.5.1 Objects
1.5.2 Classes
1.5.3 Data Abstraction
1.5.4 Encapsulation
1.5.5 Inheritance
1.5.6 Polymorphism
1.5.7 Dynamic binding
1.5.8 Message Passing
1.6 Benefits of OOP
1.7 Advantages of OOP
1.8 Applications of OOP / Usage of OOP
1.9 Object Oriented Languages
1.9.1 Object- oriented programming language
1.9.2 Object – based programming language
Summary
Review Question
Chapter 2 Introduction to C++
2.1 Evolution of C++
2.2 What is C++?
2.3 C++ and C
2.4 Characteristics of C++
2.5 Usage of C++
2.6 Structure of a C++ program
2.7 Comments
2.8 Advantages of C++
Summary
Review Question
Chapter 3 Managing Console I/O operations /Input and Output in C++
3.1 Streams in C++
3.1.1 I/O Operations
3.2 Predefined Streams
3.3 Streams Classes
3.4 Stream Class Hierarchy
3.5 Member functions of istream class
3.6 Unformatted Console I/O operations
3.7 Formatted Console I/O
3.8 Manipulators
3.9 Managing output with manipulators
3.10 Designing our own manipulators / User defined manipulators
Summary
Review Question
Chapter 4 Basics of C++
4.1 Tokens
4.1.1 Keywords
4.1.2 Identifiers
4.1.3 Constants
4.2 Data Types
4.2.1 Basic Data Type
4.2.2 User defined data type
4.2.2.1 Structure
4.2.2.2 Union
4.2.2.2.1 Difference between Structure and Union
4.2.2.3 Enumeration
4.2.2.4 Class
4.2.3 Derived Data Types
4.2.4 Operators
4.2.4.1 Arithmetic Operators
4.2.4.2 Relational Operators
4.2.4.3 Logical Operators
4.2.4.4 Assignment Operators
4.2.4.5 Increment and Decrement Operators
4.2.4.6 Bitwise Operators
4.2.4.7 Conditional Operator
4.2.5 Scope Resolution Operator (::)
4.2.6 Member dereferencing operator
4.2.7 Memory Management Operators
4.2.7.1 New
4.2.7.2 Delete
4.2.8 Comma Operator
4.2.9 sizeof operator
4.3 Strings
4.4 Variables
4.5 Dynamic initialization of variables
4.6 Reference variables
4.7 Type Casting
4.7.1 Implicit conversion
4.7.2 Explicit conversion
4.8 Symbolic constants
4.8.1 const keyword
4.8.2 enum keyword
Summary
Review Questions
Chapter 5 Expressions and Control Structures
5.1 Expressions
5.1.1 Arithmetic Expressions
5.1.2 Relationnel Expressions
5.1.3 Logical Expressions
5.2 Evaluation of expressions
5.3 Precedence of arithmetic operators
5.4 Control Statements / Control Structure
5.4.1 Unconditional Statement
5.4.1.1 goto Statement
5.4.2 Decision – making statement
5.4.2.1Simple if statement
5.4.2.2 if…else Statement
5.4.2.3 Nested-if Statement
5.4.2.4 Switch Statement
5.4.3 Looping Statement/ Repetitive Statement
5.4.3.1 While loop
5.4.3.2 Do - while
5.4.3.3 for loop
5.4.4 Jump Statement
5.4.4.1 Break statement
5.4.4.2 Continue Statement
Summary
Review Questions
Chatper-6 Pointers and Arrays
6.1 Pointers
6.1.1 Advantages
6.1.2 Pointer declaration
6.1.3 Declaring and initializing pointers
6.1.4 Pointer operators
6.2 Pointer Arithmetic
6.3 Pointers and Arrays
6.4 Pointers and Strings
6.5 Pointers to Pointers
6.6 Pointers and Structures
6.7 Pointers to classes
6.8 this pointer
6.9 Pointers to Derived Classes
6.10 Arrays
6.10.1 Characteristics of Arrays
6.10.2 Classification of Arrays
6.10.2.1 One dimensional array
6.10.2.2 Two dimensional arrays
6.10.2.3 Multidimensional arrays
6.11 Arrays of Pointers
6.12 Arrays of Structures
6.13 Arrays within a Structure
6.14 Array of Classes
Summary
Review Questions
Chapter 7 Functions
7.1 Functions
7.1.1 Main ( ) Function
7.1.2 Parts of Functions
7.1.2.1 Function prototype
7.1.2.2 Function Definition
7.1.2.3 Calling a function
7.2 Formal and Actual arguments
7.2.1 Formal arguments
7.2.2 Actual arguments/ Passing arguments
7.3 Return Statement
7.4 Storage classes
7.4.1 Type of Storage Classes
7.5 Call by Value
7.6 Call by reference / Pass by reference
7.7 Return by reference
7.8 Default argument
7.8.1 Rules for declaring default argument
7.9 Constant argument
7.10 Inline Functions
7.11 Recursion
7.12 Function Overloading
7.12.1 Using different number of parameters/arguments
7.12.2 Using different type of argument / parameters
7.13 Rules of Function Overloading
Summary
Review Questions
Chapter 8 Class and Objects
8.1 Class
8.1.1 Specifying a class
8.2 Access Specifiers / Visibility Modifiers/ Access Control
8.3 Creating objects
8.4 Accessing Class members
8.5 Defining Member Functions
8.5.1 Defining member Functions inside the class
8.5.2 Defining member functions outside the class
8.6 Nesting of member functions
8.7 Private member functions
8.8 Static Data Members
8.9 Static Member Function
8.9.1 Rules of Static Member function
8.10 Arrays of Object
8.11 Friend Function
8.11.1 Characteristics of friend functions
8.12 Bit Fields and Classes
8.12.1 Bit Fields
8.12.2 Classes
Summary
Review Questions
Chapter 9 Constructors and Destructor
9.1 Constructors
9.2 Types of Constructor
9.2.1 Default Constructor
9.2.2 Parameterized Constructor
9.2.3 Copy Constructor
9.3 Dynamic Constructor
9.4 Default Arguments
9.5 Characteristics of Constructors
9.6 Constructors Overloading
9.7 Destructors
9.7.1Rules for destructor
Summary
Review Questions
Chapter 10 Operator Overloading
10.1 Operator Overloading
10.1.1 Defining operator overloading
10.2 Types of Operator Overloading
10.2.1 Overloading unary operator
10.2.2 Overloading Binary operator
10.3 Overloading binary operators using friend function
10.4 Manipulation of strings using operators
10.5 Rules of Operator Overloading
10.6 Type Conversions
10.6.1 Basic type to Class Type
10.6.2 Class type to Basic Type
10.6.3 Class type to Class Type
Summary
Review Questions
Chapter 11 Inheritance
11.1 Inheritance
11.1.1 Rules of Inheritance
11.1.2 Advantages of inheritance
11.1.3 Disadvantages of inheritance
11.2 Defining derived classes
11.3 Types of Inheritance
11.3.1 Single Inheritance
11.3.2 Multilevel Inheritance
11.3.3 Multiple Inheritance
11.3.4 Hierarchical Inheritance
11.3.5 Hybrid Inheritance
Summary
Review Questions
Chapter 12 Polymorphism
12.1 Introduction
2.2 Polymorphism
12.3 Virtual Functions
12.3.1 Rules for Virtual Functions
12.4 Pure Virtual Function
12.5 Virtual Base Class
12.6 Abstract Class
12.7 Binding
Summary
Review Questions
Chapter 13 File Management / Working with Files in C++
13.1 Files
13.2 Stream
13.2.1 Text file
13.2.2 Binary file
13.3 Classes for file stream operation
13.4 File Operations
13.4.1 Opening and closing a file
13.4.2 Writing and reading a file
13.5 Detecting end of a file / End of file detection
13.6 File modes
13.7 File Pointers and their manipulations
13.7.1 Manipulation of file pointer using functions
13.8 Sequential input and output operations
13.9 Updating a file
13.10 Errors handling during file operations
13.11 Command line arguments
Summary
Review Questions
Chapter 14 Templates
14.1 Templates
14.2 Class Template
14.3 Class template with multiple Parameter
14.4 Function Template
14.5Function Template with multiple parameters
14.6 Overloading of function template
14.7 Member Function Template
14.8 Non-Type Template Arguments
Summary
Review Questions
Chapter 15 Exception Handling
15.1 Basics of Exception Handling
15.2 Exception Handling Mechanism
15.2.1 Try block
15.2.2 Throwing Mechanism
15.2.3 Catching Mechanism
15.3 Multiple Catch Statements
15.4 Rethrowing an Exception
15.5 Specification of Exception
Summary
Review Questions
Chapter 16 Standard Template Library
16.1 The Standard Template Library
16.2 Manipulating Strings
Summary
Review Questions
APPENDIX A: Multiple Choice Questions
APPENDIX B: Questions and Answers in C++
APPENDIX C: Exercises
APPENDIX D: Past University Question Papers