SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
OBJECT IN OOP
Objects
 An object is an instance of a class.
 An object is a class variable.
 Is can be uniquely identified by its name.
 Every object have a state which is represented by the
values of its attributes. These state are changed by
function which applied on the object.
State identity and behavior of
objects
 Every object have identity , behavior and state.
 The identity of object is defined by its name, every
object is unique and can be differentiated from other
objects.
 The behavior of an object is represented by the
functions which are defined in the object’s class. These
function show the set of action for every objects.
 The state of objects are referred by the data stored
within the object at any time moment.
Creating an object of a Class
 Declaring a variable of a class type creates an object. You
can have many variables of the same type (class).
 Also known as Instantiation
 Once an object of a certain class is instantiated, a new
memory location is created for it to store its data members
and code
 You can instantiate many objects from a class type.
 Ex) Circle c; Circle *c;
Class item
{
……….
,,,,,,,,,,,,,
}x,y,z;
We have to declared objects close to the place where they are needed
because it makes easier to identify the objects.
Object types
 There are four types of objects
1. External (global )objects
1. This object have the existence throughout the lifetime of the program and
having file –scope.
2. Automatic(local)objects
1. Persistent and visible only throughout the local scope in which they are
created.
3. Static objects
1. Persistent throughout a program but only visible within their local scope.
4. Dynamic objects
1. Lifetime may be controlled within a particular scope.
Memory Allocation of Object
class student
{
int rollno;
char name[20];
int marks;
};
student s;
rollno – 2 bytes
name- 20 bytes
marks- 2 bytes
24 bytes s
Array of objects
 The array of class type variable is known as array of
object.
 We can declare array of object as following way:-
Class _name object [length];
Employee manager[3];
1. We can use this array when calling a member function
2. Manager[i].put data();
3. The array of object is stored in memory as a multi-
dimensional array.
Object as function arguments
 This can be done in two ways:-
 A copy of entire object is passed to the function.
 ( pass by value)
 Only the address of the object is transferred to the
function. (pass by reference)
( pass by value)
 A copy of the object is passed to the function, any
changes made to the object inside the function do not
affect the object used to call function.
 When an address of object is passed, the called
