Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

Program that provides an example of function returning object

Posted By: Antonie Schmidt     Category: C++ Programming     Views: 9174

Write a program that provides an example of function returning object.

Code for Program that provides an example of function returning object in C++ Programming

# include <iostream.h>
# include <conio.h>

class data
{
    int a,b;
    public:
        void get();
        friend data sum (data,data);
        void show();
};

data sum(data a1,data a2)
{
    data a3;
    a3.a=a1.a+a2.a;
    a3.b=a1.b+a2.b;
    return a3;
}

main()
{
    clrscr();
    data a,b,c;
    a.get();
    b.get();
    c=sum(a,b);
    c.show();
}

void data::get()
{
    cout<<"PLEASE ENTER FOR A:->";
    cin>>a;
    cout<<"PLEASE ENTER FOR B:->";
    cin>>b;
}

void data::show()
{
    cout<<"A= "<<a<<endl;
    cout<<"B= "<<b<<endl;
}

  
Share: 



Antonie Schmidt
Antonie Schmidt author of Program that provides an example of function returning object is from Frankfurt, Germany.
 
View All Articles

 

Other Interesting Articles in C++ Programming:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!