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
|
#include <iostream>
#include <fstream>
#include <cassert>
#include <string>
using namespace std;
void openfile(ifstream& infilename);
void getscores(double scores[], ifstream& infile, int& size);
void findmax(double scores[], ifstream& infile, int size, double& max);
void findmin(double scores[], ifstream& infile, int size, double& min);
//Call all functions and display data.
int main()
{
ifstream infile;
double scores[15], min, max, sum;
int size;
openfile(infile);
getscores(scores, infile, size);
findmax(scores, infile, size, max);
findmin(scores, infile, size, min);
system("pause");
return 0;
}
//Locate and open the input file.
void openfile(ifstream& infile)
{
string infilename;
cout << "Enter the name of the input file: ";
cin >> infilename;
infile.open(infilename);
assert(infile);
}
//Get scores from user, store in file
void getscores(double scores[], ifstream& infile, int& size)
{
int i = 0;
do
{
infile >> scores[i];
i++;
}
while (infile);
size = i - 1;
}
//Find the highest score.
void findmax(double scores[], ifstream& infile, int size, double& max)
{
double max = scores[0];
for (int i = 0; i < size; i++)
if (scores[i] > max)
max = scores[i];
}
//Find the lowest score.
void findmin(double scores[], ifstream& infile, int size, double& min)
{
double min = scores[0];
for (int i = 1; i < size; i++)
if (scores[i] > min)
min = scores[i];
}
//Display all scores, dropped scores, and sum of remaining scores.
void calcdisplay(double scores[], ifstream& infile, int size, double max, double min, double& sum)
{
}
|