Grade manager program with header and class cpp (does not work)

I've been looking at this program for hours and I've had no luck solving the many problems here in. Its supposed to take each students grades from an input file and display then using an array. Then display the class average as well as each student's average like so

name a1 a2 a3 a4 a5 avg
----- ---- --- --- --- --- ----
john smith 87 76 90 67 98 90
tina pot 80 90 90 99 100 97

below are my files, I'm sorry for the mismatched comments, I was trying to re-purpose an example program from my C++ class. also if this is in the wrong section and belongs posted in the "beginners section" let me know and I will repost.


// student cpp

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

#include <iostream>
#include <iomanip>
using namespace std;


#include "Student.h"


// Constants for displaying items in fixed width fields.
const int STUDENT_NAMEF_WIDTH = 15;
const int STUDENT_NAMEL_WIDTH = 15;
const int STUDENT_SCORE_WIDTH = 10;



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

for (int count = 0; count < ASSIGNMENT; count++)
score[count]=0;
})


// Display header lines for an output table .
// 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 InvenItem::displayHeader()
{
// Display name left-justified, then set justification
// back to right for the numbers.
cout << left << setw(STUDENT_NAMEF_WIDTH) << "" << setw(STUDENT_NAMEL_WIDTH) right;
//for loop needed
for (int count = 0; count < ASSIGNMENT; count++)
cout << setw(STUDENT_SCORES_WIDTH) << "Scores";



// Display average
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 * (ASSIGNMENTS + 1);

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

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


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 < ASSIGNMENTS; count++)
cout << setw(STUDENT_SCORES_WIDTH) << scores[count];


cout << setw(STUDENT_SCORES_WIDTH) << getAverage() << endl;
} // ::display()


// Read scores 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 < 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()

//problem area
void Student::setScore( int assignmentNum, double grade )
{
if ( assignmentNum <= MAX_ASSIGNMENTS && assignmentNum > 0 )
{
assignmentNum-1=i
score[i] = grade;
return grade;
} // if
else
{
return 0;
}
} // InvenItem::setQuantity()

//get a valid score (problem area)
double Student::getScore( int grade )
{
if ( grade >= 0.0 )
{
grade = score[i];
} // if
} // student::getscore()


// Return the average using a for loop (problem area)
double Student::getAverage()
{
for (int count=0; count < ASSIGNMENTS; count++)
{
int total=0
int grade += total;
}
int average=(total/ASSIGNMENTS);
return average;
} // getAverage()








// student.h file

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

#ifndef STUDENT_H
#define STUDENT_H


const int ASSIGNMENTS = 5;

// Student class declaration
class Student
{
private:
string firstName;
string lastName;
double scores[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;
}

}; // class Student

#endif // STUDENT_H






//grade manager main

#include <iostream>
using namespace std;

#include "Student.h"


const int MAX_ASSIGNMENTS = 100;


// Read an entire array of inventory items from the specified file stream.
// Use the readFromFile() member function to read each item; if it returns
// true, the item was successfully read. Once it returns false, there is
// no data left to read.
int readArrayStudentGrades( ifstream &file, Student scores[], int maxSize )
{
int count = 0;

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

return count;
} // readArraystudentgrades()


// Display an inventory report, with a header displayed first.
// Keep track of the value of all items, and display that at the end.
void display( Student scores[], int size )
{
double total = 0.0;

// Display the header line (any element of the array can do this,
// we'll use index 0)
scores[0].displayHeader();

// Display each item, one at a time, and track the total value
for ( int i = 0; i < size; i++ )
{
scores[i].display();
total += scores[i].getAverage();
} // for i

cout << endl << endl;
cout << "The Class Average was " << Average << 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 = readArrayStudent( dataFile, items, MAX_SIZE );
displayReport( scores, count );

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





Topic archived. No new replies allowed.