SlideShare a Scribd company logo
Classes & Objects
Chap 5
3/11/2016 1By:-Gourav Kottawar
Contents
5.1 A Sample C++ Program with class
5.2 Access specifies
5.3 Defining Member Functions
5.4 Making an Outside Function Inline
5.5 Nesting of Member Functions
5.6 Private Member Functions
5.7 Arrays within a Class
5.8 Memory Allocation for Objects
5.9 Static Data Members, Static Member
5.10 Functions, Arrays of Objects
5.11 Object as Function Arguments
5.12 Friend Functions, Returning Objects,
5.13 Const member functions
5.14 Pointer to Members, Local Classes
5.15 Object composition & delegation
3/11/2016 2By:-Gourav Kottawar
Declaring Class
 Syntax –
class class_name
{
private :
variable declaration;
function declaration;
public:
variable declaration;
function declaration;
}
3/11/2016 3By:-Gourav Kottawar
Data hiding in classes
3/11/2016 4By:-Gourav Kottawar
Simple class program
Creating objects
Accessing class members
 Access specifies
private
public
protector
default - private
 5.3 Defining Member Functions
3/11/2016 5By:-Gourav Kottawar
5.4 Making an Outside Function Inline
class item
{
......
......
public:
void getdata(int a,float b);
};
inline void item :: getdata(int a,float b)
{
number=a;
cost=b;
}
3/11/2016 6By:-Gourav Kottawar
5.5 Nesting of Member Functions
#include<iostream.h>
#include<conio.h>
class data
{
int rollno,maths,science;
int avg();
public: void getdata();
void putdata();
};
main()
{
clrscr();
data stud[5];
for(int i=0;i<5;i++)
stud[i].getdata();
}
void data::getdata()
{
cout<<"Please enter rollno:";
cin>>rollno;
cout<<"Please enter maths marks:";
cin>>maths;
cout<<"Please enter science marks:";
cin>>science;
putdata();
}
int data::avg()
{
int a; a=(maths+science)/2;
return a;
}
void data::putdata()
{
cout<<"Average is :"<<avg()<<endl;
}
3/11/2016 7By:-Gourav Kottawar
5.7 Arrays within a Class
const int size=10;
class array
{
int a[size];
public:
void setval(void);
void display(void);
};
3/11/2016 8By:-Gourav Kottawar
Ex-
#include<iostream>
#include<string>
using namespace std;
const int val=50;
class ITEM
{
private:
int item_code[val];
int item_price[val];
int count;
public:
void initiliaze();
void get_item();
void display_item();
void display_sum();
void remove();
};
void ITEM::initiliaze()
{
count=0;
}
void ITEM::get_item()
{
cout<<"Enter the Item code == "<<endl;
cin>>item_code[count];
cout<<"Enter the Item cost == "<<endl;
cin>>item_price[count];
count++;
}
void ITEM::display_sum()
{
int sum=0;
for(int i=0; i<count;i++)
{
sum=sum + item_price[i];
}
cout<<"The Total Value Of The Cost Is ==
"<<sum<<endl;
}
3/11/2016 9By:-Gourav Kottawar
void ITEM::display_item()
{
cout<<"nCode Pricen";
for(int k=0;k<count;k++)
{
cout<<"n"<<item_code[k];
cout<<" "<<item_price[k];
}
}
void ITEM::remove()
{
int del;
cout<<"Enter the code you want to remove == ";
cin>>del;
for(int search=0; search<count; search++)
{
if(del == item_code[search])
{
item_price[search]=0;
item_code[search]=0;
}
}
}
3/11/2016 10By:-Gourav Kottawar
int main()
{
ITEM order;
order.initiliaze();
int x;
do
{
cout<<"nnYou have the following opton";
cout<<"nEnter the Appropriate number";
cout<<"nnPress 1 for ADD AN ITEMS";
cout<<"nnPress 2 for DISPLAY TOTAL
VALUE";
cout<<"nnPress 3 for DELETE AN
ITEM";
cout<<"nnPress 4 for DISPLAY ALL
ITEMS";
cout<<"nnPress 5 for QUIT";
cout<<"nEnter The Desired Number ==
n";
cin>>x;
switch(x)
{
case 1:
{
order.get_item();
break;
}
case 2:
{
order.display_sum();
break;
}
case 3:
{
order.remove();
break;
}
case 4:
{
order.display_item();
break;
}
3/11/2016 11By:-Gourav Kottawar
case 5:
break;
default: cout<<"Incorrect option Please
Press the right number == ";
}
}while(x!=5);
getchar();
return 0;
}
3/11/2016 12By:-Gourav Kottawar
5.8 Memory Allocation for Objects
common for all objects
member function 1
member function 2 memory created when
function defined
Object 1 object 2 object 3
Member varible 1 member variable 2 member
variable 1
Member variable 2 member variable 2 member variable 2
memory created
when objects defined
3/11/2016 13By:-Gourav Kottawar
5.9 Static Data Members, Static Member
 A data member of a class can be
qualified as static.
 The properties of a static member
variable are similar to that of a C static
variable.
 It is initialized to zero when the first
object of its class is created. No other
initialization is permitted.
 Only one copy of that member is created
for the entire class and is shared by all
the objects of that class, no matter how
many objects are created.
 It is visible only within the class, but its
