//class Distance with meter and cm as private data members
//read two Objects of the class
//add them by passing these two objects to a function member
//finally display result object in main() function
#include <iostream>
using namespace std;
class Distance
{
int meter,cm;
public:
void read();
void add(Distance,Distance);
void display();
};
void Distance::read()
{
cout<<"Enter meter and cm: ";
cin>>meter>>cm;
}
void Distance::add(Distance d1,Distance d2)
{
cm=d1.cm+d2.cm;
if(cm>=100)
{
cm=cm-100;
meter=1;
//read two Objects of the class
//add them by passing these two objects to a function member
//finally display result object in main() function
#include <iostream>
using namespace std;
class Distance
{
int meter,cm;
public:
void read();
void add(Distance,Distance);
void display();
};
void Distance::read()
{
cout<<"Enter meter and cm: ";
cin>>meter>>cm;
}
void Distance::add(Distance d1,Distance d2)
{
cm=d1.cm+d2.cm;
if(cm>=100)
{
cm=cm-100;
meter=1;
No comments:
Post a Comment