Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie with C++ Classes

Status
Not open for further replies.

gonzilla

Programmer
Apr 10, 2001
125
US
Hello,

I just need a little better understanding of why/how something works. Here is a class I wrote to work with student records(yes this is for a simple college assignement, so I don't want code, just suggestions)

(this is in a header file)
class Student
{
public:
Student();
int GetRec(void);
double AvgGPA(int TotStuds, Student * Studs);
void PrintRec(double Avg, int TotStuds, Student * Studs);
private:
unsigned int StudId;
char StudName[MAXLEN];
double StudHours;
double StudGPA;
};

(this is in a source file)
int main(void)
{
Student Studs[MAXREC];
int TotStuds=0;
double Avg=0.0;

//TotStuds=Studs->GetRec(Studs);
for (int i = 0; i < MAXREC; i++)
TotStuds+=Studs.GetRec();
Avg=Studs->AvgGPA(TotStuds, Studs);
Studs->PrintRec(Avg, TotStuds, Studs);

return 0;
}

In main, I have commented out what I initially used to get eac record, and put another version below it. They both work. First, which way is more standard and are there other ways? Second, the reason this is tricky for me is because it is an array of classes. I would rather not pass the array (Studs) using pointers, to each fucntion like this but I want to be able to declare:
Student Studs[MAXREC]
in main - not globally so it is visible to the class - which doesn't make sense to me in the first place why the class member functions can't access them without passing them.

Any help would be great.

Thanks.

-Tyler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top