Having difficulty understanding what is being asked

I am being asked to create a class called Person with 3 private members.
Then I'm being asked to create Accessors to Mutators for each field.
I don't understand what they actually mean by Accessors to Mutators.
I know Accessors are get value functions and Mutators are setter functions.
Any hints as to what it might be asking me to do?

I have to create a .cpp program that will access the person class and implement in in 3 ways as a .h, .cpp and whole code .cpp.

any help is highly appreciated it!
So... you create a class named Person with three private members, and you write accessor and mutator member functions for each.

Your class declaration goes in the .h file.
Your class definition goes in one .cpp file, and your main() in another.

So far this is my work in progress:

#include <iostream>
#include <string>
using namespace std;

class Person
string FirstName;
string LastName;
double age;

string getFirstName();
string getLastName();
double getAge();
void setFirstName(string);
void setLastName(string);
void setAge(double);


void Person::setFirstName(string first)
FirstName = first;


void Person::setLastName(string last)
LastName = last;

void Person::setAge(double year)
Age = year;


string Person::getFirstName()
return first;


string Person::getLastName()
return last;


double Person::getAge()
return year;

The problem I am having is that I don't think I'm allow to have a 'string function' and if this is true, how am I supposed to called first name and last name since it can only be a string?

any hints as to what I can possibly do here?
Can you use c-style strings if you aren't allowed to you the string class?
Can you show me an example of how I can use a c style string within a class?
Something like char name[81]; You can't exactly return arrays though you'd have to return a pointer to the array. Then for your setter either use strcpy or write your own version ( pretty easy ).

Strcpy looks like this:

char *strcpy( char *destination , const char *source )
    int i;
    for( i = 0; destination[i] && source[i]; ++i )
        destination[i] = source[i];
    destination[i] = '\0';
    return( destination );

//or this version
char *strcpy( char *destination , const char *source )
    while( *destination++ = *source++ );
    return( destination );

*edit was missing the slash in my code tags.

Last edited on
Topic archived. No new replies allowed.