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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int read_into_array(ifstream& inf, int scores[], int size);
void print_score_statistics(ifstream& inf, int scores[], int size);
string file;
ifstream inf;
int value;
int scores[100];
int main()
{
cout << "Please enter the file name." << endl;
cin >> file;
int index = read_into_array(inf, scores, 100);
print_score_statistics(inf, scores, index);
inf.close();
}
int read_into_array(ifstream& inf, int scores[], int size)
{
int index = 0;
inf.open(file);
if (inf.fail())
{
cout << "Error retrieving input file." << endl;
}
cout << "The scores follow." << endl;
while (inf >> scores[index])
{
cout << scores[index] << endl << endl;
index++;
}
return index;
}
void print_score_statistics(ifstream& inf, int scores[], int size)
{
int next = 0, highest = 0, lowest = 0, pass = 0, fail = 0;
highest = scores[0];
lowest = scores[0];
for (int i = 0; i < size; i++)
{
if (scores[i] < lowest)
{
lowest == scores[i];
}
if (scores[i] > highest)
{
highest = scores[i];
}
if (scores[i] >= 60)
{
pass++;
}
else if (scores[i] < 60)
{
fail++;
}
}
cout << "The highest score is: " << highest << endl;
cout << "The lowest score is: " << lowest << endl;
cout << "The number of passing scores are: " << pass << endl;
cout << "The number of failing scores are: " << fail << endl;
}
|