Display not working

Status
Not open for further replies.

hab_83

Honorable
May 1, 2012
4
0
10,510
#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";
}
 

hab_83

Honorable
May 1, 2012
4
0
10,510
You are to write a C++ program to compute the final grade for a course. Student ID numbers, which should be pure numerical number and may be as large as nine digits, identifies students. The final grade is composed of two parts, homework average counts for 40 percent and test average counts for 60 percent. There are two tests; each has maximum points of 100. There are seven homework assignments, with maximum points of 25, 30, 40, 50, 35, 35 and 50 respectively. Homework average is computed by adding all the homework scores together then divide by maximum possible points. The final grade needs to be converted to letter grade, and the scale is listed below:

> 90 A
80 – 89.9 B
70 – 79.9 C
60 – 69.9 D
< 60 E

After each student's grade is determined, the program performs a statistics on the entire class by finding out how many A's, B's, C's, D's and E's in the class.

The program should read input from data file "prg5data.txt", which is included in the assignment folder. The output should go to file "prg5out.txt", which is to be created, and should have information for each student followed by class statistics. The average and final scores should always be printed with one decimal place.

The following is a sample data file, in the order of student id, two test scores, and seven homework scores on each line:

123456789 77.2 88.3 22 28 35 45 33 35 40
234567890 97.5 90 25 30 38 48 34 35 50
345678901 82.4 77.5 22.5 27 35.5 44 35 33 48

And the following is the sample output file:

STUDENT ID HW AVE TEST AVE FINAL SCORE GRADE

123456789 89.8 82.8 85.6 B
234567890 98.1 93.8 95.5 A
345678901 92.5 80.0 85.0 B

Number of A's: 1
Number of B's: 2
Number of C's: 0
Number of D's: 0
Number of E's: 0
 

hab_83

Honorable
May 1, 2012
4
0
10,510
my problem at the getinput function. i'm trying find how many student in the file , but while(!infile.eof()) doesn't work.
while(!infile.eof())
{



infile>> std2.ID;

for(j=0; j<7; j++)
infile>> std2.grades.homework[j] ;

for(k=0; k<2; k++)
infile>> std2.grades.test[k];

size++;
i++;


}
infile.close();
return size;
}
 
Status
Not open for further replies.