mardi 8 mars 2022

How to write a get and set method for array to access a private array

Not sure if there is already an explanation regarding creating a get and set method for array but I cant find it there for I am here asking you experts. I am trying to unfriend the istream and ostream as per my assignment. but I cant figure out how to access "private Result Results[MAXRESULTUNIT]". Have been on google for the past few days trying figure this out. Hopefully someone can help guide me along with this problem of mine.

// REGIST.H - Registration class definition
// author KRI
// modified smr

#ifndef REGIST_H
#define REGIST_H


#include <iostream>
#include "Result.h"

using namespace std;

const int MAXRESULTUNIT = 1000;

class Registration
{
public:
    Registration();
    Registration(long &R_studentID, int &R_Semester);

    void SetStudentID(const long &R_studentID);
    void GetStudentID(long &R_studentID) const;
    void SetSemester(const int &R_Semester);
    void GetSemester(int &R_Semester) const;
    void SetCount(int &R_Count);
    int GetCredits() const;
    int GetCount() const;
    int GetArray(); // please ignore this. was just trying something based on what i found on google (not working)
  
private:
    long studentId;             // student ID number
    int semester;          // semester year, number
    int count;             // number of courses
    Result Results[MAXRESULTUNIT]; // array of courses
};
istream & operator >>( istream & input,Registration & R );
ostream & operator <<( ostream & os,const Registration & R);
#endif

Did some editing, was trying to create a get and set method for the array so that I can call it since its private.

Aucun commentaire:

Enregistrer un commentaire