Sunday, July 3, 2016

C++ code to calculate body fat of a person (Logic explained)

C++ code to calculate body fat of a person (Logic explained),C++ code to calculate body fat of a person (Logic explained)

Here is the C++ code to calculate body fat of a person  . It works by inputting some necessary data of person. You all should have in mind how it works exactly. Here is the algorithm.

  Steps
User side
1: User asked for his/her gender
2: User asked to enter body-weight 
3: User asked to enter wrist measurement 
4: User asked to enter waist measurement
5: User asked to enter hip measurement
6: User asked to enter forearm measurement
7: User displayed body fat
8: User displayed body fat percentage
9: Program ends here
Developer side
1: Declare variables that are going to be used in program .
2: Input gender from user (because there are different formulas for different genders)
3: If User is woman follow this
 Input enter body-weight (Calculate  A1=(bodyweight*0.732)+8.987;)
 Input wrist measurement (Calculate  A2=(wrist)/3.140;
 Input waist measurement (Calculate   A3=(waist)*0.157;)
 Input  hip measurement (Calculate   A4=(hip)*0.249;)
 Input  forearm measurement (Calculate   A5=(forearm)*0.434;)
  Know calculate following :  B=A1+A2-A3-A4+A5;
                         bodyfat=bodyweight-B;
                     
4:  If user is man then follow this
    Input body-weight (Calculate  A1=(bodyweight*1.082)+94.42;)
    Input wrist measurement (Calculate A2=(wrist)*4.15;)
    Know calculate following 
                            B=A1-A2;
                           bodyfat=bodyweight-B;
5: Calculate percentage body fat (To calculate percentage body fat use this formula  bodyfatparcentage=(bodyfat*100)/bodyweight;)

5: Output results 
6: Program ends here.
Here is the C++ code.

Code:

#include<iostream>

using namespace std;
void main()
{      char gender;
       float bodyweight,wrist,waist,hip,forearm;
       float A1,A2,A3,A4,A5,B,bodyfat,bodyfatparcentage;
       cout<<"\t\tThis program is to calculate the body fat of a person"<<endl;
       cout<<"If you are woman than press \'w\' . If you are man than press \'m\'  "<<endl;
       cin>>gender;
       switch(gender)
       {
                     case 'w':
             
                     cout<<"Enter your body weight ";
                     cin>>bodyweight;
                     A1=(bodyweight*0.732)+8.987;
                     cout<<"Enter your wrist measurement ";
                     cin>>wrist;
                     A2=(wrist)/3.140;
                     cout<<"Enter your waist measurement ";
                     cin>>waist;
                     A3=(waist)*0.157;
                     cout<<"Enter your hip measurement ";
                     cin>>hip;
                     A4=(hip)*0.249;
                     cout<<"Enter your forearm measurement ";
                     cin>>forearm;
                     A5=(forearm)*0.434;
                     //calculting B
                     B=A1+A2-A3-A4+A5;
                     bodyfat=bodyweight-B;
                     cout<<"Body Fat is equal to = "<<bodyfat<<endl;
                     bodyfatparcentage=(bodyfat*100)/bodyweight;
                     cout<<"Body Fat percentage is equal to = "<<bodyfatparcentage<<"%"<<endl;
             
              break;
       case 'm':
                    
                           cout<<"Enter your body weight ";
                           cin>>bodyweight;
                           A1=(bodyweight*1.082)+94.42;
                           cout<<"Enter your wrist measurement ";
                           cin>>wrist;
                           A2=(wrist)*4.15;
                           B=A1-A2;
                           bodyfat=bodyweight-B;
                           cout<<"Body Fat is equal to = "<<bodyfat<<endl;
                           bodyfatparcentage=(bodyfat*100)/bodyweight;
                            cout<<"Body Fat percentage is equal to = "<<bodyfatparcentage<<"%"<<endl;
                     break;
       default:
        cout<<"wrong input"<<endl;
       }
       system("pause");
}



Output:



Usman Ahmed Abid

Author & Editor

It will be great pleasure for me when anyone get some knowledge from my site.

0 comments:

Post a Comment

Manual Categories