Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For research purposes and to better help students, the admissions office of your

ID: 3621214 • Letter: F

Question

For research purposes and to better help students, the admissions office of your local university wants to know how well female and male students perform in certain courses You receive a file that contains female and male student GPA's lor certain courses. Due to confidentiality, the letter code 'f' is used for female students and 'm' is used for male students Every file entry consists of a letter code followed by their GPA Each line has one entry The number of entries in the file is unknown What a program that computes and outputs the average GPA for both female and male students Format your results to two decimal places Your program should use the following functions. Function open Files: This function opens the input and output files and sets the output of the floating-point numbers to two decimal places in a fixed decimal format with a decimal point and trailing zeroes. Function initialize: This function initializes variables such as countFemale. countMale. sumFemaleGPA and sumMaleGPA. Function sumGradev This function finds the sum of the female and male students' GPA Function averageGrade: this function finds the average GPA for male and female students. Function printResults: This function outputs the relevant results.

Explanation / Answer

please rate - thanks

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int openFiles(ifstream&, ofstream&);
void initialize(int&,double&);
void sumGrades(double&,double,int&);
double averageGrade(double,int);
void printResult(int,double,string,ofstream&);
int main(void)
{ ifstream in;
ofstream out;
int countFemale, countMale;
double sumFemaleGpa, sumMaleGpa,gpa;
char gend;
if(openFiles(in,out)!=0)
    {system("pause");
    return 0;
    }  
initialize(countFemale,sumFemaleGpa);
initialize(countMale,sumMaleGpa);   
in>>gend;
while(in)
   {in>>gpa;
   if(gend=='m')
        sumGrades(sumMaleGpa,gpa, countMale);
   else
        sumGrades(sumFemaleGpa,gpa, countFemale);
   in>>gend;
   }    
printResult(countMale,sumMaleGpa, "males",out);
printResult(countFemale,sumFemaleGpa,"females",out);
in.close();
out.close();

system("pause");
return 0;
}
int openFiles(ifstream& in, ofstream& out)
{in.open("input.txt");           //open file
   if(in.fail())             //is it ok?
       { cout<<"input file did not open please check it ";
        return 1;
        }
out.open("output.txt");           //open file
out<<setprecision(2)<<fixed<<showpoint;
}
void initialize(int& c,double& s)
{c=0;
s=0;
}
void sumGrades(double& s,double g,int& c)
{c++;
s+=g;
}
double averageGrade(double s,int c)
{return s/c;
}
void printResult(int c,double s,string mess,ofstream& out)
{out<<"The average of the "<<c<<" "<<mess<<" is "<<averageGrade(s,c)<<endl;
}