1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
class Measurements
{
private:
int sum1, sum2, temp;
//float fFraction;
public:
void getSum(int, int, int, int);
void showSum();
//void showFrac();
~Measurements();
};
void Measurements::getSum(int a, int b, int x, int y)
{
sum1 = a + b; // sum1 is the sum of the feet
sum2 = x + y; // sum2 is the sum of the inches
if(sum2 > 12)
{
sum1 = sum1 + (int)(sum2 / 12);
sum2 = sum2 % 12;
}
return;
}
void Measurements::showSum()
{
std::cout << "The sum of your measurements is: " << sum1 << " feet " << sum2 << " inches\n";
return;
}
Measurements::~Measurements()
{
std::cout << "Press the ENTER key to continue.";
std::cin.ignore();
}
int main()
{
Measurements measurementObject;
int feet1, feet2, inch1, inch2;
std::cout << "Enter measurements as follows: 3 4, representing 3 feet 4 inches.\n";
std::cout << "Enter your first integer measurement: "; std::cin >> feet1 >> inch1;
std::cout << "Enter your second integer measurement: "; std::cin >> feet2 >> inch2;
measurementObject.getSum(feet1, feet2, inch1, inch2);
measurementObject.showSum();
return 0;
}
|