Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ help
#25
Could someone help me out with "private" in object programming? I just don't get the use of it. I understand declaring things in private is supposed to make it "private", but I just can't think of a good way to use it or how it's actually "private". This is one of the examples my teacher gave me. He doesn't speak english very well which is why I had to make this thread and ask for SP's help.

Code:
#include<iostream>
using namespace std;
// declaration section:
class Student
{
    private:
       int idNum;
    public:
       static double athleticFee;
       void setIdNum(int);
       void displayStudentData();
};
// implementation section:
double Student::athleticFee = 45.25;
void Student::displayStudentData()
{
  cout<<"Student #"<<idNum<<"'s athletic fee is $"
    <<athleticFee<<endl;
}
void Student::setIdNum(int num)
{
   idNum = num;
}
int main()
{
     Student aFreshman, aSophomore;
     aFreshman.setIdNum(1234);
     aSophomore.setIdNum(2345);
     aFreshman.displayStudentData();
     aSophomore.displayStudentData();
  cout<<"The standard student athletic fee is $"<<
   Student::athleticFee<<endl;
}

Now what I don't understand is how idNum (declared in the object/class) is private. When I run the program, it straight up tells me what the idnum is of aFreshman and aSophomore, so how is that private?
Reply


Messages In This Thread
C++ help - by DrRusty - 2010-09-21, 10:03 AM
C++ help - by iamflip - 2010-09-21, 10:22 AM
C++ help - by DrRusty - 2010-09-21, 10:41 AM
C++ help - by Eos - 2010-09-21, 11:53 AM
C++ help - by Fiel - 2010-09-21, 12:23 PM
C++ help - by Eos - 2010-09-21, 12:34 PM
C++ help - by DrRusty - 2010-09-21, 12:42 PM
C++ help - by Eos - 2010-09-21, 12:47 PM
C++ help - by DrRusty - 2010-09-21, 12:55 PM
C++ help - by Fiel - 2010-09-21, 12:59 PM
C++ help - by Fiel - 2010-09-21, 01:21 PM
C++ help - by Stereo - 2010-09-21, 01:40 PM
C++ help - by DrRusty - 2010-09-21, 04:23 PM
C++ help - by Fiel - 2010-09-21, 04:35 PM
C++ help - by DrRusty - 2010-09-21, 05:02 PM
C++ help - by Fiel - 2010-09-21, 05:10 PM
C++ help - by DrRusty - 2010-09-21, 05:31 PM
C++ help - by GummyBear - 2010-09-22, 06:21 AM
C++ help - by DrRusty - 2010-09-22, 08:24 AM
C++ help - by GummyBear - 2010-09-22, 09:39 AM
C++ help - by Stereo - 2010-09-22, 01:41 PM
C++ help - by GummyBear - 2010-09-22, 07:15 PM
C++ help - by Fiel - 2010-09-22, 08:50 PM
C++ help - by GummyBear - 2010-09-23, 10:27 AM
C++ help - by DrRusty - 2010-09-27, 09:22 AM
C++ help - by Eos - 2010-09-27, 09:28 AM
C++ help - by DrRusty - 2010-09-27, 09:34 AM
C++ help - by Eos - 2010-09-27, 09:44 AM
C++ help - by Fiel - 2010-09-27, 10:13 AM
C++ help - by Eos - 2010-09-27, 10:27 AM
C++ help - by DrRusty - 2010-09-27, 10:28 AM
C++ help - by Eos - 2010-09-27, 10:34 AM
C++ help - by DrRusty - 2010-09-27, 11:28 AM
C++ help - by ArbalistMaster - 2010-09-27, 01:24 PM
C++ help - by Fiel - 2010-09-27, 03:44 PM
C++ help - by Stereo - 2010-09-27, 04:57 PM
C++ help - by GummyBear - 2010-09-28, 08:57 AM
C++ help - by Russt - 2010-09-28, 07:31 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)