Sunday, March 17, 2013

Returning Class Objects

#include<iostream>
using namespace std;
class complex{
                 int id;
                 int marks;
                 public:
                 void input()
                 {
                     cin>>id;
                     cin>>marks;
                 }
                 friend complex sum(complex,complex);
                 void show(complex);
             };
complex sum(complex c1,complex c2)
{
    complex c3;
    int maxx=c1.marks;
    if(c1.marks<c2.marks)
    //maxx=c2.marks;
    return (c2);
    else
    return (c1);
}
void complex::show(complex c)
{
    cout<<c.id<<"  "<<c.marks<<"\n";
}
int main()
{
    complex a,b,c;
    a.input();
    b.input();
    c=sum(a,b);
    cout<<"a ";
    a.show(a);
    cout<<"b ";
    b.show(b);
    cout<<"c ";
    c.show(c);
    return 0;
}

0 comments:

Post a Comment