lifetime is the entire program.
3/11/2016 14By:-Gourav Kottawar
#include
using namespace std;
class item
{
static int count;
int number;
public:
void getdata(int a)
{
number = a;
count ++;
}
void getcount(void)
{
cout << "Count: ";
cout << count <<"n";
}
};
int item :: count;
int main()
{
item a,b,c;
a.getcount();
b.getcount();
c.getcount();
a.getdata(100);
b.getdata(200);
c.getdata(300);
cout << "After reading
data"<<"n";
a.getcount();
b.getcount();
c.getcount();
return 0;
}
3/11/2016 15By:-Gourav Kottawar
#include
using namespace std;
class item
{
static int count;
int number;
public:
void getdata(int a)
{
number = a;
count ++;
}
void getcount(void)
{
cout << "Count: ";
cout << count <<"n";
}
};
int item :: count;
int main()
{
item a,b,c;
a.getcount();
b.getcount();
c.getcount();
a.getdata(100);
b.getdata(200);
c.getdata(300);
cout << "After reading
data"<<"n";
a.getcount();
b.getcount();
c.getcount();
return 0;
}
The output of
the program
would be:
Count: 0
Count: 0
Count: 0
After reading
data
Count: 3
Count: 3
Count: 3
3/11/2016 16By:-Gourav Kottawar
Sharing of a static data
member
3/11/2016 17By:-Gourav Kottawar
Static member function
 A member function that is declared
static has following properties
1. A static function can have access to
only other static members (functions
or variables) declared in the same
class.
2. A static member function can be
called using the class name (instead
of its objects ) as follows :
class – name :: function – name;3/11/2016 18By:-Gourav Kottawar
3/11/2016 19
class Something
{
private:
static int s_nValue;
public:
static int GetValue() { return s_nValue; }
};
int Something::s_nValue = 1; // initializer
int main()
{
std::cout << Something::GetValue() <<
std::endl;
}
By:-Gourav Kottawar
3/11/2016 20
class IDGenerator
{
private:
static int s_nNextID;
public:
static int GetNextID() { return
s_nNextID++; }
};
// We'll start generating IDs at 1
int IDGenerator::s_nNextID = 1;
int main()
{
for (int i=0; i < 5; i++)
cout << "The next ID is: " <<
IDGenerator::GetNextID() << endl;
return 0;
}
The next ID is: 1
The next ID is: 2
The next ID is: 3
The next ID is: 4
The next ID is: 5
By:-Gourav Kottawar
3/11/2016 21
class IDGenerator
{
private:
static int s_nNextID;
public:
static int GetNextID() { return s_nNextID++; }
};
// We'll start generating IDs at 1
int IDGenerator::s_nNextID = 1;
int main()
{
for (int i=0; i < 5; i++)
cout << "The next ID is: " << IDGenerator::GetNextID() <<
endl;
return 0;
}
By:-Gourav Kottawar
Array of object
3/11/2016 22By:-Gourav Kottawar
5.11 Object as Function Arguments
 Two ways
1. A copy of the entire object is passed
to the function.
i.e. pass by value
2. Only the address of the object is
transferred to the function
i.e. pass by reference
3/11/2016 23By:-Gourav Kottawar
3/11/2016 24By:-Gourav Kottawar
3/11/2016 25
#include <iostream>
using namespace std;
class Complex
{
private: int real;
int imag;
public:
void Read()
{
cout<<"Enter real and imaginary number
respectively:"<<endl; cin>>real>>imag;
}
void Add(Complex comp1,Complex comp2)
{
real=comp1.real+comp2.real;
/* Here, real represents the real data of object c3 because this function is
called using code c3.add(c1,c2); */
imag=comp1.imag+comp2.imag;
/* Here, imag represents the imag data of object c3 because this function
is called using code c3.add(c1,c2); */
}
By:-Gourav Kottawar
3/11/2016 26
void Display()
{
cout<<"Sum="<<real<<"+"<<imag<<"i";
}
};
int main()
{
Complex c1,c2,c3;
c1.Read();
c2.Read();
c3.Add(c1,c2);
c3.Display();
return 0;
}
By:-Gourav Kottawar
Returning Object from Function
3/11/2016 27By:-Gourav Kottawar
3/11/2016 28
#include <iostream>
using namespace std;
class Complex
{
private: int real;
int imag;
public: void Read()
{
cout<<"Enter real and imaginary number respectively:"<<endl;
cin>>real>>imag;
}
Complex Add(Complex comp2)
{
Complex temp;
temp.real=real+comp2.real;
/* Here, real represents the real data of object c1 because this
function is called using code c1.Add(c2) */
temp.imag=imag+comp2.imag;
/* Here, imag represents the imag data of object c1 because this
function is called using code c1.Add(c2) */
return temp; 0;
} By:-Gourav Kottawar
3/11/2016 29
}
void Display()
{
cout<<"Sum="<<real<<"+"<<ima
g<<"i"; }
};
int main()
{
Complex c1,c2,c3;
c1.Read();
c2.Read();
c3=c1.Add(c2);
c3.Display();
return 0;
}
By:-Gourav Kottawar
5.12 Friend function
 Need
a data is declared as private inside a
class, then it is not accessible from
outside the class.
A function that is not a member or an
external class will not be able to access
the private data.
A programmer may have a situation
where he or she would need to access
private data from non-member functions
and external classes. For handling such
cases, the concept of Friend functions is
a useful tool.
3/11/2016 30By:-Gourav Kottawar
5.12 Friend function
What is a Friend Function?
 A friend function is used for accessing
the non-public members of a class.
 A class can allow non-
member functions and other classes to
access its own private data, by making
them friends.
 Thus, a friend function is an ordinary
function or a member of another class.
3/11/2016 31By:-Gourav Kottawar
5.12 Friend function
 General syntax
Class ABC
{
…..
…..
public :
…..
…..
Friend void func1(void);
};
3/11/2016 32By:-Gourav Kottawar
5.12 Friend function
Special Characteristics
 The keyword friend is placed only in the function declaration
of the friend function and not in the function definition.
 It is not in the scope of the class to which it has been declared
as friend.
 It is possible to declare a function as friend in any number of
classes.
 When a class is declared as a friend, the friend class has access
