fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. float calculateBodyMassIndex (int height, int weight);
  7. void rateLevelOfObesityBasedOnBmi (float bmi, string forename, vector <string>& peopleWithUnderweight,
  8. vector <string>& peopleWithCorrectWeight,
  9. vector <string>& peopleWtihOverweight);
  10. void showObesityClassificationsOfPeople (vector <string>& peopleWithUnderweight,
  11. vector <string>& peopleWithCorrectWeight,
  12. vector <string>& peopleWtihOverweight);
  13.  
  14. int main()
  15. {
  16. int numberOfPeople;
  17. cin >> numberOfPeople;
  18. string forename;
  19. int weight, height;
  20.  
  21. vector <string> peopleWithUnderweight;
  22. vector <string> peopleWithCorrectWeight;
  23. vector <string> peopleWtihOverweight;
  24.  
  25. for(int i = 0; i < numberOfPeople; i++)
  26. {
  27. cin >> forename;
  28.  
  29. float bmi = calculateBodyMassIndex (height, weight);
  30. rateLevelOfObesityBasedOnBmi (bmi, forename, peopleWithUnderweight, peopleWithCorrectWeight, peopleWtihOverweight);
  31. }
  32. if (numberOfPeople == 0)
  33. return 0;
  34. showObesityClassificationsOfPeople (peopleWithUnderweight, peopleWithCorrectWeight, peopleWtihOverweight);
  35.  
  36. return 0;
  37. }
  38.  
  39. float calculateBodyMassIndex (int height, int weight)
  40. {
  41. do
  42. cin >> weight;
  43. while (weight <= 0);
  44. do
  45. cin >> height;
  46. while (height <= 0);
  47.  
  48. float bmi = (weight/((height/100)*(height/100)));
  49. return bmi;
  50. }
  51.  
  52. void rateLevelOfObesityBasedOnBmi (float bmi, string forename, vector <string>& peopleWithUnderweight,
  53. vector <string>& peopleWithCorrectWeight,
  54. vector <string>& peopleWtihOverweight)
  55. {
  56. if (bmi < 18.5)
  57. peopleWithUnderweight.push_back(forename);
  58. else if ((bmi >= 18.5) && (bmi < 25))
  59. peopleWithCorrectWeight.push_back(forename);
  60. else if (bmi >= 25)
  61. peopleWtihOverweight.push_back(forename);
  62. }
  63.  
  64. void showObesityClassificationsOfPeople (vector <string>& peopleWithUnderweight,
  65. vector <string>& peopleWithCorrectWeight,
  66. vector <string>& peopleWtihOverweight)
  67. {
  68. cout << "niedowaga" << endl;
  69. for(int i = 0; i < peopleWithUnderweight.size(); i++)
  70. cout << peopleWithUnderweight[i] << endl;
  71.  
  72. cout << '\n';
  73. cout << "waga prawidlowa" << endl;
  74. for(int i = 0; i < peopleWithCorrectWeight.size(); i++)
  75. cout << peopleWithCorrectWeight[i] << endl;
  76.  
  77. cout << '\n';
  78. cout << "nadwaga" << endl;
  79. for(int i = 0; i < peopleWtihOverweight.size(); i++)
  80. cout << peopleWtihOverweight[i] << endl;
  81. }
  82.  
Success #stdin #stdout 0s 16056KB
stdin
Standard input is empty
stdout
Standard output is empty