c++ programming complete
c++ programming complete
VI SEMESTER
CO/PO PO01 PO02 PO03 PO04 PO05 PO06 PO07 PO08 PO09 PO10 PO11 PO12
CO1
3 - - - 2 - 2 - - 3 2
CO2
- 2 - - - 2 - - 3 - -
CO3
- - - 2 3 - - 3 - - 2 -
CO4
3 - 3 - - 3 3 - 3 - - 3
Department of Electrical and Electronics Engineering, BVCOE, New Delhi
4 Subject: C++ Programming , Instructor: Dr. Sandeep Sharma
UNIT 1
Review of C, Difference between C and C++, Procedure Oriented
and Object Oriented Approach. Basic Concepts: Objects, classes,
Principals like Abstraction, Encapsulation, Inheritance and
Polymorphism. Dynamic Binding, Message Passing. Characteristics of
Object-Oriented Languages. Abstract data types, Object & classes,
attributes, methods, C++ class declaration, Local Class and Global
Class, State identity and behaviour of an object, Local Object and
Global Object, Scope resolution operator, Friend Functions, Inline
functions, Constructors and destructors, instantiation of objects,
Types of Constructors, Static Class Data, Array of Objects, Constant
member functions and Objects, Memory management Operators.
Functions in C are not defined inside Functions can be used inside a structure in
structures. C++.
Namespace features are not present inside Namespace is used by C++, which avoid
the C. name collisions.
Reference variables are not supported by C. Reference variables are supported by C++.
Virtual and friend functions are not Virtual and friend functions are supported
supported by C. by C++.
C provides malloc() and calloc() functions C++ provides new operator for memory
for dynamic memory allocation, and free() allocation and delete operator for memory
for memory de-allocation. de-allocation.
Direct support for exception handling is not
Exception handling is supported by C++.
supported by C.
scanf() and printf() functions are used for cin and cout are used for input/output in
input/output in C. C++.
Abstract Data type (ADT) is a type (or class) for objects whose
behavior is defined by a set of values and a set of operations.
The definition of ADT only mentions what operations are to be
performed but not how these operations will be implemented.
It does not specify how data will be organized in memory and
what algorithms will be used for implementing the operations.
It is called “abstract” because it gives an implementation-
independent view.
The user of data type does not need to know how that data
type is implemented, for example, we have been using
Primitive values like int, float, char data types only with the
knowledge that these data type can operate and be
performed on without any idea of how they are
implemented.
So a user only needs to know what a data type can do, but
not how it will be implemented. Think of ADT as a black box
which hides the inner structure and design of the data type.
Now we’ll define three ADTs namely List ADT, Stack ADT,
Queue ADT.
// Driver Code
int main() { return 0; }
State:
Definition: For any given moment, the state of an object is formed from its
characteristics.
Example: The state of ‘car’ can include properties like color, speed, fuel level and
present gear.
Behavior:
Definition: This is a terminology that refers to the actions or methods that are
performed by an object. They describe how the given object relates with others or its
environment.
Example: Behaviors for cars can include accelerate, brake, changeGear, turnLeft.
Identity:
Definition: An object’s identity is what separates it from other objects. It helps
differentiate between multiple instances of the same class in the system.
Example: Every car on the road has certain unique identity such as a license plate
number or Vehicle Identification Number (VIN).
To access a global variable when there is a local variable with same name:
// C++ program to show that we can access a global variable
// using scope resolution operator :: when there is a local
// variable with same name
#include<iostream>
using namespace std;
int x; // Global x
int main()
{
int x = 10; // Local x
cout << "Value of global x is " << ::x;
cout << "\nValue of local x is " << x;
return 0;
}
class A {
public:
// Only declaration
void fun();
};
int main()
{
A a;
a.fun();
return 0;
}
•If you use too many inline functions then the size of the binary executable
file will be large, because of the duplication of the same code.
•Too much inlining can also reduce your instruction cache hit rate, thus
reducing the speed of instruction fetch from that of cache memory to that
of primary memory.
•The inline function may increase compile time overhead if someone
changes the code inside the inline function then all the calling location has
to be recompiled because the compiler would be required to replace all
the code once again to reflect the changes, otherwise it will continue with
old functionality.