|
-
March 16th, 2005, 02:20 PM
#1
accessor&mutator functions
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
-
March 16th, 2005, 02:34 PM
#2
Re: accessor&mutator functions
Accessors are methods that grant you access for read/write the private/protected data members. So for track:
Code:
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. I'm not familiar with this term.
-
March 16th, 2005, 03:23 PM
#3
Re: accessor&mutator functions
 Originally Posted by cilu
Sorry, but I don't know what "mutators" are.  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.
-
March 16th, 2005, 03:40 PM
#4
Re: accessor&mutator functions
guys,
thanks for the help that sheds a great deal of light for me, for i am new to programming
t3
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|