1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

#include <iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int sum(int arr[],int size);
double average(int arr[],int size);
int smallestAt(int arr[],int size);
int largestAt(int arr[],int size);
void getCounts(int arr[],int size,int count[]);
int main()
{
const int STUDENTS=1000;
int scores[STUDENTS];
ifstream infile("scores.txt");
double avg;
int minScore,maxScore;
int counts[4]={0};
if(!infile)
{
cout<<"File failed to open.";
exit(1);
}
for(int i=0;i<STUDENTS;i++)
{
infile>>scores[i];
}
avg=average(scores,STUDENTS);
minScore=scores[smallestAt(scores,STUDENTS)];
maxScore=scores[largestAt(scores,STUDENTS)];
getCounts(scores,STUDENTS,counts);
cout<<"Average:\t"<<avg<<endl
<<"Min. Score:\t"<<minScore<<endl
<<"Max. Score:\t"<<maxScore<<endl
<<"Counts:"<<endl
<<"Excellent(95100): "<<counts[0] <<endl
<<"Satisfactory(8094): "<<counts[1]<<endl
<<"Normal (5079): "<<counts[2]<<endl
<<"Needs Improvement (049): "<<counts[3]<<endl;
cin.get();
return 0;
}
int sum(int arr[],int size)
{
int total=0;
for(int i=0;i<size;i++)
{
total+=arr[i];
}
return total;
}
double average(int arr[],int size)
{
int total=sum(arr,size);
return (double)total/(double)size;
}
int smallestAt(int arr[],int size)
{
int small=0;
for(int i=1;i<size;i++)
{
if(arr[small]>arr[i])
small=i;
}
return small;
}
int largestAt(int arr[],int size)
{
int large=0;
for(int i=1;i<size;i++)
{
if(arr[large]<arr[i])
large=i;
}
return large;
}
void getCounts(int arr[],int size,int count[])
{
int x;
for(int i=0;i<size;i++)
{
x=arr[i];
if(x<=100 && x>=95)
count[0]++;
else if(x<=94 && x>=80)
count[1]++;
else if(x<=79 && x>=50)
count[2]++;
else
count[3]++;
}
return;
}
 