Advertisement
Guest User

dsadas

a guest
Feb 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. // ConsoleApplication12.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. struct peopleData {
  11. char sex[2];
  12. int varsta;
  13. float greutate, inaltime;
  14. };
  15.  
  16. peopleData people[128];
  17.  
  18. int n;
  19.  
  20. void inputData(peopleData people[], int n) {
  21. for (int i = 1; i <= n; i++) {
  22. cout << "Introdu sexul persoanei " << i << ": ";
  23. cin.get(people[i].sex, 2);
  24. cin.get();
  25. cout << endl;
  26. cout << "Introdu varsta persoanei " << i << ": ";
  27. cin >> people[i].varsta;
  28. cout << endl;
  29. cout << "Introdu greutatea persoanei " << i << ": ";
  30. cin >> people[i].greutate;
  31. cout << endl;
  32. cout << "Introdu inaltimea persoanei " << i << ": ";
  33. cin >> people[i].inaltime;
  34. cout << endl;
  35. }
  36. }
  37.  
  38. int globalMb, globalMg, globalM, globalF;
  39.  
  40. void percent(peopleData people[], int n) {
  41. int male = 0, female = 0;
  42. for (int i = 1; i <= n; i++) {
  43. if (people[i].sex == "M") male++;
  44. else female++;
  45. }
  46.  
  47. globalM = male;
  48. globalF = female;
  49.  
  50. int perc = (male / n) * 100;
  51. cout << "Procentajul barbatilor este de " << perc << " iar cel al femeilor este de " << 100 - perc << endl;
  52. }
  53.  
  54. void medAge(peopleData people[], int n) {
  55. int mg = 0, sb = 0, male = 0, mb = 1;
  56. for (int i = 1; i <= n; i++) {
  57. mg += (people[i].varsta);
  58. if (people[i].sex == "M")
  59. {
  60. sb += (people[i].varsta);
  61. male++;
  62. }
  63. }
  64. globalMg = mg;
  65. mb = sb / male;
  66. cout << "Varsta medie a grupului este: " << mg/n << " iar a barbatilor: " << mb << ". \n";
  67. }
  68.  
  69. void percFemMale(peopleData people[], int n) {
  70. int countFem = 0, countMale = 0;
  71. for (int i = 1; i <= n; i++) {
  72. if (people[i].sex == "M" && people[i].varsta > globalMg) countMale++;
  73. else if (people[i].sex == "F" && people[i].varsta > globalMg) countFem++;
  74. }
  75. int percFem = (countFem / n) * 100;
  76. cout << "Procentul de femei este: " << percFem << " iar cel de barbati este: " << 100 - percFem;
  77. }
  78.  
  79. void medHeight(peopleData people[], int n) {
  80. int hM = 0, hFem = 0;
  81. for (int i = 1; i <= n; i++) {
  82. hM += (people[i].inaltime);
  83. if (people[i].sex == "F")
  84. hFem += people[i].inaltime;
  85. }
  86. float hFemMed = hFem / globalF;
  87. float hMedG = hM / n;
  88. cout << "Inaltimea medie a grupului este: " << hMedG << " iar a femeilor este: " << hFemMed << endl;
  89. int countFem = 0, countMale = 0;
  90. for (int i = 1; i <= n; i++) {
  91. if (people[i].sex == "M" && people[i].inaltime > hMedG) countMale++;
  92. else if (people[i].sex == "F" && people[i].inaltime > hMedG) countFem++;
  93. }
  94. int percFem = (countFem / n) * 100;
  95. cout << "Procentul de femei este: " << percFem << " iar cel de barbati este: " << 100 - percFem;
  96.  
  97. }
  98.  
  99. void medWeight(peopleData people[], int n) {
  100. int groupWeight = 0, maleWeight = 0, femWeight = 0;
  101. for (int i = 1; i <= n; i++) {
  102. groupWeight += people[i].greutate;
  103. if (people[i].sex == "M")
  104. maleWeight += people[i].greutate;
  105. else femWeight += people[i].greutate;
  106. }
  107. cout << "Greutatea medie a grupului: " << groupWeight / n << " , cea a femeilor: " << femWeight / globalF << " iar cea a barbatilor: " << maleWeight / globalM;
  108.  
  109. int countFem = 0, countMale = 0;
  110. for (int i = 1; i <= n; i++) {
  111. if (people[i].sex == "M" && people[i].greutate > groupWeight / n) countMale++;
  112. else if (people[i].sex == "F" && people[i].greutate > groupWeight / n) countFem++;
  113. }
  114. int percFem = (countFem / n) * 100;
  115. cout << "Procentul de femei este: " << percFem << " iar cel de barbati este: " << 100 - percFem;
  116. }
  117.  
  118. int main()
  119. {
  120. cout << "Mentioneaza numarul de persoane: ";
  121. cin >> n;
  122.  
  123. inputData(people, n);
  124. percent(people, n);
  125. medAge(people, n);
  126. percFemMale(people, n);
  127. medHeight(people, n);
  128. medWeight(people, n);
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement