HOME

Tuesday, September 22, 2015

SUM OF DISTANCE BY PASSING OBJECT AS ARGUMNET IN C++

#include<iostream>
using namespace std;
class distancee
{
    int km,m,cm;
public:
    void getdata();
    void sum(distancee, distancee);
};
void distancee :: getdata()
{
    cout<<"Enter the kilometer"<<endl;
    cin>>km;
    cout<<"Enter the meter"<<endl;
    cin>>m;
    cout<<"Enter the centimeter"<<endl;
    cin>>cm;
}
void distancee :: sum(distancee d1, distancee d2)
{
    cm=d1.cm+d2.cm;
    m=cm/100;
    cm%=100;
    m=m+d1.m+d2.m;
    km=m/1000;
    m%=1000;
    km=km+d1.km+d2.km;
    cout<<"total distance is "<<endl;
cout<<km<<" km "<<m<<" m "<<cm<<" cm "<<endl;
}
int main()
{
    distancee d1,d2,d3;
    d1.getdata();
    d2.getdata();
    d3.sum(d1,d2);
    return 0;
}

No comments:

Post a Comment