I need a lot of help

I'm having a lot of trouble writing this program. It's supposed to take student grades from an input file and display them next to the students name. and then display the class average at the bottom. I know this is really bad code but if anyone could help me I would be really grateful. Below are the .h file, the student class, and the main. I've been trying to get this all weekend. please help.

CLASS

/ A class to store information about a student
#include <iostream>
#include <iomanip>
using namespace std;


#include "Student.h"


// Constants for displaying items in fixed width fields.
const int STUDENT_FIRSTNAME_WIDTH = 15;
const int STUDENT_LASTNAME_WIDTH = 15;
const int STUDENT_SCORES_WIDTH = 10;


// Default constructor.
Student::Student()
{
firstName = "";
lastName = "";

for (int count = 0; count < MAX_ASSIGNMENTS; count++)
scores[count]=0;
}


.
// This is part of the class, because this function can be kept in
// synchronization with the display() member function (say if the
// field widths were to change).
void Student::displayHeader()
{
// Display name left-justified, then set justification
// back to right for the numbers.
cout << left << setw(STUDENT_FIRSTNAME_WIDTH) << "" << setw(STUDENT_LASTNAME_WIDTH) << right;
//for loop needed
for (int count = 0; count < MAX_ASSIGNMENTS; count++)
cout << setw(STUDENT_SCORES_WIDTH) << "Scores";




// Display total value of this item in inventory
cout << setw(STUDENT_SCORES_WIDTH) << "Average" << endl;

// Display a line of dashes that is just long enough
int width = STUDENT_FIRSTNAME_WIDTH + STUDENT_LASTNAME_WIDTH + STUDENT_SCORES_WIDTH * (MAX_ASSIGNMENTS + 1);

for ( int i = 0; i < width; i++ )
cout << "-";

cout << endl;
} // InvenItem::displayHeader()


// Display a InvenItem record in a format suitable for columns in a table.
void Student::display()
{
// Set output format for the monetary values
cout << fixed << showpoint << setprecision(2);

// Display name left-justified, then set justification
// back to right for the numbers.
cout << left << setw(STUDENT_FIRSTNAME_WIDTH) << firstName;
cout << setw(STUDENT_LASTNAME_WIDTH) << lastName << right;

for (int count = 0; count < MAX_ASSIGNMENTS; count++)
cout << setw(STUDENT_SCORES_WIDTH) << scores[count];

// Display total value of this item in inventory
cout << setw(STUDENT_SCORES_WIDTH) << getAverage(average) << endl;
} // InvenItem::display()


// Read an inventory item from an input file, if possible.
// Returns true if item was successfully read, false otherwise.
bool Student::readFromFile( ifstream &file )
{
if ( file >> firstName >> lastName )
{
for (int count = 0; count < MAX_ASSIGNMENTS; count++)
file >> scores[count];
return true;
}

// Could not read from scores.txt

return false;
} // InvenItem::readFromFile()


// Allow the user to change the name with no restrictions.
// Note that this simple function could also be written inline.
void Student::setNames( string nameF, string nameL )
{
firstName = nameF;
lastName = nameL;
} // InvenItem::setName()


// Allow the user to change the item quantity only if it is valid
// (greater than or equal to zero).
// If the parameter is in valid, it is ignored.
void Student::setScores( int assignmentNum, double newScore )
{

if ( assignmentNum <= MAX_ASSIGNMENTS && assignmentNum >= 0 )
{
int i = assignmentNum-1
scores[i] = newScore;
} // if

} // InvenItem::setQuantity()


// Allow the user to change the item's price only if it is valid
// (greater than or equal to zero).
// If the parameter is in valid, it is ignored.
double Student::getScores( int assignmentNumber )
{
if ( assignmentNumber <= MAX_ASSIGNMENTS )
{
int ArrayNum = assignmentNumber-1;
return scores[ArrayNum];
} // if
else
{
return 0;
}
} // student::getscore()


// Return the average using a for loop
double Student::getAverage( )
{
double total=0;
for (int count=0; count < MAX_ASSIGNMENTS; count++)
{
int assignmentNumber = count;
total += scores[assignmentNum];
}
double average=(total/MAX_ASSIGNMENTS);
return average;
}





.H file
// A class to store information about an inventory item.

#include <string>
#include <fstream>
using namespace std;

#ifndef STUDENT_H
#define STUDENT_H


const int MAX_ASSIGNMENTS = 5;

// Student class declaration
class Student
{
private:
string firstName;
string lastName;
double scores[MAX_ASSIGNMENTS];

public:
// Default constructor
Student();


// Display the grade data in a standard format
void displayHeader();
void display();

// Read info item from a data file
bool readFromFile( ifstream &file );

// Student's data
void setNames( string, string );



// Retrieve the item name
string getFirst()
{
return firstName ;
}

// Retrieve the
string getLast()
{
return lastName;
}

void setScores(int, double);

double getScores(int);


double getAverage(double);



}; // class Student

#endif // STUDENT_H








MAIN




#include <iostream>
using namespace std;

#include "Student.h"


const int MAX_SIZE = 100;


// Read an entire array of scores from the specified file.
int readArrayScores( ifstream &file, Student scores[], int maxSize )
{
int count = 0;

while ( count < maxSize && scores[count].readFromFile( file ) )
{
count++;
} // while

return count;
} // readArrayScores()

//display layout for grade manager
void displayReport( Student scores[], int size )
{
double total = 0.0;

// Display the header line
scores[0].displayHeader();

//would be student grades
//would be student grades
for ( int i = 0; i < size; i++ )
{
scores[i].display();
total += scores[i].getAverage(i);
} // for i

cout << endl << endl;
cout << "The class average was: " << total << endl << endl;
} // displayReport()




int main()
{
Student scores[MAX_SIZE];
int count;
ifstream dataFile;

dataFile.open( "scores.txt" );
if ( dataFile.fail() )
{
cout << "Could not open data file!" << endl;
exit( 1 );
} // if

count = readArrayScores( dataFile, scores, MAX_SIZE );
displayReport( scores[]; count );

system( "pause" );
return 0;
} // main()


again. please I know I'm asking a lot but i can't find any problems and I'm
desperate for help

Topic archived. No new replies allowed.