#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int const size=30;
struct studentgrade
{
int homework[7];
int test[2];
int hwAve;
int testAve;
int finalScore;
char grade;
};
struct studentType
{
int ID; //student's ID
studentgrade grades;
};
int acount;
int bcount;
int ccount;
int dcount;
int ecount;
int getInput (ifstream& indata,struct studentType std2[], int );
void process (ifstream& indata_pro,struct studentType std2[], int );
void display (ofstream& ouData, const struct studentType std2[], int );
int main()
{
studentType std1[size];
int num_student;
ifstream infile;
ofstream outfile;
infile.open("prg5data.txt"); //opens prog3a.dat
if(infile.fail()) //checks to see if file was able to open
{
cout << "Can't find file proData5" <<endl; //displays if file cannot be found
system("pause>NUL");
return 0;
}
num_student = getInput (infile, std1,size);
process (infile,std1, num_student);
infile.close();
outfile.open("prg5out.txt"); //opens prog3a.dat
if(outfile.fail()) //checks to see if file was able to open
{
cout << "Can't find file prog3a.dat" <<endl; //displays if file cannot be found
system("pause>NUL");
return 0;
}
//display (outfile, std1,num_student);
outfile.close();
return 0;
}
int getInput (ifstream& inData, studentType std2[], int num )
{
int j,k;
int size=0;
int i=0;
while (!inData.eof()) {
inData >> std2.ID ;
for(j=0; j<7; j++)
inData>> std2.grades.homework[j] ;
for(k=0; k<2; k++)
inData >> std2.grades.test[k];
size++;
}
return size;
//process (std1, size);
}
void process (ifstream& indata_pro, studentType std2[], int ie )
{
int testsum,hwsum,final;
int k;
for( k=0; k<ie; k++)
{
for (int i = 0; i < 2; i++)
{
testsum =+ std2[k].grades.test;
std2[k].grades.testAve= testsum / 2;
for (int j = 0; j < 7; j++)
{
hwsum =+ std2[k].grades.homework[j];
std2[k].grades.hwAve= hwsum / 7;
final = ( std2[k].grades.testAve * .6) + (std2[k].grades.hwAve * .4);
std2.grades.finalScore = final;
}}
if (std2[k].grades.finalScore > 90)
{
std2[k].grades.grade='A';
indata_pro >> std2[k].grades.grade;
acount++;
if(std2[k].grades.finalScore >80 && std2[k].grades.finalScore <89.9)
{
std2[k].grades.grade='B';
indata_pro >> std2[k].grades.grade;
bcount++;
}
else if(std2[k].grades.finalScore >70 && std2[k].grades.finalScore <79.9)
{
std2[k].grades.grade='C';
indata_pro >> std2[k].grades.grade;
ccount++;
}
else if(std2[k].grades.finalScore >60 && std2[k].grades.finalScore <69.9)
{
std2[k].grades.grade='D';
indata_pro>> std2[k].grades.grade;
dcount++;
}
else
{
std2[k].grades.grade='E';
ecount++;
}
}
indata_pro >> std2[k].grades.grade;
}}
void display (ofstream& outData, const studentType std2[], int num)
{
int index;
outData << "----------- Student Grade Report ---------"
<< "----" << endl;
outData << endl;
outData << " STUDENT ID HW AVE TEST AVE "
<< "FINAL SCORE GRADE" << endl;
outData << "____________________________________________"
<< "_________________" << endl;
for (index = 0; index <= num; index++)
{
outData << std2[index].ID << " ";
outData << setw(10)<< std2[index].grades.hwAve;
outData << setw(10) << std2[index].grades.testAve;
outData << setw(10) << std2[index].grades.finalScore;
outData << setw(10) << std2[index].grades.grade << endl;
}
outData << endl;
outData << "Number of A's: " << acount << endl;
outData << "Number of B's: " << bcount << endl;
outData << "Number of C's: " << ccount << endl;
outData << "Number of D's: " << dcount << endl;
outData << "Number of E's: " << ecount << endl;
// cout<<"successfully";
}
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int const size=30;
struct studentgrade
{
int homework[7];
int test[2];
int hwAve;
int testAve;
int finalScore;
char grade;
};
struct studentType
{
int ID; //student's ID
studentgrade grades;
};
int acount;
int bcount;
int ccount;
int dcount;
int ecount;
int getInput (ifstream& indata,struct studentType std2[], int );
void process (ifstream& indata_pro,struct studentType std2[], int );
void display (ofstream& ouData, const struct studentType std2[], int );
int main()
{
studentType std1[size];
int num_student;
ifstream infile;
ofstream outfile;
infile.open("prg5data.txt"); //opens prog3a.dat
if(infile.fail()) //checks to see if file was able to open
{
cout << "Can't find file proData5" <<endl; //displays if file cannot be found
system("pause>NUL");
return 0;
}
num_student = getInput (infile, std1,size);
process (infile,std1, num_student);
infile.close();
outfile.open("prg5out.txt"); //opens prog3a.dat
if(outfile.fail()) //checks to see if file was able to open
{
cout << "Can't find file prog3a.dat" <<endl; //displays if file cannot be found
system("pause>NUL");
return 0;
}
//display (outfile, std1,num_student);
outfile.close();
return 0;
}
int getInput (ifstream& inData, studentType std2[], int num )
{
int j,k;
int size=0;
int i=0;
while (!inData.eof()) {
inData >> std2.ID ;
for(j=0; j<7; j++)
inData>> std2.grades.homework[j] ;
for(k=0; k<2; k++)
inData >> std2.grades.test[k];
size++;
}
return size;
//process (std1, size);
}
void process (ifstream& indata_pro, studentType std2[], int ie )
{
int testsum,hwsum,final;
int k;
for( k=0; k<ie; k++)
{
for (int i = 0; i < 2; i++)
{
testsum =+ std2[k].grades.test;
std2[k].grades.testAve= testsum / 2;
for (int j = 0; j < 7; j++)
{
hwsum =+ std2[k].grades.homework[j];
std2[k].grades.hwAve= hwsum / 7;
final = ( std2[k].grades.testAve * .6) + (std2[k].grades.hwAve * .4);
std2.grades.finalScore = final;
}}
if (std2[k].grades.finalScore > 90)
{
std2[k].grades.grade='A';
indata_pro >> std2[k].grades.grade;
acount++;
if(std2[k].grades.finalScore >80 && std2[k].grades.finalScore <89.9)
{
std2[k].grades.grade='B';
indata_pro >> std2[k].grades.grade;
bcount++;
}
else if(std2[k].grades.finalScore >70 && std2[k].grades.finalScore <79.9)
{
std2[k].grades.grade='C';
indata_pro >> std2[k].grades.grade;
ccount++;
}
else if(std2[k].grades.finalScore >60 && std2[k].grades.finalScore <69.9)
{
std2[k].grades.grade='D';
indata_pro>> std2[k].grades.grade;
dcount++;
}
else
{
std2[k].grades.grade='E';
ecount++;
}
}
indata_pro >> std2[k].grades.grade;
}}
void display (ofstream& outData, const studentType std2[], int num)
{
int index;
outData << "----------- Student Grade Report ---------"
<< "----" << endl;
outData << endl;
outData << " STUDENT ID HW AVE TEST AVE "
<< "FINAL SCORE GRADE" << endl;
outData << "____________________________________________"
<< "_________________" << endl;
for (index = 0; index <= num; index++)
{
outData << std2[index].ID << " ";
outData << setw(10)<< std2[index].grades.hwAve;
outData << setw(10) << std2[index].grades.testAve;
outData << setw(10) << std2[index].grades.finalScore;
outData << setw(10) << std2[index].grades.grade << endl;
}
outData << endl;
outData << "Number of A's: " << acount << endl;
outData << "Number of B's: " << bcount << endl;
outData << "Number of C's: " << ccount << endl;
outData << "Number of D's: " << dcount << endl;
outData << "Number of E's: " << ecount << endl;
// cout<<"successfully";
}