CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2005
    Posts
    3

    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

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Aug 2002
    Location
    Kerala
    Posts
    1,183

    Re: accessor&mutator functions

    Quote 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.

  4. #4
    Join Date
    Mar 2005
    Posts
    3

    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
  •  





Click Here to Expand Forum to Full Width

Featured