- Main Page
- Files

# bmi.cpp File Reference

Compute body-mass index. More...

`#include <algorithm>`
`#include <cstdlib>`
`#include <iomanip>`
`#include <iostream>`
`#include <istream>`
`#include <limits>`
`#include <locale>`
`#include <ostream>`
`#include <string>`
`#include <vector>`

Go to the source code of this file.

## Functions
int | compute_bmi (int height, int weight)
| Compute the body-mass index (BMI). The height is in centimeters, so the computed value is off by 10,000. Integer division truncates, but we want to round off to nearest, so add 0.5 and then truncate by casting to an integer.
void | skip_line ()
| Skip the rest of the input line.
bool | get_record (std::vector< std::string > &names, std::vector< int > &heights, std::vector< int > &weights, std::vector< char > &sexes)
| Get a single person's record. Store the name, height, weight, and sex in the supplied vectors.
void | print_table (char sex, std::vector< int > const &heights, std::vector< int > const &weights, std::vector< int > const &bmis, std::vector< char > const &sexes, std::vector< std::string > const &names, int threshold)
| Print a table. Print a table of height, weight, sex, BMI, and name. Print only records for which sex matches `sex`. At the end of each table, print the mean and median BMI.
int | main ()
| Main program to compute BMI.

## Detailed Description

Compute body-mass index.

Definition in file bmi.cpp.

## Function Documentation

int compute_bmi | ( | int | height,
|  | int | weight |
| ) |  |  |

Compute the body-mass index (BMI). The height is in centimeters, so the computed value is off by 10,000. Integer division truncates, but we want to round off to nearest, so add 0.5 and then truncate by casting to an integer.

Parameters:

  | height | The person's height in centimeters.
  | weight | The person's weight in kilograms.

Returns:
  the person's BMI, rounded to an integer

Definition at line 60 of file bmi.cpp.

Referenced by main().

bool get_record | ( | std::vector< std::string > & | names,
|  | std::vector< int > & | heights,
|  | std::vector< int > & | weights,
|  | std::vector< char > & | sexes |
| ) |  |  |

Get a single person's record. Store the name, height, weight, and sex in the supplied vectors.

Parameters:

  | names | array of persons' full names
  | heights | array of height in centimeters
  | weights | array of weight in kilograms
  | sexes | array of persons' sex: 'M' means male and 'F' means female

Returns:
  true to continue reading records or false to stop

Definition at line 79 of file bmi.cpp.

References skip_line().

Referenced by main().

void print_table | ( | char | sex,
|  | std::vector< int > const & | heights,
|  | std::vector< int > const & | weights,
|  | std::vector< int > const & | bmis,
|  | std::vector< char > const & | sexes,
|  | std::vector< std::string > const & | names,
|  | int | threshold |
| ) |  |  |

Print a table. Print a table of height, weight, sex, BMI, and name. Print only records for which sex matches `sex`. At the end of each table, print the mean and median BMI.

Parameters:

  | sex | the sex to match
  | heights | the array of heights
  | weights | the array of weights
  | bmis | the array of BMIs
  | sexes | the array of sexes
  | names | the array of names
  | threshold | print only elements for which BMI > this

Definition at line 155 of file bmi.cpp.

Referenced by main().