Project 1 - Body-mass index
Functions
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. 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.
 

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
heightThe person's height in centimeters.
weightThe 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
namesarray of persons' full names
heightsarray of height in centimeters
weightsarray of weight in kilograms
sexesarray 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
sexthe sex to match
heightsthe array of heights
weightsthe array of weights
bmisthe array of BMIs
sexesthe array of sexes
namesthe array of names
thresholdprint only elements for which BMI > this

Definition at line 155 of file bmi.cpp.

Referenced by main().