to the private data of the class that made this a friend.
 A friend function, even though it is not a member function,
would have the rights to access the private members of the
class.
 It is possible to declare the friend function as either private or
public without affecting meaning.
 The function can be invoked without the use of an object.
 It has object as argument.
3/11/2016 33By:-Gourav Kottawar
3/11/2016 34
#include <iostream>
using namespace std;
class exforsys
{
private:
int a,b;
public:
void test()
{
a=100;
b=200;
}
friend int compute(exforsys e1);
//Friend Function
Declaration with keyword friend and
with the object of class exforsys to
which it is friend passed to it
};
int compute(exforsys e1)
{
//Friend Function Definition
which has access to private data
return int(e1.a+e1.b)-5;
}
void main()
{
exforsys e;
e.test();
cout << "The result is:" <<
compute(e);
//Calling of Friend
Function with object as argument.
}
By:-Gourav Kottawar
Constant Member Functions
 Declaring a member function with
the const keyword specifies that the
function is a "read-only" function that
does not modify the object for which it is
called.
 A constantmember function cannot
modify any non-static data members or
call any member functions that aren't
constant.
 The const keyword is required in both the
declaration and the definition.
3/11/2016 35By:-Gourav Kottawar
Constant Member Functions –
EXclass Date
{
public:
Date( int mn, int dy, int yr );
int getMonth() const; // A
read-only function
void setMonth( int mn ); // A
write function; can't be const
private:
int month;
};
int Date::getMonth() const
{
return month; // Doesn't
modify anything
}
3/11/2016 36
void Date::setMonth( int mn )
{
month = mn; // Modifies data
member
}
int main()
{
Date MyDate( 7, 4, 1998 );
const Date BirthDate( 1, 18, 1953
); MyDate.setMonth( 4 ); // Okay
BirthDate.getMonth(); // Okay
BirthDate.setMonth( 4 ); // C2662
Error
}
By:-Gourav Kottawar
5.14 Pointers to members
 Pointers to members allow you to refer to nonstatic
members of class objects.
 You cannot use a pointer to member to point to a static
class member because the address of a static member is
not associated with any particular object.
 To point to a static class member, you must use a
normal pointer.
 You can use pointers to member functions in the same
manner as pointers to functions.
 You can compare pointers to member functions, assign
values to them, and use them to call member functions.
 Note - a member function does not have the same type
as a nonmember function that has the same number
and type of arguments and the same return type.
3/11/2016 37By:-Gourav Kottawar
5.14 Pointers to members - Ex
#include <iostream>
using namespace std;
class X
{
public:
int a;
void f(int b)
{
cout << "The value of b is
"<< b << endl;
}
};
3/11/2016 38
int main()
{
// declare pointer to data member
int X::*ptiptr = &X::a;
// declare a pointer to member
function
void (X::* ptfptr) (int) = &X::f;
// create an object of class type X
X xobject;
// initialize data member
xobject.*ptiptr = 10;
cout << "The value of a is " <<
xobject.*ptiptr << endl;
// call member function
(xobject.*ptfptr) (20);
}
By:-Gourav Kottawar
5.14 Local Classes
 A local class is declared within a function
definition.
 Declarations in a local class can only use type
names, enumerations, static variables from the
enclosing scope, as well as external variables and
functions.
 Member functions of a local class have to be
defined within their class definition, if they are
defined at all.
 As a result, member functions of a local class are
inline functions. Like all member functions, those
defined within the scope of a local class do not need
the keyword inline.
3/11/2016 39By:-Gourav Kottawar
3/11/2016 40
int x; // global variable
void f() // function definition
{
static int y; // static variable y can be used by local class
int x; // auto variable x cannot be used by local class
extern int g(); // extern function g can be used by local class
class local // local class
{
int g() { return x; } // error, local variable x
// cannot be used by g
int h() { return y; } // valid,static variable y
int k() { return ::x; } // valid, global x
int l() { return g(); } // valid, extern function g
};
}
int main()
{
local* z; // error: the class local is not
visible
// ...}
By:-Gourav Kottawar
3/11/2016 41
A local class cannot have static data members.
void f()
{
class local
{
int f(); // error, local class has noninline
// member function
int g() {return 0;} // valid, inline member
function
static int a; // error, static is not allowed for //
local class
int b; // valid, nonstatic variable
};
} // . . .
By:-Gourav Kottawar

More Related Content

What's hot (19)

Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]
Devon Bernard
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
Iram Ramrajkar
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
Fahad Shaikh
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
Rodica Dada
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Fabio Collini
 
Best Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIBest Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part II
ICS
 
Managing parallelism using coroutines
Managing parallelism using coroutinesManaging parallelism using coroutines
Managing parallelism using coroutines
Fabio Collini
 
The zen of async: Best practices for best performance
The zen of async: Best practices for best performanceThe zen of async: Best practices for best performance
The zen of async: Best practices for best performance
Microsoft Developer Network (MSDN) - Belgium and Luxembourg
 
Why Sifu
Why SifuWhy Sifu
Why Sifu
LambdaWorks
 
Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)
RichardWarburton
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community conf
Fabio Collini
 
GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0
Tobias Meixner
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose world
Fabio Collini
 
SISTEMA DE FACTURACION (Ejemplo desarrollado)
SISTEMA DE FACTURACION (Ejemplo desarrollado)SISTEMA DE FACTURACION (Ejemplo desarrollado)
SISTEMA DE FACTURACION (Ejemplo desarrollado)
Darwin Durand
 
Droidjam 2019 flutter isolates pdf
Droidjam 2019 flutter isolates pdfDroidjam 2019 flutter isolates pdf
Droidjam 2019 flutter isolates pdf
Anvith Bhat
 
