Write a class named \"htm\" that represents the height (in meters) and mass (in
ID: 3772001 • Letter: W
Question
Write a class named "htm" that represents the height (in meters) and mass (in kilograms) of a person Your class will have these double attributes: ht. ma Your class must have these methods a. Accessors for both attributes. Mutators for both attributes. A default constructor with both attributes set to 0; and an initial value constructor. A method that overloads (redefines) the subtraction operator and returns a real number. The result is the difference in the masses of the two people. A method with a return type of "double" that calculates the body mass index (BMI) of a person. BMI = mass/height^2. Once the class is written, use it in a program. Write a program that creates two "htm" objects A and B. A has attributes (ht =1.8 and ma = 90). Ask the user to input the attributes for B. Using your subtraction operator, calculate A - B as well as the BMI of each person. Output the results.Explanation / Answer
#include<iostream>
using namespace std;
class htm
{
public:
double ht,ma;
htm()
{
ht=0.0;
ma=0.0;
}
htm(double h,double m)
{
ht=h;
ma=m;
}
};
int main()
{
htm A(1.8,90.0);
double h,m;
cout<<"Enter height : ";
cin>>h;
cout<<"Enter mass : ";
cin>>m;
htm B(h,m);
cout<<"BIM = "<<B.ma/(B.ht*B.ht);
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.