Simple problem: The copy constructor for streams is protected, so you can't publicly access it. In your functions' arguments, change all of the streams to references. You did that for openFiles, but not for the other functions.
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
void openFiles(ifstream&, ofstream&);
void initialize();
void sumGrades(ifstream&, ofstream&, int&, int&, double&, double&);
void averageGrade(int, int, double, double, double&, double&);
void printResults(ifstream&, ofstream&, int, int, double, double, double, double);
int main()
{
cout << "See final.txt for results." << endl;
initialize();
system("pause");
return 0;
}
void initialize()
{
int countFemale = 0;
int countMale = 0;
double sumFemaleGPA = 0.0;
double sumMaleGPA = 0.0;
double averageMaleGPA = 0.0;
double averageFemaleGPA = 0.0;
ifstream inGrades;
ofstream outGrades;
openFiles(inGrades, outGrades);
sumGrades(inGrades, outGrades, countFemale, countMale, sumFemaleGPA, sumMaleGPA);
averageGrade(countFemale, countMale, sumFemaleGPA, sumMaleGPA, averageMaleGPA, averageFemaleGPA);
printResults(inGrades, outGrades, countFemale, countMale, sumFemaleGPA, sumMaleGPA, averageMaleGPA, averageFemaleGPA);
}
void openFiles(ifstream& inGrades, ofstream& outGrades)
{
inGrades.open("Ch7_Ex6Data.txt");
outGrades.open("final.txt");
outGrades << fixed << showpoint << setprecision(3);
}
void sumGrades(ifstream& inGrades, ofstream& outGrades, int& countFemale,
int& countMale, double& sumFemaleGPA, double& sumMaleGPA)
{
char gender;
double grade;
while (inGrades)
{
inGrades >> gender >> grade;
if (gender == 'm')
{
countMale++;
sumMaleGPA = sumMaleGPA + grade;
}
else
{
countFemale++;
sumFemaleGPA = sumFemaleGPA + grade;
}
}
}
void averageGrade(int countFemale, int countMale, double sumFemaleGPA, double sumMaleGPA,
double& averageMaleGPA, double& averageFemaleGPA)
{
averageMaleGPA = sumMaleGPA / countMale;
averageFemaleGPA = sumFemaleGPA / countFemale;
}
void printResults(ifstream& inGrades, ofstream& outGrades, int countFemale, int countMale,
double sumFemaleGPA, double sumMaleGPA, double averageMaleGPA, double averageFemaleGPA)
{
outGrades << "Processing Grades." << endl;
outGrades << inGrades;
outGrades << "Sum Female GPA:" << sumFemaleGPA << endl;
outGrades << "Sum Male GPA:" << sumMaleGPA << endl;
outGrades << "Male count:" << countMale << endl;
outGrades << "Female count:" << countFemale << endl;
outGrades << "Male Average:" << averageMaleGPA << endl;
outGrades << "Female Average:" << averageFemaleGPA << endl;
inGrades.close();
outGrades.close();
}