I have a problem that I have not been able to figure out with this assignment. The idea is to write a grading program that will calculate the letter grade, and average while also giving exam scores for 5 students, each student has 4 exams. I have built it up to this and even viewed a similar assignment posted but didn't find that helpful. I have gone through the book which also isn't very helpful in this regard. I am receiving errors regarding the highlighted sections that deal with processing the file data into the program. Error code in Visual Studio LNK1120:1 unresolved externals. If I remove "student.input(input, thisStudent);" this bit of code the program will run but with garbage values and that is where hopefully someone can help me with. How can I properly direct the data from a file into exam1-4. Am I missing something? If I can get the program to run with correct values I should be able figure out the rest. Thanks in advance.

#include <iostream>
#include <fstream> // I/O
#include <iomanip> // For setw()
using namespace std;

ofstream     outputfile("output.txt");     // Output file

// Defined Constants
const int    MAX_FILE_NAME = 35;            // Max space allocated for file name
const int CLASS_SIZE = 5;
class StudentRecord
{

public:

    **void input(ifstream& input,int studentid);** // reads exam scores for this student 
    void computeGrade(); //calculates the numeric average and letter grade. 
    void output(); //outputs the student record.
    //outputs student record

private:
    int studentNumber;
    double exam1;
    double exam2;
    double exam3;
    double exam4;
    double average;
    char grade;
};

void open_input(ifstream& input, char name[]); // Get file name & Open file
void process_file(ifstream& input);            // Read each value & process 

int main()
{
    //StudentRecord student1, student2, student3, 
    //  student4, student5;

    char again;             // Does user want to go through loop again?
    char file_name[MAX_FILE_NAME + 1]; // Name of file to be processed
   ifstream input_numbers;            // For working with input file

   cout << "This program will calculate student grades.\n"
         << "It will give exam scores and averages with letter grade.\n";

   system("pause"); // Hold message on screen until key is pressed

   do 
   {  
      system("cls");                           // Clear screen
      open_input(input_numbers, file_name);    // Get file name & open file
      process_file(input_numbers);             // Process values in file
      input_numbers.close();                   // Close file

      cout << "\nDo you want to process another file (Y/N)? ";
      cin >> again;
      cin.ignore(256, '\n');  // Remove Enter key from keyboard buffer

   } while ( again == 'y' || again == 'Y'); 

   cout << "\nEnd of Program!" << endl;
   outputfile << "\n\nThanks for using Grade Pro!\f"; 
   outputfile.close();

   return 0; 
}  // End of main()

void process_file(ifstream& input) 
// Parameters: Variable for file reference
// Returns:    None
// Calls:      Invoice::set_merchandise_value(), Invoice::output()

{  
    double thisStudent = 0;              // Merchandise value from file

    StudentRecord student = StudentRecord();    // Record for student

    while (thisStudent++ < CLASS_SIZE)
    {
        **student.input(input, thisStudent);**
        student.computeGrade();
        student.output();
    } // End of process_file()
}
void open_input(ifstream& input, char name[]) //Open file, exit on error
// Parameters: Variables for input file reference nad input file name
// Returns:    None
// Calls:      None
{  int count = 0;             // Count number of tries
   do // Continue until we get a valid file name and can open file
   {  count++;
      if (count != 1)  // Issue error message if we are trying again.
      {  cout << "\n\aInvalid file name or file does not exist. Please try again." 
              << endl;
      }
      cout << "\nEnter the input file name (maximum of " << MAX_FILE_NAME
           << " characters please)\n:> ";
      cin.get(name, MAX_FILE_NAME + 1);// Gets at most MAX_FILE_NAME characters
      cin.ignore(256, '\n');           // Remove Enter key from keyboard buffer
      input.clear();                   // Clear all error flags, if any, from prev try
      input.open(name,ios_base::in); // Open only if file exists
   } while (input.fail() );            // If can't open file, try again
} // End of open_input()

void StudentRecord::computeGrade()
{

    double average; 
    average = (exam1+exam2+exam3+exam4)/4;

    //Letter grade: A => 90 > B => 80 > C => 70 > D => 60 > F
    if(average>=90)
        grade = 'A';
    else if(average<90 && average>=80)
        grade = 'B';
    else if(average<80 && average>=70)
        grade = 'C';
    else if(average<70 && average>=60)
        grade = 'D';
    else if(average<60)
        grade = 'F';
}
void StudentRecord::output()
{
    cout << "\n\nExam1: " << setw(8) << exam1 << endl;
   cout <<      "Exam2: " << setw(8) << exam2 << endl;
   cout <<      "Exam3: " << setw(8) << exam3 << endl;
   cout <<      "Exam4: " << setw(8) << exam4 << endl;
   cout <<      "Avg:   " << setw(8) << average<< endl;
   cout <<      "Grade: " << setw(8) << grade << endl;
}

Big problem, you haven't provided an implementation for void input(ifstream& input,int studentid);

Wow thanks vmanes... I really should have seen that one.

Still trying to figure out the second part of my problem; dividing the data input between exams1-4. If someone could point me in the right direction for that bit of code it would be awsome.

Ok I came up with this for the implementation for void StudentRecord::input(ifstream& input,int studentid) but how do I pass the values that go into value to the objects exam1, exam2, exam3, and exam4. The values get to this part but I am at a lost of how to initialize those values to exam's 1-4. The input file is simply a set of 20 scores, 4 scores to each student. I am fairly new to this and could use all the help I can get on this one. Thanks.

void StudentRecord::input(ifstream& input,int studentid)
{
    double value;              // Value from file
   double sum = 0;
   double count = 0;
   while (input >> value)
   {  
      sum += value;
      count++;
   }

}

I got it solved. But a funny quirk with the average. It would calculate but would not pass through to output but all the exam scores passed through no problem; however it did work to evaluate to a letter grade. I ended up just re-posting the equation in the output function.

Solved by assigning the studentNumber to the studentid and inserted the data to exam1, exam2, etc.

This article has been dead for over six months. Start a new discussion instead.