Advertisement
Guest User

AVERAGE HEIGHT

a guest
Jan 16th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include<cstdlib>
  3. #include<cmath>
  4. using namespace std;
  5. typedef struct person{
  6. double age;
  7. double height;
  8. }PERSON;
  9. void create_person(PERSON *person0);
  10. double average_height(PERSON person0[], int sizE);
  11.  
  12. void display_person(PERSON person0);
  13. int main()
  14. {
  15. const int sizE=2;
  16. PERSON persons [sizE];
  17. for (int i=0;i<sizE;i++){
  18. create_person( &persons[i]);
  19. display_person( persons[i]);
  20.  
  21. }
  22. average_height(persons,sizE);
  23. cout<<""<<average_height(persons,sizE);
  24.  
  25. return 0;
  26. }
  27. double average_height(PERSON person0[], int sizE){
  28. double n=0,sum=0,avg;
  29. for (int i=0;i<sizE;i++){
  30. if(person0[i].age>20){
  31. sum+=person0[i].height;
  32. n++;
  33. }
  34. }
  35. avg=sum/n;
  36. return avg;
  37. }
  38. double n(PERSON person0[], int sizE){
  39. double n=0;
  40. for (int i=0;i<sizE;i++){
  41. if(person0[i].age>20){
  42. n++;
  43. }
  44. }
  45. return n;
  46. }
  47. void create_person(PERSON *person0){
  48. person0->age=rand()%100+20.;
  49. person0->height=rand()%56+150.;
  50. }
  51. void display_person(PERSON person0){
  52. cout<<"person details"<<endl;
  53. cout<<"age"<<person0.age<<endl;
  54. cout<<"height"<<person0.height<<endl;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement