Click to See Complete Forum and Search --> : accessor&mutator functions


t3hseen
March 16th, 2005, 01:20 PM
i need some help with these two functions can anyone please help?
Given the following class:
class Recording{
private:
int tracks;
float tot_time;
char year_issued;
char *Artist;
char *Title;

write accessor and mutator functions for: tracks: cannot be less that zero or greater than 16
year_issued: seen as standard (i.e. 2004) but stored internally as years since 1950 (2004 is 54)

if someone can please help with this i would really appreciate it

cilu
March 16th, 2005, 01:34 PM
Accessors are methods that grant you access for read/write the private/protected data members. So for track:

public:
int GetTracks() const
{
return tracks;
}

bool SetTracks(int _tracks)
{
if(_tracks<0 || _tracks>16)
return false;

tracks = _tracks;
return true;
}


Sorry, but I don't know what "mutators" are. :sick: I'm not familiar with this term.

Sahir
March 16th, 2005, 02:23 PM
Sorry, but I don't know what "mutators" are. :sick: I'm not familiar with this term.


In your example, bool SetTracks(int _tracks); is a mutator. This word is sometimes used in OOPspeak, but it has not made it into the dictionary. I looked in two of them and did not find this word.

t3hseen
March 16th, 2005, 02:40 PM
guys,

thanks for the help that sheds a great deal of light for me, for i am new to programming

t3