Testing Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UKTesting Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UK
Fabio Collini
 
FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.
UA Mobile
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
go_oh
 
The art of reverse engineering flash exploits
The art of reverse engineering flash exploitsThe art of reverse engineering flash exploits
The art of reverse engineering flash exploits
Priyanka Aash
 
Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]Lean React - Patterns for High Performance [ploneconf2017]
Lean React - Patterns for High Performance [ploneconf2017]
Devon Bernard
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
Fahad Shaikh
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Fabio Collini
 
Best Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIBest Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part II
ICS
 
Managing parallelism using coroutines
Managing parallelism using coroutinesManaging parallelism using coroutines
Managing parallelism using coroutines
Fabio Collini
 
Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)
RichardWarburton
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community conf
Fabio Collini
 
GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0
Tobias Meixner
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose world
Fabio Collini
 
SISTEMA DE FACTURACION (Ejemplo desarrollado)
SISTEMA DE FACTURACION (Ejemplo desarrollado)SISTEMA DE FACTURACION (Ejemplo desarrollado)
SISTEMA DE FACTURACION (Ejemplo desarrollado)
Darwin Durand
 
Droidjam 2019 flutter isolates pdf
Droidjam 2019 flutter isolates pdfDroidjam 2019 flutter isolates pdf
Droidjam 2019 flutter isolates pdf
Anvith Bhat
 
Testing Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UKTesting Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UK
Fabio Collini
 
FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.
UA Mobile
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
go_oh
 
The art of reverse engineering flash exploits
The art of reverse engineering flash exploitsThe art of reverse engineering flash exploits
The art of reverse engineering flash exploits
Priyanka Aash
 

Viewers also liked (18)

Strengthening the environment for web entrepreneurs in europe 22 november 2011
Strengthening the environment for web entrepreneurs in europe 22 november 2011Strengthening the environment for web entrepreneurs in europe 22 november 2011
Strengthening the environment for web entrepreneurs in europe 22 november 2011
IAMCP MENTORING
 
Interview
InterviewInterview
Interview
Vikaash Thakur
 
Lesson4humanimpactonbiosphere
Lesson4humanimpactonbiosphereLesson4humanimpactonbiosphere
Lesson4humanimpactonbiosphere
sarah marks
 
Holly Molly catalogo inv2015 precios x menor
Holly Molly catalogo inv2015   precios x menorHolly Molly catalogo inv2015   precios x menor
Holly Molly catalogo inv2015 precios x menor
Mariana Duche
 
The Factors Affecting the Location of Foreign Direct Investment by U.S. Compa...
The Factors Affecting the Location of Foreign Direct Investment by U.S. Compa...The Factors Affecting the Location of Foreign Direct Investment by U.S. Compa...
The Factors Affecting the Location of Foreign Direct Investment by U.S. Compa...
Brent Alexander Newton, JD, CPA, MAc
 
個資法 - 資料就是財富
個資法 - 資料就是財富個資法 - 資料就是財富
個資法 - 資料就是財富
ChrisChenTw
 
Empirical Reasearch Project
Empirical Reasearch ProjectEmpirical Reasearch Project
Empirical Reasearch Project
Emerald J Kleespies
 
International experience in REC mechanismmr
International experience in REC mechanismmrInternational experience in REC mechanismmr
International experience in REC mechanismmr
Anuj Kaushik
 
σκληρός+δ..
σκληρός+δ..σκληρός+δ..
σκληρός+δ..
giota89
 
A
AA
A
dinanurfadhilah
 
Sun Web Server Brief
Sun Web Server BriefSun Web Server Brief
Sun Web Server Brief
Murthy Chintalapati
 
Commscope-Andrew ATBT-S522
Commscope-Andrew ATBT-S522Commscope-Andrew ATBT-S522
Commscope-Andrew ATBT-S522
savomir
 
แจ้งผลการประชุม ก.จ. ก.ท. และ ก.อบต. ครั้งที่ 10/2559 เมื่อวันที่ 28 ตุลาคม 2559
แจ้งผลการประชุม ก.จ. ก.ท. และ ก.อบต. ครั้งที่ 10/2559 เมื่อวันที่ 28 ตุลาคม 2559แจ้งผลการประชุม ก.จ. ก.ท. และ ก.อบต. ครั้งที่ 10/2559 เมื่อวันที่ 28 ตุลาคม 2559
แจ้งผลการประชุม ก.จ. ก.ท. และ ก.อบต. ครั้งที่ 10/2559 เมื่อวันที่ 28 ตุลาคม 2559
ประพันธ์ เวารัมย์
 
3Com 3C17224-RE
3Com 3C17224-RE3Com 3C17224-RE
3Com 3C17224-RE
savomir
 
1 news item
1 news item1 news item
1 news item
Novi Yanti
 
What is technology
What is technologyWhat is technology
What is technology
Gambari Isiaka
 
Strengthening the environment for web entrepreneurs in europe 22 november 2011
Strengthening the environment for web entrepreneurs in europe 22 november 2011Strengthening the environment for web entrepreneurs in europe 22 november 2011
Strengthening the environment for web entrepreneurs in europe 22 november 2011
IAMCP MENTORING
 
Lesson4humanimpactonbiosphere
Lesson4humanimpactonbiosphereLesson4humanimpactonbiosphere
Lesson4humanimpactonbiosphere
sarah marks
 
Holly Molly catalogo inv2015 precios x menor
Holly Molly catalogo inv2015   precios x menorHolly Molly catalogo inv2015   precios x menor
Holly Molly catalogo inv2015 precios x menor
Mariana Duche
 
The Factors Affecting the Location of Foreign Direct Investment by U.S. Compa...
The Factors Affecting the Location of Foreign Direct Investment by U.S. Compa...The Factors Affecting the Location of Foreign Direct Investment by U.S. Compa...
The Factors Affecting the Location of Foreign Direct Investment by U.S. Compa...
Brent Alexander Newton, JD, CPA, MAc
 
