Logo 
Search:

C++ Programming Articles

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

Program that provides an example to return an object from a function

Posted By: Ryan Evans     Category: C++ Programming     Views: 9018

Write a program that provides an example to return an object from a function.

Code for Program that provides an example to return an object from a function in C++ Programming

#include<iostream.h>
#include<conio.h>
class data1
{
    public:
        int a,b;
        void get1();
};
class data2
{
    public:
        int c,d;
        void get2();
};
class data3
{
    int x,y;
    void show();
    public:
        void sum(data1,data2);
};

main()
{
    clrscr();
    data1 d1;
    data2 d2;
    data3 d3;
    d1.get1();
    d2.get2();
    d3.sum(d1,d2);
}

void data1::get1()
{
    cout<<"Enter for a: ";
    cin>>a;
    cout<<"Enter for b: ";
    cin>>b;
}
void data2::get2()
{
    cout<<"Enter for c: ";
    cin>>c;

    cout<<"Enter for d: ";
    cin>>d;
}

void data3::sum(data1 a1,data2 a2)
{
    x=a1.a+a2.c;
    y=a1.b+a2.d;
    show();
}
void data3::show()
{
    cout<<"X= "<<x<<endl;
    cout<<"Y= "<<y<<endl;
}
  
Share: 



Ryan Evans
Ryan Evans author of Program that provides an example to return an object from a function is from London, United Kingdom.
 
View All Articles

 
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!