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
|
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
void GetData (int TestScoresf [], int &Indexf);
void ComputeAvg(int TestScoresf[],int Indexf, float &Avgf);
void PrintReport (int TestScoref [], int Indexf, float Avgf);
//constant identifier
const int MaxSize = 10;
//Main body
int main()
{
//local identifiers
int TestScores [MaxSize];
int Index;
float Avg;
//function calls
GetData (TestScores, Index);
ComputeAvg (TestScores, Index, Avg);
PrintReport (TestScores, Index, Avg);
system("pause");
return 0;
} //end main
//function deffinitions
void GetData (int TestScoresf [], int &Index)
{
int Indexf = -1;
do
{
Indexf++;
cout<<"Please enter test #"<<Indexf + 1<<": <-1 to exit>\t";
cin>>TestScoresf[Indexf];
Index=Indexf;
} while ((TestScoresf[Indexf] >= 0) && (Indexf < MaxSize - 1));
return;
} //end of GetData
void ComputeAvg(int TestScoresf[],int Indexf, float &Avgf)
{
int sum = 0;
for (int i=0; i < Indexf; i++)
{
sum += TestScoresf[i];
}
Avgf = float (sum) / Indexf;
return;
} //end ComputeAvg
void PrintReport (int TestScoref [], int Indexf, float Avgf)
{
cout << "\n\n";
cout << setw(48)<< "Test Scores Report";
cout << "\n\n";
cout << setw(28)<< "Test Number" << setw(29) << "Test Score"<<endl;
for(int i=0;i<Indexf;i++)
{
cout<< setw(18)<<Indexf + 1<<setw(31)<<TestScoref[i]<<endl;
cout<<endl<<fixed<<showpoint<<setprecision(2);
}
cout<<"Class average = "<<Avgf<<endl;
return;
|