Write a program to add height and store it in 3rd object

/*
 WAP to add height
 and store it in 3rd object
*/
#include<iostream>
using namespace std;

class Height
{
int foot,inch;

public:
void accept()
{
cout<<"\n\n Enter foot and inch: ";
cin>>foot>>inch;
}
void display(Height H)
{
cout<<"\n\n "<<H.foot<<" foot "<<H.inch<<" inch ";
}

void add(Height h1,Height h2);
};

void Height::add(Height h1,Height h2)
{
Height h3;

h3.foot=h1.foot+h2.foot;
h3.inch=h1.inch+h2.inch;

if(h3.inch>=12)
{
h3.foot=h3.foot+(h3.inch/12);
h3.inch=h3.inch%12;

display(h3);
}

int main()
{
Height h1,h2;

h1.accept();
h2.accept();

h1.display(h1);
h2.display(h2);

h1.add(h1,h2);

return 0;
}

Previous
Next Post »