I'm stuck with this one question we were asked to do in class...The program is to read input from a file that contains students' ids and marks and we have to determine their grades and store these variables as arrays then print it out. Then we were to create a class called student and then test it if it's working by creating an object in main() and testing each methods of the class. Then we must create an array of classes called Student student_Info[MAXSIZE] and use that instead of the parrallel arrays. I've done most parts of it till this part where we have to delete the parrallel arrays (i.e id[MAXSIZE], marks[MAXSIZE] and grade[MAXSIZE] and create a new array for student class to be used instead. I am not sure what needs to be done next... Can anyone please help me?

Here is what I've done so far but still have errors. Note that I've included comments on the parts where I'm stuck with:

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string>

const int MAX_SIZE = 10;

//Class Definition
class Student{
          string id;
          int marks;
          char grade;
          void setID(string);
          string getID();
          void setMarks(int);
          int getMarks();
          void setGrade(char);
          char getGrade();
};     // closing class

//class function body

        cout<< "Student Constructor called" << endl;

         cout<< "Student Destructor called" << endl;

void Student::setID(string id)


string Student::getID()
return this->id;

void Student::setMarks(int marks)

int Student::getMarks()
return this->marks;

void Student::setGrade(char grade)

char Student::getGrade()
return this->grade;

//Function Prototypes

char determine_grade(int smarks);
void discard_line(ifstream &in);
void print_students_records(student s[], int size)   //This is the modified version of the below commented function which was used at first
//void print_students_records(string sid[], int smarks[], char sgrades[], int size);

int main()
    //Student test;      //This is used just to test whether my class was working or not
    //test.setGrade('A');   //This is used just to test whether the methods in my class were working or not

    Student student_Info[MAX_SIZE];   //New array of Student class created

    //string id[MAX_SIZE];      //These parallel arrays are deleted
    //int marks[MAX_SIZE];
    //char grade[MAX_SIZE];

    int total_records;
    int choice;
    char response;

     string temp_id;
     int temp_marks;

    ifstream input;

    cout<<"This program determines the grades of students."<<endl;


		cerr<<"File could not be opened"<<endl;


    total_records = 0;

        id[total_records] = temp_id;         //Do I need to do something here?
        marks[total_records] = temp_marks;

    for (int i = 0; i < total_records; i++){
        grade[i] = determine_grade(marks[i]);   //Do I need to do something here?


    //cout<< test.getGrade();

    //print_students_records (id, marks, grade, total_records );
     print_students_records (Student student_Info[], total_records);

    return 0;

//void print_students_records(string sid[], int smarks[], char sgrades[],int size)   //Modified below

//Is this how this should be done? I'm still getting errors
void print_students_records(Student s[], int size){
    cout<<"\n\nstudents' records"<<endl<<endl;
    for (int i = 0; i < size; i++){
        //cout<<"id: "<<sid[i]<<", marks: "<<smarks[i]<<", grade: "<<sgrades[i]<<endl;
        cout<<"id: "<<Student s[i]<<", marks: "<<Student s[i]<<", grade: "<<Student s[i]<<endl;

char determine_grade(int smarks){
     char sgrade;

     if (smarks >= 80)
        sgrade = 'A';
     else if(smarks >= 65)
        sgrade = 'B';
     else if(smarks >= 50)
        sgrade = 'C';
        sgrade = 'D';

     return sgrade;

void discard_line(ifstream &in)
    char c;

    while (c!='\n');
Re: Help needed with parrallel arrays/array of classes 80 80

It's just a simple replacement of each thing[position] with structArray[position].thing But since you're using a class, you need to invoke member functions, so thing[position] = value; would be classArray[position].setValue(value);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.