Wrtie a C++ Program for finding values of distance
//create two classes DM and DB which stores the value of distances. DM stores distances in metres
//and centimetres and DB in feet and inches. Write a program that can read values for the class objects
//and add one object DM with another object of DB.
//use friend function.
#include
#include
class db;
class dm
{
float mt;
int cm;
public:
void getdata(void);
void display(void);
friend dm add(dm,db);
};
class db
{
int feet;
float inches;
public:
void getdata(void);
void display(void);
friend dm add(dm,db);
};
void dm :: getdata(void)
{
clrscr();
cout<<"\t\tDM GETDATA FUNCTION\n\n"; cout<<"\n\nEnter Values for metres :-"; cin>>mt;
cout<<"Enter Values for centimetres:-"; cin>>cm;
}
void dm :: display(void)
{
cout<<"\n\nThe value of distance in metres is "<
cout<<"Enter Values for inches :-"; cin>>inches;
}
void db :: display(void)
{
cout<<"\n\nThe value of distance in feet is "<
cout<<"\nThe value of distance in inches is "<
}
dm add(dm a,db b)
{
dm temp;
temp.cm=a.cm+(b.feet*30)+((b.inches*30)/12.0);
temp.mt=a.mt+(temp.cm % 100);
temp.cm=temp.cm-((temp.cm % 100)*100);
return(temp);
}
void main()
{
dm a;
a.getdata();
db b;
b.getdata();
clrscr();
cout<<"\n\t\tAFTER CONVERSION AND THEIR ADDITION IS PERFORMED\n";
//extra variable of type dm to display result of adding two different types of distance
dm extra;
extra=add(a,b);
extra.display();
getch();
}