個資法 - 資料就是財富
個資法 - 資料就是財富個資法 - 資料就是財富
個資法 - 資料就是財富
ChrisChenTw
 
International experience in REC mechanismmr
International experience in REC mechanismmrInternational experience in REC mechanismmr
International experience in REC mechanismmr
Anuj Kaushik
 
σκληρός+δ..
σκληρός+δ..σκληρός+δ..
σκληρός+δ..
giota89
 
Commscope-Andrew ATBT-S522
Commscope-Andrew ATBT-S522Commscope-Andrew ATBT-S522
Commscope-Andrew ATBT-S522
savomir
 
แจ้งผลการประชุม ก.จ. ก.ท. และ ก.อบต. ครั้งที่ 10/2559 เมื่อวันที่ 28 ตุลาคม 2559
แจ้งผลการประชุม ก.จ. ก.ท. และ ก.อบต. ครั้งที่ 10/2559 เมื่อวันที่ 28 ตุลาคม 2559แจ้งผลการประชุม ก.จ. ก.ท. และ ก.อบต. ครั้งที่ 10/2559 เมื่อวันที่ 28 ตุลาคม 2559
แจ้งผลการประชุม ก.จ. ก.ท. และ ก.อบต. ครั้งที่ 10/2559 เมื่อวันที่ 28 ตุลาคม 2559
ประพันธ์ เวารัมย์
 
3Com 3C17224-RE
3Com 3C17224-RE3Com 3C17224-RE
3Com 3C17224-RE
savomir
 
Ad

Similar to classes & objects in cpp overview (20)

class c++
class c++class c++
class c++
vinay chauhan
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Class object
Class objectClass object
Class object
Dr. Anand Bihari
 
Classes in C++ computer language presentation.ppt
Classes in C++ computer language presentation.pptClasses in C++ computer language presentation.ppt
Classes in C++ computer language presentation.ppt
AjayLobo1
 
classes & objects.ppt
classes & objects.pptclasses & objects.ppt
classes & objects.ppt
BArulmozhi
 
Class and object
Class and objectClass and object
Class and object
prabhat kumar
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
Durga Devi
 
APL-2-classes and objects.ppt
APL-2-classes and objects.pptAPL-2-classes and objects.ppt
APL-2-classes and objects.ppt
srividyal2
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
Introduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesIntroduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book Notes
DSMS Group of Institutes
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
Vineeta Garg
 
APL-2-classes and objects.ppt data structures using c++
APL-2-classes and objects.ppt data structures using c++APL-2-classes and objects.ppt data structures using c++
APL-2-classes and objects.ppt data structures using c++
ProfLSrividya
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Kamal Acharya
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Marlom46
 
static member and static member fumctions.ppt
static member and static member fumctions.pptstatic member and static member fumctions.ppt
static member and static member fumctions.ppt
poojitsaid2021
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Anil Kumar
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
Praveen M Jigajinni
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOP
Amrit Kaur
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
nafisa rahman
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Classes in C++ computer language presentation.ppt
Classes in C++ computer language presentation.pptClasses in C++ computer language presentation.ppt
Classes in C++ computer language presentation.ppt
AjayLobo1
 
classes & objects.ppt
classes & objects.pptclasses & objects.ppt
classes & objects.ppt
BArulmozhi
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
Durga Devi
 
APL-2-classes and objects.ppt
APL-2-classes and objects.pptAPL-2-classes and objects.ppt
APL-2-classes and objects.ppt
srividyal2
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
Introduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesIntroduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book Notes
DSMS Group of Institutes
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
Vineeta Garg
 
APL-2-classes and objects.ppt data structures using c++
APL-2-classes and objects.ppt data structures using c++APL-2-classes and objects.ppt data structures using c++
APL-2-classes and objects.ppt data structures using c++
ProfLSrividya
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Marlom46
 
static member and static member fumctions.ppt
static member and static member fumctions.pptstatic member and static member fumctions.ppt
static member and static member fumctions.ppt
poojitsaid2021
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Anil Kumar
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOP
Amrit Kaur
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
nafisa rahman
 
Ad

More from gourav kottawar (20)

operator overloading & type conversion in cpp
operator overloading & type conversion in cppoperator overloading & type conversion in cpp
operator overloading & type conversion in cpp
gourav kottawar
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
gourav kottawar
 
classes & objects in cpp
classes & objects in cppclasses & objects in cpp
classes & objects in cpp
gourav kottawar
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
gourav kottawar
 
basics of c++
basics of c++basics of c++
basics of c++
gourav kottawar
 
working file handling in cpp overview
working file handling in cpp overviewworking file handling in cpp overview
working file handling in cpp overview
gourav kottawar
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpp
gourav kottawar
 
exception handling in cpp
exception handling in cppexception handling in cpp
exception handling in cpp
gourav kottawar
 
cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basics
gourav kottawar
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
gourav kottawar
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
gourav kottawar
 
basics of c++
basics of c++basics of c++
basics of c++
gourav kottawar
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
gourav kottawar
 
SQL || overview and detailed information about Sql
SQL || overview and detailed information about SqlSQL || overview and detailed information about Sql
SQL || overview and detailed information about Sql
gourav kottawar
 
SQL querys in detail || Sql query slides
SQL querys in detail || Sql query slidesSQL querys in detail || Sql query slides
SQL querys in detail || Sql query slides
gourav kottawar
 
Rrelational algebra in dbms overview
Rrelational algebra in dbms overviewRrelational algebra in dbms overview
Rrelational algebra in dbms overview
gourav kottawar
 
