#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
//Global Infile and Outfile
ifstream fin;
ofstream fout;
//Function Prototypes
void eofwhileloopfn(ifstream &fin, ofstream &fout,
string name[2],float score[6],float avg[3]);
void inputfn(ifstream &fin,string name[2], float score[6]);
void calcfn(float score[6],float avg[3]);
void outputfn(ifstream &fin, ofstream &fout,
string name[2],float score[6], float avg[3]);
int main ()
{
system ("color f0");
string name[2];
float score[6], avg[3];
char inputfile[51];//stores name of the input file
char outputfile[51];//variable to store the name of the output file
cout<<left<<fixed<<showpoint<<setprecision(2);
cout<<"Enter the input file name: ";
cin>>inputfile;
cout<<endl;
fin.open(inputfile);
if (!fin)
{
cout<<"Cannot open the input file. "<<endl;
system("pause");
return 1;
}
cout<<"Enter the output file name: ";
cin>>outputfile;
cout<<endl;
fout.open(outputfile);
// The End-of-File While Loop Function
eofwhileloopfn (fin,fout,name,score,avg);
fin.close();
fout.close();
system ("pause");
return 0;
}//end of main fn
//***********************************************************************
void eofwhileloopfn(ifstream &fin, ofstream &fout,
string name[2],float score[6], float avg[3])
//float sum
{
//End-Of-File Controlled While Loop
//Call Other Functions Inside of Loop
while (!fin.eof())
{
inputfn(fin,name,score);
calcfn (score,avg);
outputfn(fin,fout,name,score,avg);
}
}//End of Loop Function
//************************************************************************
void inputfn(ifstream &fin, string name[2], float score[6])
{
//File Input
fin>>name[0]>>name[1];
for (int col=0;col<6;col++)
{fin>>score[col];}//col represents index
}
//***********************************************************************
void calcfn(float score[6],float avg[3])
//int sum [2]
{
cout<<left<<fixed<<showpoint<<setprecision(2);
//Program Average
//Test Average
for (int col=0;col<6;col++)
{
while (col<3)
//for (int col=0;col<3;col++)
{
avg[0]=float(score[col]+score[col]+score[col]);
}
while (col>3||col<6)
//for (int col=0;col<6;col++)
{
avg[1]=float(score[col]+score[col]+score[col]);
}
}
//Course Average
avg[0]=avg[0]/3.0;
avg[1]=avg[1]/3.0;
avg[2]=(avg[0]+avg[1])/2.0;
}//end of calculation function
//***********************************************************************
void outputfn(ifstream &fin, ofstream &fout,
string name[2],float score[6],float avg[3])
{
cout<<left<<setw(20)<<name[0]+" "+name[1];
for (int col=0;col<3;col++)
{cout<<left<<setw(5)<<avg[0]<<setw(5)<<avg[1]<<setw(5)<<avg[2];}
cout<<endl;
}//End of Output Function
//***********************************************************************
Please ignore the "//float sum" 's, I was just trying to use those to play around with the calculations.
Attached File(s)
-
input.txt (258bytes)
Number of downloads: 15

New Topic/Question
Reply



MultiQuote





|