Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // functions.cpp : main project file.
- #include "stdafx.h"
- #include <iomanip>
- #include <iostream>
- #include <conio.h>
- using namespace System;
- using namespace std;
- int no_students(int min,int max);
- void get_heights(float heights[],int size);
- float averge_height(float heights[],int size);
- void statistics(int & above, int & below, float heights [], int size, float average);
- void get_heights(float heights[], int size)
- {
- int c;
- Console::Clear();
- cout << "\n\n\n" << setw(45) << "Create array of Student Heights " << setw(5) << "of " << setw(5) << size << setw(10) << "Students" << "\n\n\n";
- for (c=0;c<size;c++)
- {
- cout << "\n" << setw(40) << "Enter Height " ;
- cin >> heights[c];
- }
- }
- float average_height(float heights[],int size)
- {
- int c;
- float average,tot_height=0;
- for (c=0;c<size;c++)
- tot_height = tot_height + heights[c];
- average = tot_height / size;
- return average;
- }
- void statistics (int & above, int & below, float heights [], float average,int size)
- {
- int c;
- for (c=0;c<size;c++)
- {
- if (heights[c] >= average)
- above++;
- else
- below++;
- }
- }
- int no_students(int min, int max)
- {
- int no;
- cout << "\n\n\n" << setw(30) << "Enter number between "
- << setw(5) << min << setw(8) << " and "
- << setw(5) << max << "\n\n\n";
- do
- {
- cout << "\n"<< setw(50) << "Number " ;
- cin >> no;
- }while (no<min||no>max);
- return no;
- }
- void main(void)
- {
- int howmany;
- float student_heights[500],average_student_height;
- int above_average=0,below_average=0;
- howmany = no_students(1,500);
- get_heights(student_heights,howmany);
- average_student_height = average_height(student_heights,howmany);
- statistics (above_average,below_average,student_heights,average_student_height,howmany );
- cout << "\n\n\n\n"
- << setw(45) << "Average Height " << setw(10) << average_student_height << "\n\n"
- << setw(45) << "No above average height " << setw(10) << above_average << "\n\n"
- << setw(45) << "No below average height " << setw(10) << below_average << "\n\n";
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement