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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void number_subject(int&, bool&);
void score_subject(int[], int[], int);
double average_compute(int[], int[], int);
double frac_to_decimal(int, int);
double deviation_compute(int[], int[], int, double);
double percentage(double&, double&);
void output(float, float, float);
void another_set(char&);
int main()
{
bool quit=false, error=false;
int subject;
double average_score, standard_deviation,percent;
char choice;
do
{
number_subject(subject, error);
if (error==true)
continue;
int*numerator=new int [subject];
int*denominator=new int [subject];
score_subject(numerator, denominator, subject);
average_score=average_compute(numerator, denominator, subject);
standard_deviation=deviation_compute(numerator, denominator, subject, average_score);
percent=percentage(average_score, standard_deviation);
output(average_score, standard_deviation, percent);
another_set(choice);
}while (choice=='y');
system("pause");
return 0;
}
void number_subject(int& subject, bool& error)
{
cout<<"Please enter total number of subjects registered by the students:"<<endl;
cin>>subject;
if (subject<=0)
{
cout<<"Please reenter new value!!!"<<endl;
error=true;
}
}
void score_subject(int numerator[], int denominator[], int subject)
{
cout<<"Please enter a series scores (in fraction) of the "<<subject<<" subjects: "<<endl;
for(int x = 0; x<subject; x++)
{
cin>>numerator[x];
cin>>denominator[x];
}
}
double average_compute(int numerator[], int denominator[], int subject)
{
int sum = 0;
for(int x=0;x<subject;x++)
sum += frac_to_decimal(numerator[x],denominator[x]);
return (sum/subject)*100;
}
double deviation_compute(int numerator[], int denominator[], int subject, double average_score)
{
int sum = 0;
double a, b, standard_deviation;
for(int x = 0; x<subject; x++)
{
a=frac_to_decimal(numerator[x], denominator[x]);
a*=100;
a-=average_score;
b=pow(a,2);
sum+=b;
}
standard_deviation = sqrt((1.0/subject)*sum);
return (standard_deviation);
}
double frac_to_decimal(int numerator, int denominator)
{
double decimal;
decimal = double(numerator)/double(denominator);
return(decimal);
}
double percentage(double& average_score, double& standard_deviation)
{
return((standard_deviation/average_score)*100);
}
void output(float average_score, float standard_deviation, float percent)
{
cout<<"The average of input scores is: "<<average_score<<endl;
cout<<"The standard deviation is: "<<standard_deviation<<endl;
cout<<"The deviation is "<<percent<<" % greater than the average!"<<endl;
if(percent>20)
cout<<"Special attention should be given to the students."<<endl;
else
cout<<"No special attention should be given to the students."<<endl;
}
void another_set(char& choice)
{
bool quit=false;
do
{
cout<<"Try again? (y/n):"<<endl;
cin>>choice;
if (choice=='n')
quit=true;
}while(choice!='y' && choice!='n');
}
|