Student Grade Structure

Hi, all. I'm given an assignment to create a student grade structure, and calculate the numeric grades and letter grades.

The part I'm having trouble with is that, we are also asked to used a function to catch duplicate student ID. i.e. if one ID has been entered already, we'd tell the user to try another. Then somehow we go back to the loop and record a new student data.(I don't know how to do this part).

Here is what I have done so far:

#include <iostream>
using namespace std;

struct StudentRecord
{
int studentNumber; // as ID
double quiz; // from input
double midterm; // from input
double final; // from input
double average; // calculated and output
char grade; // calculated and output
};

void input2(int index, StudentRecord students[]);

//calculates the numeric average and letter grade.
void computeGrade(StudentRecord& student);

//outputs the student record.
void output(const StudentRecord& student);

int main()
{
const int CLASS_SIZE = 2;
StudentRecord studentAry[CLASS_SIZE];
int index;
cout << "Input " << CLASS_SIZE << " students' Data please...\n\n";


for(index = 0; index < CLASS_SIZE; index++)
{
input2(index, studentAry);
}


for(index=0; index < CLASS_SIZE; index++)
computeGrade(studentAry[index]);

for(index=0; index < CLASS_SIZE; index++)
output(studentAry[index]);

system ("pause");
return 0;
}

void input2(int index, StudentRecord students[])

{
cout << "Enter the student number: ";
cin >> students[index].studentNumber;

if(students[index].studentNumber == students[index-1].studentNumber)
{
cout << "This student's data has been entered already, please try another..." << endl;
input2(index, &students[index++]);
}

cout << "Enter three grades of quiz, midterm, and final (Max 100 each): ";
cin >> students[index].quiz >> students[index].midterm >> students[index].final;
}


void computeGrade(StudentRecord& student)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

student.average = (student.quiz + student. midterm + student.final)/3;

if (student.average < 60)
student.grade = 'F';
if (student.average < 70 && student.average >= 60)
student.grade = 'D';
if (student.average < 80 && student.average >= 70)
student.grade = 'C';
if (student.average < 90 && student.average >= 80)
student.grade = 'B';
if (student.average >= 90)
student.grade = 'A';
}

void output(const StudentRecord& student)
{
cout << "The record for student number: " << student.studentNumber << endl;
cout << "Three grades for quiz, midterm, and final are: ";
cout << student.quiz << " ";
cout << student.midterm << " ";
cout << student.final << endl;

cout << "The numeric average is: " << student.average << endl;
cout << "The letter grade assigned is: " << student.grade << endl;

}

Any suggestions or help will be greatly appreciated.
Topic archived. No new replies allowed.