overview of database concept
overview of database conceptoverview of database concept
overview of database concept
gourav kottawar
 
Relational Model in dbms & sql database
Relational Model in dbms & sql databaseRelational Model in dbms & sql database
Relational Model in dbms & sql database
gourav kottawar
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
gourav kottawar
 
security and privacy in dbms and in sql database
security and privacy in dbms and in sql databasesecurity and privacy in dbms and in sql database
security and privacy in dbms and in sql database
gourav kottawar
 
operator overloading & type conversion in cpp
operator overloading & type conversion in cppoperator overloading & type conversion in cpp
operator overloading & type conversion in cpp
gourav kottawar
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
gourav kottawar
 
classes & objects in cpp
classes & objects in cppclasses & objects in cpp
classes & objects in cpp
gourav kottawar
 
working file handling in cpp overview
working file handling in cpp overviewworking file handling in cpp overview
working file handling in cpp overview
gourav kottawar
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpp
gourav kottawar
 
exception handling in cpp
exception handling in cppexception handling in cpp
exception handling in cpp
gourav kottawar
 
cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basics
gourav kottawar
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
gourav kottawar
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
gourav kottawar
 
SQL || overview and detailed information about Sql
SQL || overview and detailed information about SqlSQL || overview and detailed information about Sql
SQL || overview and detailed information about Sql
gourav kottawar
 
SQL querys in detail || Sql query slides
SQL querys in detail || Sql query slidesSQL querys in detail || Sql query slides
SQL querys in detail || Sql query slides
gourav kottawar
 
Rrelational algebra in dbms overview
Rrelational algebra in dbms overviewRrelational algebra in dbms overview
Rrelational algebra in dbms overview
gourav kottawar
 
overview of database concept
overview of database conceptoverview of database concept
overview of database concept
gourav kottawar
 
Relational Model in dbms & sql database
Relational Model in dbms & sql databaseRelational Model in dbms & sql database
Relational Model in dbms & sql database
gourav kottawar
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
gourav kottawar
 
security and privacy in dbms and in sql database
security and privacy in dbms and in sql databasesecurity and privacy in dbms and in sql database
security and privacy in dbms and in sql database
gourav kottawar
 

Recently uploaded (20)

TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 

