#include <iostream>
#include <conio.h>
using namespace std;
class DB;
class DM
{
float meters, centimeters;
public:
DM(float &meters, float ¢imeters)
{
this->meters = meters;
this->centimeters = centimeters;
}
void conversion()
{
meters = 3.37 * meters;
centimeters = 0.394 * centimeters;
}
friend void add(DM, DB);
};
class DB
{
float feet, inches;
public:
DB(float &feet, float &inches)
{
this->feet = feet;
this->inches = inches;
}
void conversion()
{
feet = 0.305 * feet;
inches = 2.54 * inches;
}
friend void add(DM, DB);
};
void add(DM A, DB D)
{
A.meters = A.meters + D.feet;
A.centimeters += D.inches;
cout << A.meters << "\t" << A.centimeters << endl;
}
int main()
{
float num1, num2, num3, num4;
cout << "enter distance in feet and inches\n";
cout << "enter feet\n";
cin >> num1;
cout << "enter inches\n";
cin >> num2;
DB obj1(num1, num2);
system("cls");
cout << "\nenter distance in meters and centimeters\n";
cout << "enter meters\n";
cin >> num3;
cout << "enter centimeters\n";
cin >> num4;
DM obj2(num3, num4);
int choice;
system("cls");
cout << "enter\n1. for adding data and display addition in meters and centimeters\n2. for adding data and display addition in feet and inches\n";
cin >> choice;
if (choice == 1)
{
system("cls ");
cout << "meters "
<< "\t"
<< "centimeters \n";
obj1.conversion();
add(obj2, obj1);
}
else if (choice == 2)
{
system("cls");
cout << "feet "
<< "\t"
<< "inches \n";
obj2.conversion();
add(obj2, obj1);
}
return 0;
}
No comments:
Post a Comment