Please help with Public/Private methods

Hello,
Panicking here. My professor asked for an assignment in which we use:

"Eight private methods (1 method per calculated value) to calculate the values and store them in the private properties. Each of the 8 methods will use the object properties to calculate the values. In other words, those methods will not have parameters."

However, how on earth do you write the what you actually want the private function to do? Every time I try and define it, I get the error 'such_and_such_method is private'.


Does your professor mean something like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class MyClass
{
private:
variable1;
variable2;
...
variable8;

priv_meth1();
priv_meth2();
...
priv_meth8();
...
public:
MyClass();
...

?
Last edited on
Yes, that's exactly it. I just don't know how to tell the computer what the private method should do. For example, my private method, calc_area, should calculate the area from a base and height entered by the user in the main program. No idea where to define that, however.
Wait a minute. I think it is letting me define it, just like any other method:

void BEAM::calc_area(double b, double h)
{
A=b*h;
}

However, when I try to pass b and h variables from the main function, it does not let me. How would I call such a function?
Topic archived. No new replies allowed.