I have a table of 250 patients divided in categories of age and blood pressure. I need to write a c++ program that will tell the number of each age group and each blood pressure group ( there are 3 age groups and 5 blood pressure groups).
You'll need a std::map<age,count> to histogram your data.
Loop through all the patients. For each one, get his age, and update the histogram:
1 2 3 4 5 6 7 8 9 10 11 12
// histogram the ages of the patients
std::map <unsigned, unsigned> ages;
for (each patient)
{
ages[ patient.age ] += 1;
}
// display the number of patients for each age
for (auto info : ages)
{
cout << "There are " << info.second << " patients who are " << info.first << " years old.\n";
}
It works the same way with blood pressures. (You can even combine the loops.)