Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. // functions.cpp : main project file.
  2.  
  3. #include "stdafx.h"
  4. #include <iomanip>
  5. #include <iostream>
  6. #include <conio.h>
  7.  
  8. using namespace System;
  9. using namespace std;
  10.  
  11. int no_students(int min,int max);
  12. void get_heights(float heights[],int size);
  13. float averge_height(float heights[],int size);
  14. void statistics(int & above, int & below, float heights [], int size, float average);
  15.  
  16. void get_heights(float heights[], int size)
  17. {
  18. int c;
  19. Console::Clear();
  20. cout << "\n\n\n" << setw(45) << "Create array of Student Heights " << setw(5) << "of " << setw(5) << size << setw(10) << "Students" << "\n\n\n";
  21. for (c=0;c<size;c++)
  22. {
  23. cout << "\n" << setw(40) << "Enter Height " ;
  24. cin >> heights[c];
  25. }
  26. }
  27.  
  28. float average_height(float heights[],int size)
  29. {
  30. int c;
  31. float average,tot_height=0;
  32. for (c=0;c<size;c++)
  33. tot_height = tot_height + heights[c];
  34. average = tot_height / size;
  35. return average;
  36. }
  37.  
  38. void statistics (int & above, int & below, float heights [], float average,int size)
  39. {
  40. int c;
  41. for (c=0;c<size;c++)
  42. {
  43. if (heights[c] >= average)
  44. above++;
  45. else
  46. below++;
  47. }
  48. }
  49.  
  50. int no_students(int min, int max)
  51. {
  52. int no;
  53. cout << "\n\n\n" << setw(30) << "Enter number between "
  54. << setw(5) << min << setw(8) << " and "
  55. << setw(5) << max << "\n\n\n";
  56. do
  57. {
  58. cout << "\n"<< setw(50) << "Number " ;
  59. cin >> no;
  60. }while (no<min||no>max);
  61.  
  62. return no;
  63. }
  64.  
  65. void main(void)
  66. {
  67. int howmany;
  68. float student_heights[500],average_student_height;
  69. int above_average=0,below_average=0;
  70.  
  71. howmany = no_students(1,500);
  72.  
  73. get_heights(student_heights,howmany);
  74.  
  75. average_student_height = average_height(student_heights,howmany);
  76.  
  77. statistics (above_average,below_average,student_heights,average_student_height,howmany );
  78.  
  79. cout << "\n\n\n\n"
  80. << setw(45) << "Average Height " << setw(10) << average_student_height << "\n\n"
  81. << setw(45) << "No above average height " << setw(10) << above_average << "\n\n"
  82. << setw(45) << "No below average height " << setw(10) << below_average << "\n\n";
  83. getch();
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement