Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A health visitor at a school is going to measure the heights of all pupils. For

ID: 3635220 • Letter: A

Question

A health visitor at a school is going to measure the heights of all pupils. For a class she makes a
statistics giving the number of pupils of each height and the average height.

Make a C++ program that helps the health visitor making the statistics. Divide your program into
functions that do the following



Reading pupils' heights (assume the heights range from 160cm to 170cm only)



statistics of the number of pupils of each height

• the class height average
Example: In a class with 10 pupils the heights of the individual pupils, in centimeters, are:

166, 167, 160, 165, 170, 165, 165, 170, 160, 162

The program should read in all the numbers and outputs a table like this:

Height
160
161
162
163
164
165
166
167
168
169
170
Average height 163.9

number of pupils
2
0
1
2
1
2
0
1
0
0
1

Page 2 of 5

Explanation / Answer

#include<iostream>
using namespace std;
void read(int a[])
{
for(int i=0; i<10; i++)
{
cout << " enter height :"<<endl;
cin >> a[i];
}
}
double avg(int a[])
{
int sum = 0;
for(int i=0; i<10; i++)
sum = sum + a[i];
double avg = static_cast<double> (sum)/10.0;
return avg;
}
void numofppl(int a[],int b[])
{
for(int i=0; i<10; i++)
{
b[170-a[i]]++;
}
}
int main()
{
int a[10];
int b[11];
for(int i=0; i<11; i++)
b[i]=0;
read(a);
numofppl(a,b);
cout << " Height " << " number of pupil " << endl;
for(int i=0; i<11; i++)
cout << (160+i) << "              "<< b[i] << endl;
cout << " average height given by " << avg(a);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote