I have problems with this small class program, have two classes...registration and course. I am writing a small function for registration adds the credits. I made an array called ptr of type course in the registration class. Now when i try to access credit a private member in the class course, when i compile it says i cannot access it, but i am using ptr which is a course type, i thought it should have access since its part of the course class. example this is how how i called it... ptr.credits . This is not working in the total_credits function in the registration class, need help to call credits into this class, how can i do this?????????? cannot create any more variables as is, just need to find how to get the values of credits from the course class into the registration class
#include <stdio.h>
#include <iostream.h>
class course
{
private:
char string[20];
int credit;
public:
course(void);
~course(void);
};
class registration
{
private:
course *ptr;
int num;
public:
registration(int iNum);
~registration();
total_credits();
};
registration::registration(int iNum)
{
num = iNum;
ptr = new course[num];
}
registration::~registration()
{
delete [] ptr;
cout << "reg deconstructor\n";
}
registration::total_credits()
{
int iTotal =0, i;
for(i=0; i<=num-1;++i)
iTotal= iTotal + ptr.credit;
cout<<"/nTotal credits are:" << iTotal;
cout<< "\n";
}
course::course(void)
{
cout<< "Enter the course name and number of credits\n";
cin>> string >> credit;
cout << "constructor" << endl;
}
course::~course(void)
{
cout << "\n" <<string <<" " << credit;
cout << "\ndeconstructor\n" << endl;
}
void main(void)
{
int iNum;
cout<< "how many:";
cin >> iNum;
registration test(iNum);
test.total_credits();
}