function works directly on the actual object used in
the call. Means that any change made in side the
function will reflect in the actual object.
(pass by reference)
Passing Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
void sum (Complex A, Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
void Complex : : sum ( complex A, complex B)
{
real = A.real + B.real;
imag= A.imag + B.imag;
}
void main( )
{
Complex X,Y,Z;
X.getdata( );
Y.getdata( );
Z.sum(X,Y);
Z.putdata( );
}
Passing Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
void sum (Complex A, Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
void Complex : : sum ( Complex A, Complex B)
{
real = A.real + B.real;
imag= A.imag + B.imag;
}
void main( )
{
Complex X,Y,Z;
X.getdata( );
Y.getdata( );
Z.sum(X,Y);
Z.putdata( );
}
X Y Z
Passing Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
void sum (Complex A, Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
void Complex : : sum ( Complex A, Complex B)
{
real = A.real + B.real;
imag= A.imag + B.imag;
}
void main( )
{
Complex X,Y,Z;
X.getdata( );
Y.getdata( );
Z.sum(X,Y);
Z.putdata( );
}
5
6
7
8
X Y Z
Passing Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
void sum (Complex A, Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
void Complex : : sum ( Complex A, Complex B)
{
real = A.real + B.real;
imag= A.imag + B.imag;
}
void main( )
{
Complex X,Y,Z;
X.getdata( );
Y.getdata( );
Z.sum(X,Y);
Z.putdata( );
}
5
6
7
8
X Y Z
5
6
7
8
A B
Passing Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
void sum(Complex A, Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
void Complex : : sum ( Complex A, Complex B)
{
real = A.real + B.real;
imag= A.imag + B.imag;
}
void main( )
{
Complex X,Y,Z;
X.getdata( );
Y.getdata( );
Z.sum(X,Y);
Z.putdata( );
}
5
6
7
8
12
14
X Y Z
5
6
7
8
A B
+
+
=
=
Passing Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
void sum (Complex A, Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
void complex : : sum ( Complex A, Complex B)
{
real = A.real + B.real;
imag= A.imag + B.imag;
}
void main( )
{
Complex X,Y,Z;
X.getdata( );
Y.getdata( );
Z.sum(X,Y);
Z.putdata( );
}
12 + 14 i
5
6
7
8
12
14
X Y Z
5
6
7
8
A B
+
+
=
=
Returning Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
Complex sum (Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
Complex Complex : : sum (Complex B)
{
Complex temp;
temp.real=real + B.real;
temp.imag= imag + B.imag;
return temp;
}
void main ( )
{
Complex X, Y, Z;
X.Getdata( );
Y. getdata( );
Z= X.sum (Y);
Z.putdata( );
}
Returning Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
Complex sum (Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
Complex Complex : : sum (Complex B)
{
Complex temp;
temp.real=real + B.real;
temp.imag= imag + B.imag;
return temp;
}
void main ( )
{
Complex X, Y, Z;
X.Getdata( );
Y. getdata( );
Z= X.sum (Y);
Z.putdata( );
}
X Y Z
Returning Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
Complex sum (Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
Complex Complex : : sum (Complex B)
{
Complex temp;
temp.real=real + B.real;
temp.imag= imag + B.imag;
return temp;
}
void main ( )
{
Complex X, Y, Z;
X.Getdata( );
Y. getdata( );
Z= X.sum (Y);
Z.putdata( );
}
5
6
7
8
X Y Z
Returning Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
Complex sum (Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
Complex Complex : : sum (Complex B)
{
Complex temp;
temp.real=real + B.real;
temp.imag= imag + B.imag;
return temp;
}
void main ( )
{
Complex X, Y, Z;
X.Getdata( );
Y. getdata( );
Z= X.sum (Y);
Z.putdata( );
}
5
6
7
8
X Y Z
7
8
B
Returning Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
Complex sum (Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
Complex Complex : : sum (Complex B)
{
Complex temp;
temp.real=real + B.real;
temp.imag= imag + B.imag;
return temp;
}
void main ( )
{
Complex X, Y, Z;
X.Getdata( );
Y. getdata( );
Z= X.sum (Y);
Z.putdata( );
}
5
6
7
8
X Y Z
7
8
B
Returning Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
Complex sum (Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
Complex Complex : : sum (Complex B)
{
Complex temp;
temp.real=real + B.real;
temp.imag= imag + B.imag;
return temp;
}
void main ( )
{
Complex X, Y, Z;
X.Getdata( );
Y. getdata( );
Z= X.sum (Y);
Z.putdata( );
}
5
6
7
8
X Y Z
7
8
B
12
14
temp
Returning Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
Complex sum (Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
Complex Complex : : sum (Complex B)
{
Complex temp;
temp.real=real + B.real;
temp.imag= imag + B.imag;
return temp;
}
void main ( )
{
Complex X, Y, Z;
X.Getdata( );
Y. getdata( );
Z= X.sum (Y);
Z.putdata( );
}
5
6
7
8
X Y Z
7
8
B
12
14
temp
Returning Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
Complex sum (Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”;
else
cout<<real<<imag<<“i”;
}
Complex Complex : : sum (Complex B)
{
Complex temp;
temp.real=real + B.real;
temp.imag= imag + B.imag;
return temp;
}
void main ( )
{
Complex X, Y, Z;
X.Getdata( );
Y. getdata( );
Z= X.sum (Y);
Z.putdata( );
}
5
6
7
8
12
14
X Y Z
7
8
B
12
14
temp
Returning Object
#include<iostream.h>
class Complex
{
float real, imag;
public:
void getdata( );
void putdata( );
Complex sum (Complex B);
};
void Complex : : getdata( )
{
cout<<“enter real part:”;
cin>>real;
cout<<“enter imaginary part:”;
cin>>imag;
}
void Complex : : putdata( )
{
if (imag>=0)
cout<<real<<“+”<<imag<<“i”
;
else
cout<<real<<imag<<“i”;
}
Complex Complex : : sum (Complex B)
{
Complex temp;
temp.real=real + B.real;
temp.imag= imag + B.imag;
return temp;
}
void main ( )
{
Complex X, Y, Z;
X.Getdata( );
Y. getdata( );
Z= X.sum (Y);
Z.putdata( );
}
12 + 14 i
5
6
7
8
12
14
X Y Z
7
8
B
12
14
temp

More Related Content

Similar to OBJECTS IN Object Oriented Programming .ppt (20)

PDF
C++ largest no between three nos
krismishra
 
PPT
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
PPTX
classes & objects in cpp overview
gourav kottawar
 
PPTX
class and objects
Payel Guria
 
PDF
Classes and objects
Kamal Acharya
 
PDF
Class object
Dr. Anand Bihari
 
PPTX
Online CPP Homework Help
C++ Homework Help
 
PPTX
Chp 3 C++ for newbies, learn fast and earn fast
nhbinaaa112
 
PPT
C++lecture9
FALLEE31188
 
PPT
Oop objects_classes
sidra tauseef
 
PDF
Ch 4
AMIT JAIN
 
PDF
OOPs theory about its concepts and properties.
ssuser1af273
 
PPTX
C++ & Data Structure - Unit - first.pptx
KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY
 
PPTX
oopusingc.pptx
MohammedAlobaidy16
 
PPTX
class c++
vinay chauhan
 
PDF
C++ normal assignments by maharshi_jd.pdf
maharshi1731
 
PPTX
Pointer to Member Function.pptx pointer in c++
ankeshshri
 
PDF
Object Oriented Programming (OOP) using C++ - Lecture 3
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
PPT
Lec 45.46- virtual.functions
Princess Sam
 
C++ largest no between three nos
krismishra
 
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
classes & objects in cpp overview
gourav kottawar
 
class and objects
Payel Guria
 
Classes and objects
Kamal Acharya
 
Class object
Dr. Anand Bihari
 
Online CPP Homework Help
C++ Homework Help
 
Chp 3 C++ for newbies, learn fast and earn fast
nhbinaaa112
 
C++lecture9
FALLEE31188
 
Oop objects_classes
sidra tauseef
 
Ch 4
AMIT JAIN
 
OOPs theory about its concepts and properties.
ssuser1af273
 
C++ & Data Structure - Unit - first.pptx
KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY
 
oopusingc.pptx
MohammedAlobaidy16
 
class c++
vinay chauhan
 
C++ normal assignments by maharshi_jd.pdf
maharshi1731
 
Pointer to Member Function.pptx pointer in c++
ankeshshri
 
Object Oriented Programming (OOP) using C++ - Lecture 3
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
Lec 45.46- virtual.functions
Princess Sam
 

Recently uploaded (20)

PDF
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
PPTX
Ward Management: Patient Care, Personnel, Equipment, and Environment.pptx
PRADEEP ABOTHU
 
PDF
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PPTX
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
PDF
Genomics Proteomics and Vaccines 1st Edition Guido Grandi (Editor)
kboqcyuw976
 
PDF
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
PPTX
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
PPTX
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
PPTX
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
PPTX
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
PDF
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
PPTX
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
PDF
Quiz Night Live May 2025 - Intra Pragya Online General Quiz
Pragya - UEM Kolkata Quiz Club
 
PPTX
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PDF
Indian National movement PPT by Simanchala Sarab, Covering The INC(Formation,...
Simanchala Sarab, BABed(ITEP Secondary stage) in History student at GNDU Amritsar
 
PPTX
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
Ward Management: Patient Care, Personnel, Equipment, and Environment.pptx
PRADEEP ABOTHU
 
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
Genomics Proteomics and Vaccines 1st Edition Guido Grandi (Editor)
kboqcyuw976
 
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
Quiz Night Live May 2025 - Intra Pragya Online General Quiz
Pragya - UEM Kolkata Quiz Club
 
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
Indian National movement PPT by Simanchala Sarab, Covering The INC(Formation,...
Simanchala Sarab, BABed(ITEP Secondary stage) in History student at GNDU Amritsar
 
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
Ad

OBJECTS IN Object Oriented Programming .ppt

  • 2. Objects  An object is an instance of a class.  An object is a class variable.  Is can be uniquely identified by its name.  Every object have a state which is represented by the values of its attributes. These state are changed by function which applied on the object.
  • 3. State identity and behavior of objects  Every object have identity , behavior and state.  The identity of object is defined by its name, every object is unique and can be differentiated from other objects.  The behavior of an object is represented by the functions which are defined in the object’s class. These function show the set of action for every objects.  The state of objects are referred by the data stored within the object at any time moment.
  • 4. Creating an object of a Class  Declaring a variable of a class type creates an object. You can have many variables of the same type (class).  Also known as Instantiation  Once an object of a certain class is instantiated, a new memory location is created for it to store its data members and code  You can instantiate many objects from a class type.  Ex) Circle c; Circle *c; Class item { ………. ,,,,,,,,,,,,, }x,y,z; We have to declared objects close to the place where they are needed because it makes easier to identify the objects.
  • 5. Object types  There are four types of objects 1. External (global )objects 1. This object have the existence throughout the lifetime of the program and having file –scope. 2. Automatic(local)objects 1. Persistent and visible only throughout the local scope in which they are created. 3. Static objects 1. Persistent throughout a program but only visible within their local scope. 4. Dynamic objects 1. Lifetime may be controlled within a particular scope.
  • 6. Memory Allocation of Object class student { int rollno; char name[20]; int marks; }; student s; rollno – 2 bytes name- 20 bytes marks- 2 bytes 24 bytes s
  • 7. Array of objects  The array of class type variable is known as array of object.  We can declare array of object as following way:- Class _name object [length]; Employee manager[3]; 1. We can use this array when calling a member function 2. Manager[i].put data(); 3. The array of object is stored in memory as a multi- dimensional array.
  • 8. Object as function arguments  This can be done in two ways:-  A copy of entire object is passed to the function.  ( pass by value)  Only the address of the object is transferred to the function. (pass by reference)
  • 9. ( pass by value)  A copy of the object is passed to the function, any changes made to the object inside the function do not affect the object used to call function.  When an address of object is passed, the called function works directly on the actual object used in the call. Means that any change made in side the function will reflect in the actual object. (pass by reference)
  • 10. Passing Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); void sum (Complex A, Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } void Complex : : sum ( complex A, complex B) { real = A.real + B.real; imag= A.imag + B.imag; } void main( ) { Complex X,Y,Z; X.getdata( ); Y.getdata( ); Z.sum(X,Y); Z.putdata( ); }
  • 11. Passing Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); void sum (Complex A, Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } void Complex : : sum ( Complex A, Complex B) { real = A.real + B.real; imag= A.imag + B.imag; } void main( ) { Complex X,Y,Z; X.getdata( ); Y.getdata( ); Z.sum(X,Y); Z.putdata( ); } X Y Z
  • 12. Passing Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); void sum (Complex A, Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } void Complex : : sum ( Complex A, Complex B) { real = A.real + B.real; imag= A.imag + B.imag; } void main( ) { Complex X,Y,Z; X.getdata( ); Y.getdata( ); Z.sum(X,Y); Z.putdata( ); } 5 6 7 8 X Y Z
  • 13. Passing Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); void sum (Complex A, Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } void Complex : : sum ( Complex A, Complex B) { real = A.real + B.real; imag= A.imag + B.imag; } void main( ) { Complex X,Y,Z; X.getdata( ); Y.getdata( ); Z.sum(X,Y); Z.putdata( ); } 5 6 7 8 X Y Z 5 6 7 8 A B
  • 14. Passing Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); void sum(Complex A, Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } void Complex : : sum ( Complex A, Complex B) { real = A.real + B.real; imag= A.imag + B.imag; } void main( ) { Complex X,Y,Z; X.getdata( ); Y.getdata( ); Z.sum(X,Y); Z.putdata( ); } 5 6 7 8 12 14 X Y Z 5 6 7 8 A B + + = =
  • 15. Passing Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); void sum (Complex A, Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } void complex : : sum ( Complex A, Complex B) { real = A.real + B.real; imag= A.imag + B.imag; } void main( ) { Complex X,Y,Z; X.getdata( ); Y.getdata( ); Z.sum(X,Y); Z.putdata( ); } 12 + 14 i 5 6 7 8 12 14 X Y Z 5 6 7 8 A B + + = =
  • 16. Returning Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); Complex sum (Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } Complex Complex : : sum (Complex B) { Complex temp; temp.real=real + B.real; temp.imag= imag + B.imag; return temp; } void main ( ) { Complex X, Y, Z; X.Getdata( ); Y. getdata( ); Z= X.sum (Y); Z.putdata( ); }
  • 17. Returning Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); Complex sum (Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } Complex Complex : : sum (Complex B) { Complex temp; temp.real=real + B.real; temp.imag= imag + B.imag; return temp; } void main ( ) { Complex X, Y, Z; X.Getdata( ); Y. getdata( ); Z= X.sum (Y); Z.putdata( ); } X Y Z
  • 18. Returning Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); Complex sum (Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } Complex Complex : : sum (Complex B) { Complex temp; temp.real=real + B.real; temp.imag= imag + B.imag; return temp; } void main ( ) { Complex X, Y, Z; X.Getdata( ); Y. getdata( ); Z= X.sum (Y); Z.putdata( ); } 5 6 7 8 X Y Z
  • 19. Returning Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); Complex sum (Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } Complex Complex : : sum (Complex B) { Complex temp; temp.real=real + B.real; temp.imag= imag + B.imag; return temp; } void main ( ) { Complex X, Y, Z; X.Getdata( ); Y. getdata( ); Z= X.sum (Y); Z.putdata( ); } 5 6 7 8 X Y Z 7 8 B
  • 20. Returning Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); Complex sum (Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } Complex Complex : : sum (Complex B) { Complex temp; temp.real=real + B.real; temp.imag= imag + B.imag; return temp; } void main ( ) { Complex X, Y, Z; X.Getdata( ); Y. getdata( ); Z= X.sum (Y); Z.putdata( ); } 5 6 7 8 X Y Z 7 8 B
  • 21. Returning Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); Complex sum (Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } Complex Complex : : sum (Complex B) { Complex temp; temp.real=real + B.real; temp.imag= imag + B.imag; return temp; } void main ( ) { Complex X, Y, Z; X.Getdata( ); Y. getdata( ); Z= X.sum (Y); Z.putdata( ); } 5 6 7 8 X Y Z 7 8 B 12 14 temp
  • 22. Returning Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); Complex sum (Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } Complex Complex : : sum (Complex B) { Complex temp; temp.real=real + B.real; temp.imag= imag + B.imag; return temp; } void main ( ) { Complex X, Y, Z; X.Getdata( ); Y. getdata( ); Z= X.sum (Y); Z.putdata( ); } 5 6 7 8 X Y Z 7 8 B 12 14 temp
  • 23. Returning Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); Complex sum (Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i”; else cout<<real<<imag<<“i”; } Complex Complex : : sum (Complex B) { Complex temp; temp.real=real + B.real; temp.imag= imag + B.imag; return temp; } void main ( ) { Complex X, Y, Z; X.Getdata( ); Y. getdata( ); Z= X.sum (Y); Z.putdata( ); } 5 6 7 8 12 14 X Y Z 7 8 B 12 14 temp
  • 24. Returning Object #include<iostream.h> class Complex { float real, imag; public: void getdata( ); void putdata( ); Complex sum (Complex B); }; void Complex : : getdata( ) { cout<<“enter real part:”; cin>>real; cout<<“enter imaginary part:”; cin>>imag; } void Complex : : putdata( ) { if (imag>=0) cout<<real<<“+”<<imag<<“i” ; else cout<<real<<imag<<“i”; } Complex Complex : : sum (Complex B) { Complex temp; temp.real=real + B.real; temp.imag= imag + B.imag; return temp; } void main ( ) { Complex X, Y, Z; X.Getdata( ); Y. getdata( ); Z= X.sum (Y); Z.putdata( ); } 12 + 14 i 5 6 7 8 12 14 X Y Z 7 8 B 12 14 temp