Project 1 - Body-mass index
|
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. More... | |
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. More... | |
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. More... | |
int | main () |
Main program to compute BMI. | |
Compute body-mass index.
Definition in file bmi.cpp.
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.
height | The person's height in centimeters. |
weight | The person's weight in kilograms. |
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.
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 |
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.
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().