classes & objects in cpp overview

  • 1. Classes & Objects Chap 5 3/11/2016 1By:-Gourav Kottawar
  • 2. Contents 5.1 A Sample C++ Program with class 5.2 Access specifies 5.3 Defining Member Functions 5.4 Making an Outside Function Inline 5.5 Nesting of Member Functions 5.6 Private Member Functions 5.7 Arrays within a Class 5.8 Memory Allocation for Objects 5.9 Static Data Members, Static Member 5.10 Functions, Arrays of Objects 5.11 Object as Function Arguments 5.12 Friend Functions, Returning Objects, 5.13 Const member functions 5.14 Pointer to Members, Local Classes 5.15 Object composition & delegation 3/11/2016 2By:-Gourav Kottawar
  • 3. Declaring Class  Syntax – class class_name { private : variable declaration; function declaration; public: variable declaration; function declaration; } 3/11/2016 3By:-Gourav Kottawar
  • 4. Data hiding in classes 3/11/2016 4By:-Gourav Kottawar
  • 5. Simple class program Creating objects Accessing class members  Access specifies private public protector default - private  5.3 Defining Member Functions 3/11/2016 5By:-Gourav Kottawar
  • 6. 5.4 Making an Outside Function Inline class item { ...... ...... public: void getdata(int a,float b); }; inline void item :: getdata(int a,float b) { number=a; cost=b; } 3/11/2016 6By:-Gourav Kottawar
  • 7. 5.5 Nesting of Member Functions #include<iostream.h> #include<conio.h> class data { int rollno,maths,science; int avg(); public: void getdata(); void putdata(); }; main() { clrscr(); data stud[5]; for(int i=0;i<5;i++) stud[i].getdata(); } void data::getdata() { cout<<"Please enter rollno:"; cin>>rollno; cout<<"Please enter maths marks:"; cin>>maths; cout<<"Please enter science marks:"; cin>>science; putdata(); } int data::avg() { int a; a=(maths+science)/2; return a; } void data::putdata() { cout<<"Average is :"<<avg()<<endl; } 3/11/2016 7By:-Gourav Kottawar
  • 8. 5.7 Arrays within a Class const int size=10; class array { int a[size]; public: void setval(void); void display(void); }; 3/11/2016 8By:-Gourav Kottawar
  • 9. Ex- #include<iostream> #include<string> using namespace std; const int val=50; class ITEM { private: int item_code[val]; int item_price[val]; int count; public: void initiliaze(); void get_item(); void display_item(); void display_sum(); void remove(); }; void ITEM::initiliaze() { count=0; } void ITEM::get_item() { cout<<"Enter the Item code == "<<endl; cin>>item_code[count]; cout<<"Enter the Item cost == "<<endl; cin>>item_price[count]; count++; } void ITEM::display_sum() { int sum=0; for(int i=0; i<count;i++) { sum=sum + item_price[i]; } cout<<"The Total Value Of The Cost Is == "<<sum<<endl; } 3/11/2016 9By:-Gourav Kottawar
  • 10. void ITEM::display_item() { cout<<"nCode Pricen"; for(int k=0;k<count;k++) { cout<<"n"<<item_code[k]; cout<<" "<<item_price[k]; } } void ITEM::remove() { int del; cout<<"Enter the code you want to remove == "; cin>>del; for(int search=0; search<count; search++) { if(del == item_code[search]) { item_price[search]=0; item_code[search]=0; } } } 3/11/2016 10By:-Gourav Kottawar
  • 11. int main() { ITEM order; order.initiliaze(); int x; do { cout<<"nnYou have the following opton"; cout<<"nEnter the Appropriate number"; cout<<"nnPress 1 for ADD AN ITEMS"; cout<<"nnPress 2 for DISPLAY TOTAL VALUE"; cout<<"nnPress 3 for DELETE AN ITEM"; cout<<"nnPress 4 for DISPLAY ALL ITEMS"; cout<<"nnPress 5 for QUIT"; cout<<"nEnter The Desired Number == n"; cin>>x; switch(x) { case 1: { order.get_item(); break; } case 2: { order.display_sum(); break; } case 3: { order.remove(); break; } case 4: { order.display_item(); break; } 3/11/2016 11By:-Gourav Kottawar
  • 12. case 5: break; default: cout<<"Incorrect option Please Press the right number == "; } }while(x!=5); getchar(); return 0; } 3/11/2016 12By:-Gourav Kottawar
  • 13. 5.8 Memory Allocation for Objects common for all objects member function 1 member function 2 memory created when function defined Object 1 object 2 object 3 Member varible 1 member variable 2 member variable 1 Member variable 2 member variable 2 member variable 2 memory created when objects defined 3/11/2016 13By:-Gourav Kottawar
  • 14. 5.9 Static Data Members, Static Member  A data member of a class can be qualified as static.  The properties of a static member variable are similar to that of a C static variable.  It is initialized to zero when the first object of its class is created. No other initialization is permitted.  Only one copy of that member is created for the entire class and is shared by all the objects of that class, no matter how many objects are created.  It is visible only within the class, but its lifetime is the entire program. 3/11/2016 14By:-Gourav Kottawar
  • 15. #include using namespace std; class item { static int count; int number; public: void getdata(int a) { number = a; count ++; } void getcount(void) { cout << "Count: "; cout << count <<"n"; } }; int item :: count; int main() { item a,b,c; a.getcount(); b.getcount(); c.getcount(); a.getdata(100); b.getdata(200); c.getdata(300); cout << "After reading data"<<"n"; a.getcount(); b.getcount(); c.getcount(); return 0; } 3/11/2016 15By:-Gourav Kottawar
  • 16. #include using namespace std; class item { static int count; int number; public: void getdata(int a) { number = a; count ++; } void getcount(void) { cout << "Count: "; cout << count <<"n"; } }; int item :: count; int main() { item a,b,c; a.getcount(); b.getcount(); c.getcount(); a.getdata(100); b.getdata(200); c.getdata(300); cout << "After reading data"<<"n"; a.getcount(); b.getcount(); c.getcount(); return 0; } The output of the program would be: Count: 0 Count: 0 Count: 0 After reading data Count: 3 Count: 3 Count: 3 3/11/2016 16By:-Gourav Kottawar
  • 17. Sharing of a static data member 3/11/2016 17By:-Gourav Kottawar
  • 18. Static member function  A member function that is declared static has following properties 1. A static function can have access to only other static members (functions or variables) declared in the same class. 2. A static member function can be called using the class name (instead of its objects ) as follows : class – name :: function – name;3/11/2016 18By:-Gourav Kottawar
  • 19. 3/11/2016 19 class Something { private: static int s_nValue; public: static int GetValue() { return s_nValue; } }; int Something::s_nValue = 1; // initializer int main() { std::cout << Something::GetValue() << std::endl; } By:-Gourav Kottawar
  • 20. 3/11/2016 20 class IDGenerator { private: static int s_nNextID; public: static int GetNextID() { return s_nNextID++; } }; // We'll start generating IDs at 1 int IDGenerator::s_nNextID = 1; int main() { for (int i=0; i < 5; i++) cout << "The next ID is: " << IDGenerator::GetNextID() << endl; return 0; } The next ID is: 1 The next ID is: 2 The next ID is: 3 The next ID is: 4 The next ID is: 5 By:-Gourav Kottawar
  • 21. 3/11/2016 21 class IDGenerator { private: static int s_nNextID; public: static int GetNextID() { return s_nNextID++; } }; // We'll start generating IDs at 1 int IDGenerator::s_nNextID = 1; int main() { for (int i=0; i < 5; i++) cout << "The next ID is: " << IDGenerator::GetNextID() << endl; return 0; } By:-Gourav Kottawar
  • 22. Array of object 3/11/2016 22By:-Gourav Kottawar
  • 23. 5.11 Object as Function Arguments  Two ways 1. A copy of the entire object is passed to the function. i.e. pass by value 2. Only the address of the object is transferred to the function i.e. pass by reference 3/11/2016 23By:-Gourav Kottawar
  • 25. 3/11/2016 25 #include <iostream> using namespace std; class Complex { private: int real; int imag; public: void Read() { cout<<"Enter real and imaginary number respectively:"<<endl; cin>>real>>imag; } void Add(Complex comp1,Complex comp2) { real=comp1.real+comp2.real; /* Here, real represents the real data of object c3 because this function is called using code c3.add(c1,c2); */ imag=comp1.imag+comp2.imag; /* Here, imag represents the imag data of object c3 because this function is called using code c3.add(c1,c2); */ } By:-Gourav Kottawar
  • 26. 3/11/2016 26 void Display() { cout<<"Sum="<<real<<"+"<<imag<<"i"; } }; int main() { Complex c1,c2,c3; c1.Read(); c2.Read(); c3.Add(c1,c2); c3.Display(); return 0; } By:-Gourav Kottawar
  • 27. Returning Object from Function 3/11/2016 27By:-Gourav Kottawar
  • 28. 3/11/2016 28 #include <iostream> using namespace std; class Complex { private: int real; int imag; public: void Read() { cout<<"Enter real and imaginary number respectively:"<<endl; cin>>real>>imag; } Complex Add(Complex comp2) { Complex temp; temp.real=real+comp2.real; /* Here, real represents the real data of object c1 because this function is called using code c1.Add(c2) */ temp.imag=imag+comp2.imag; /* Here, imag represents the imag data of object c1 because this function is called using code c1.Add(c2) */ return temp; 0; } By:-Gourav Kottawar
  • 29. 3/11/2016 29 } void Display() { cout<<"Sum="<<real<<"+"<<ima g<<"i"; } }; int main() { Complex c1,c2,c3; c1.Read(); c2.Read(); c3=c1.Add(c2); c3.Display(); return 0; } By:-Gourav Kottawar
  • 30. 5.12 Friend function  Need a data is declared as private inside a class, then it is not accessible from outside the class. A function that is not a member or an external class will not be able to access the private data. A programmer may have a situation where he or she would need to access private data from non-member functions and external classes. For handling such cases, the concept of Friend functions is a useful tool. 3/11/2016 30By:-Gourav Kottawar
  • 31. 5.12 Friend function What is a Friend Function?  A friend function is used for accessing the non-public members of a class.  A class can allow non- member functions and other classes to access its own private data, by making them friends.  Thus, a friend function is an ordinary function or a member of another class. 3/11/2016 31By:-Gourav Kottawar
  • 32. 5.12 Friend function  General syntax Class ABC { ….. ….. public : ….. ….. Friend void func1(void); }; 3/11/2016 32By:-Gourav Kottawar
  • 33. 5.12 Friend function Special Characteristics  The keyword friend is placed only in the function declaration of the friend function and not in the function definition.  It is not in the scope of the class to which it has been declared as friend.  It is possible to declare a function as friend in any number of classes.  When a class is declared as a friend, the friend class has access to the private data of the class that made this a friend.  A friend function, even though it is not a member function, would have the rights to access the private members of the class.  It is possible to declare the friend function as either private or public without affecting meaning.  The function can be invoked without the use of an object.  It has object as argument. 3/11/2016 33By:-Gourav Kottawar
  • 34. 3/11/2016 34 #include <iostream> using namespace std; class exforsys { private: int a,b; public: void test() { a=100; b=200; } friend int compute(exforsys e1); //Friend Function Declaration with keyword friend and with the object of class exforsys to which it is friend passed to it }; int compute(exforsys e1) { //Friend Function Definition which has access to private data return int(e1.a+e1.b)-5; } void main() { exforsys e; e.test(); cout << "The result is:" << compute(e); //Calling of Friend Function with object as argument. } By:-Gourav Kottawar
  • 35. Constant Member Functions  Declaring a member function with the const keyword specifies that the function is a "read-only" function that does not modify the object for which it is called.  A constantmember function cannot modify any non-static data members or call any member functions that aren't constant.  The const keyword is required in both the declaration and the definition. 3/11/2016 35By:-Gourav Kottawar
  • 36. Constant Member Functions – EXclass Date { public: Date( int mn, int dy, int yr ); int getMonth() const; // A read-only function void setMonth( int mn ); // A write function; can't be const private: int month; }; int Date::getMonth() const { return month; // Doesn't modify anything } 3/11/2016 36 void Date::setMonth( int mn ) { month = mn; // Modifies data member } int main() { Date MyDate( 7, 4, 1998 ); const Date BirthDate( 1, 18, 1953 ); MyDate.setMonth( 4 ); // Okay BirthDate.getMonth(); // Okay BirthDate.setMonth( 4 ); // C2662 Error } By:-Gourav Kottawar
  • 37. 5.14 Pointers to members  Pointers to members allow you to refer to nonstatic members of class objects.  You cannot use a pointer to member to point to a static class member because the address of a static member is not associated with any particular object.  To point to a static class member, you must use a normal pointer.  You can use pointers to member functions in the same manner as pointers to functions.  You can compare pointers to member functions, assign values to them, and use them to call member functions.  Note - a member function does not have the same type as a nonmember function that has the same number and type of arguments and the same return type. 3/11/2016 37By:-Gourav Kottawar
  • 38. 5.14 Pointers to members - Ex #include <iostream> using namespace std; class X { public: int a; void f(int b) { cout << "The value of b is "<< b << endl; } }; 3/11/2016 38 int main() { // declare pointer to data member int X::*ptiptr = &X::a; // declare a pointer to member function void (X::* ptfptr) (int) = &X::f; // create an object of class type X X xobject; // initialize data member xobject.*ptiptr = 10; cout << "The value of a is " << xobject.*ptiptr << endl; // call member function (xobject.*ptfptr) (20); } By:-Gourav Kottawar
  • 39. 5.14 Local Classes  A local class is declared within a function definition.  Declarations in a local class can only use type names, enumerations, static variables from the enclosing scope, as well as external variables and functions.  Member functions of a local class have to be defined within their class definition, if they are defined at all.  As a result, member functions of a local class are inline functions. Like all member functions, those defined within the scope of a local class do not need the keyword inline. 3/11/2016 39By:-Gourav Kottawar
  • 40. 3/11/2016 40 int x; // global variable void f() // function definition { static int y; // static variable y can be used by local class int x; // auto variable x cannot be used by local class extern int g(); // extern function g can be used by local class class local // local class { int g() { return x; } // error, local variable x // cannot be used by g int h() { return y; } // valid,static variable y int k() { return ::x; } // valid, global x int l() { return g(); } // valid, extern function g }; } int main() { local* z; // error: the class local is not visible // ...} By:-Gourav Kottawar
  • 41. 3/11/2016 41 A local class cannot have static data members. void f() { class local { int f(); // error, local class has noninline // member function int g() {return 0;} // valid, inline member function static int a; // error, static is not allowed for // local class int b; // valid, nonstatic variable }; } // . . . By:-Gourav Kottawar