Showing posts with label Passing objects as arguments. Show all posts
Showing posts with label Passing objects as arguments. Show all posts

Thursday, December 9, 2010

Passing objects as arguments(headerfiles are iostream.h and conio.h)

#include
#include
class add
{
private:
int a,b;
public:
void read_number();
void add_func(add,add);
void show_sum();
};
void add::read_number()
{
cout<<"\n\nENTER THE 1 NUMBER=";
cin>>a;
cout<<"\n\nENTER THE 2 NUMBER=";
cin>>b;
}
void add::add_func(add ad1,add ad2)
{
a=ad1.a+ad2.a; //IMPTORTANT FUNCTION
b=ad1.b+ad2.b;
}
void add::show_sum()
{
cout<<"\n\nSUM OBTAINED AFTER ADDING=";
cout<}
int main()
{
clrscr();
add add1,add2,add3;
add1.read_number();
add2.read_number();
add3.add_func(add1,add2);
add3.show_sum();
getch();
return(0);
}
/*********************************
OUTPUT
***********************************


ENTER THE 1 NUMBER=2

ENTER THE 2 NUMBER=2

ENTER THE 1 NUMBER=3

ENTER THE 2 NUMBER=3

SUM OBTAINED AFTER ADDING=5
5
*/

Programming the Whole World!