This is a very simple C++ question but i can not get this.
I was doing a work and question came that create a simple calculator class which performs different operations. I have done this easily through methods but it says more that
“Every operation performed by the calculator object must be stored in
the object’s memory, which can be get or set by the user further.”
As a hint the book have given two methods
voidSetMem(double d);
double GetMem();
I can not understand what does this line means.
Undertanding Getter / Setter Methods
Basically a ‘Getter’ is a function that returns the data stored in some variable, in you’re text book hint
And your ‘Setter’ would be a function used to set some variable
Notice two things:
1.) The getter function returns a data type double (because you are asking the program to provide you with data already set/stored
2.) The setter function returns NO data type (because you are telling/setting some variable)
Here is a basic example to GET the area from a square:
Now in your program you would obtain this data like so:
Here is a basic example to SET the area from a square:
And in your program you would set this data like so:
Hope This answers your question. Good Luck