3.1
Write a Short program that asks for your height in integer inches and converts your height to feet & inches.
- Use underscore character to indicate where to type the response.
- Use const symbolic constant to represent the conversion factor.
This what I have for assignment 3.1:
Code: Select all
//Assignment 3.1
#include <iostream>
#include <cstdlib>
using std::cout;
using std::cin;
using std::endl;
int inchesToFeet(int i)
{
int f = i/12;
return f;
}
int getRemainder(int i)
{
int r = i % 12;
return r;
}
int main()
{
int heightInches;
int heightFeet;
int heightRemainInches;
cout << "Enter your height in inches:";
cin >> heightInches;
heightFeet = inchesToFeet(heightInches);
heightRemainInches = getRemainder(heightInches);
cout << "You are " << heightFeet << " feet & " << heightRemainInches << " inches tall." << endl;
system("PAUSE");
return 0;
}
Assignment 3.2:
Write a short program that asks for your height in feet & inches and your weight in pounds. (Use three variables to store the information.) Have the program report body mass index (BMI). To calculate the BMI, first convert your height in feet & inches to your height in inches (1 foot = 12 inches). Then, convert your height in inches to your height in meters by multiplying by 0.0254. Then, convert your weight in pounds into your mass in kilograms by dividing by 2.2. Finally, compute your BMI by dividing your mass in kilograms by the square of your weight in meters. Use symbolic constants to represent the various conversion factors.
Code: Select all
//Assignment 3.2
#include <iostream>
#include <cstdlib>
using std::cout;
using std::cin;
using std::endl;
int feetToInches(int i)
{
double r = i * 12;
return r;
}
double inchesToMeters(int i)
{
double m = i * 0.0254;
return m;
}
double poundsToKilogramsMass(int p)
{
double k = p/2.2;
return k;
}
double getBMI(double weightK,double heightM)
{
double hSquared = heightM * heightM;
double r = weightK/hSquared;
return r;
}
int main()
{
int heightInches;
int heightFeet;
int weight;
cout << "Enter your height in feet & inches."
<< endl
<< "Feet: ";
cin >> heightFeet;
cout << "Inches: ";
cin >> heightInches;
cout << "Enter your weight in pounds:";
cin >> weight;
int feetConv = feetToInches(heightFeet);
int heightInchesTotal = feetConv + heightInches;
double heightMeters = inchesToMeters(heightInchesTotal);
double kiloMass = poundsToKilogramsMass(weight);
double BMI = getBMI(kiloMass,heightMeters);
cout << "Your Body Mass Index (BMI) is " << BMI << endl;
system("PAUSE");
return 0;
}


