C++PPT - Unit - I - 2022-23
C++PPT - Unit - I - 2022-23
UNIT - I
PREPARED BY
S. LAKSHMI, DEPT. OF COMPUTER APPLICATIONS
INTRODUCTION TO C++
It
was created by Bjarne Stroustrup at Bell Labs in
1983
CLASSES
DATA ABSTRACTION
DATA ENCAPSULATION
INHERITANCE
POLYMORPHISM
DYNAMIC BINDING
MESSAGE PASSING
OBJECTS &
CLASSES
Objects are the basic run time entities
Class declaration
Class function definitions
class class_name
{
private:
variable declarations;
Function declarations;
public:
variable declarations;
Function declarations;
};
DEFINING MEMBER FUNCTIONS
Member of function can be defined in two places:
Outside the class definition
Inside the class definition
Outside:
return – type class-name :: function-name (argument
declaration)
{
Function body
}
Example:
void item :: getdata(int a, float b)
{
number = a;
cost = b;
INSIDE THE CLASS
DEFINITION
class Item
{
int number;
float cost;
public:
void getdata(int a,float b); //declaration
//inline function
void putdata(void) // definition inside the class
{
cout<<number << “\n”;
cout<<cost << “\n”;
}
};
#include<iostream.h>
class MyClass
{ // The class
public: // Access specifier
int myNum; // Attribute (int variable)
string myString; // Attribute (string variable)
};
int main()
{
MyClass myObj; // Create an object of MyClass
2. Compiletime Polymorphism.
Example: Function Overloading,
Operator Overloading
DYNAMIC
BINDING
Its also known as late binding