// ex_3.1
#include <iostream>
using namespace std;
int main()
{
const int FeetToInch = 12;
int height = 0;
cout << "Enter your height(in inch):___\b\b\b";
cin >> height;
int feet = height / FeetToInch;
int inches = height % FeetToInch;
cout << "Your height is " <<feet << " foot " << inches << " inch." << endl;
return 0;
}
// ex_3.2
#include <iostream>
using namespace std;
const int FOOT_TO_INCHES = 12;
const double INCHES_TO_METERS = 0.0254;
const double POUNDS_TO_KILOGRAMS = 1.0 / 2.2;
int main()
{
int height_foot = 0;
int height_inch = 0;
double height_meter = 0;
double weight_pound = 0;
double BMI = 0;
cout << "Enter your height in foot and inch" << endl;
cout << "Enter the foot: ";
cin >> height_foot;
cout << "Enter the inch: ";
cin >> height_inch;
cout << "Enter your weight in pounds: ";
cin >> weight_pound;
height_meter = INCHES_TO_METERS * (FOOT_TO_INCHES * height_foot + height_inch);
BMI = weight_pound * POUNDS_TO_KILOGRAMS / (height_meter * height_meter);
cout << "Your BMI is " << BMI;
return 0;
}
// ex_3.3
#include <iostream>
using namespace std;
const double MINUTE_TO_SECOND = 60;
int main()
{
double degrees = 0;
double minutes = 0;
double seconds = 0;
double decimalFormat = 0;
cout << "Enrer a latitude in degrees, minutes, and seconds:" << endl;
cout << "First, enter the degrees: ";
cin >> degrees;
cout << "Next, enter the minutes of arc: ";
cin >> minutes;
cout << "Finaly, enter the seconds of arc: ";
cin >> seconds;
decimalFormat = degrees + (minutes + (seconds / MINUTE_TO_SECOND)) * (5.0 / 300);
cout << int(degrees) << " degrees, " << int(minutes) << " minutes, " << int(seconds) << " seconds = " << decimalFormat << " degrees" << endl;
return 0;
}
// ex_3.4
#include <iostream>
using namespace std;
int main()
{
long long totSeconds;
cout << "Enter a time in seconds: " ;
cin >> totSeconds ;
int currentDay = totSeconds / (24 * 60 * 60);
int currentHours = (totSeconds - currentDay * (24 * 60 * 60)) / 3600;
int currentMin = ((totSeconds % (60 * 60)) / 60);
int currentSec = totSeconds % 60;
cout << totSeconds << " seconds = " << currentDay<<" days, "
<< currentHours <<" hours, " << currentMin << " minutes, " << currentSec << " seconds" << endl;
return 0;
}