Skip to content

Instantly share code, notes, and snippets.

@OrsoEric
Created January 24, 2019 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OrsoEric/72375178855e019a0c2d42fe2a1f73e4 to your computer and use it in GitHub Desktop.
Save OrsoEric/72375178855e019a0c2d42fe2a1f73e4 to your computer and use it in GitHub Desktop.
Parent Class Implementation
/****************************************************************************
** Empty constructor
**
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
****************************************************************************/
Human::Human( void )
{
///--------------------------------------------------------------------------
/// STATIC VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// LOCAL VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// CHECK
///--------------------------------------------------------------------------
//Trace Enter
DENTER();
///--------------------------------------------------------------------------
/// INITIALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// BODY
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// FINALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// RETURN
///--------------------------------------------------------------------------
//Trace Return
DRETURN();
return;
} //end constructor: void
/****************************************************************************
** Initialized constructor
** Human | bool, int
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
****************************************************************************/
Human::Human( bool f_male, int age, string name )
{
///--------------------------------------------------------------------------
/// STATIC VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// LOCAL VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// CHECK
///--------------------------------------------------------------------------
//Trace Enter
DENTER_ARG("gender: %s, age: %d\n", GENDER_TO_STR(f_male), age );
///--------------------------------------------------------------------------
/// INITIALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// BODY
///--------------------------------------------------------------------------
//Set class variabiles
this -> set_gender( f_male );
this -> set_age( age );
this -> set_name( name );
///--------------------------------------------------------------------------
/// FINALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// RETURN
///--------------------------------------------------------------------------
//Trace Return
DRETURN();
return;
} //end constructor: void
/****************************************************************************
*****************************************************************************
** DESTRUCTORS
*****************************************************************************
****************************************************************************/
/****************************************************************************
** Empty Destructor
**
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
****************************************************************************/
Human::~Human( void )
{
///--------------------------------------------------------------------------
/// STATIC VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// LOCAL VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// CHECK
///--------------------------------------------------------------------------
//Trace Enter
DENTER();
///--------------------------------------------------------------------------
/// INITIALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// BODY
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// FINALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// RETURN
///--------------------------------------------------------------------------
//Trace Return
DRETURN();
return;
} //end empty constructor
/****************************************************************************
*****************************************************************************
** SETTERS
*****************************************************************************
****************************************************************************/
/****************************************************************************
** Public Setter
** set_gender | bool
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
****************************************************************************/
bool Human::set_gender( bool f_male )
{
///--------------------------------------------------------------------------
/// STATIC VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// LOCAL VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// CHECK
///--------------------------------------------------------------------------
//Trace Enter
DENTER_ARG("gender: %s\n", GENDER_TO_STR(f_male));
///--------------------------------------------------------------------------
/// INITIALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// BODY
///--------------------------------------------------------------------------
//Set the gender
this -> g_f_male = f_male;
///--------------------------------------------------------------------------
/// FINALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// RETURN
///--------------------------------------------------------------------------
//Trace Return
DRETURN();
return false; //OK
} //end function: set_gender | bool
/****************************************************************************
** Public Setter
** set_age | int
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
****************************************************************************/
bool Human::set_age( int age )
{
///--------------------------------------------------------------------------
/// STATIC VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// LOCAL VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// CHECK
///--------------------------------------------------------------------------
//Trace Enter
DENTER_ARG("age: %d\n", age);
if ((age < MIN_AGE) || (age > MAX_AGE))
{
return true; //Fail: bad age
}
///--------------------------------------------------------------------------
/// INITIALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// BODY
///--------------------------------------------------------------------------
this -> g_age = age;
///--------------------------------------------------------------------------
/// FINALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// RETURN
///--------------------------------------------------------------------------
//Trace Return
DRETURN();
return false; //OK
} //end function: set_age | int
/****************************************************************************
** Public Method
** set_name | std::string
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
** Set name of the human
****************************************************************************/
bool Human::set_name( std::string name )
{
///--------------------------------------------------------------------------
/// STATIC VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// LOCAL VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// CHECK
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// INITIALIZATIONS
///--------------------------------------------------------------------------
//Trace Enter
DENTER_ARG("name: %s\n", &name[0]);
//if: bad size
if (name.size() >= this -> g_name.size() )
{
DPRINT("ERR: bad size | source: %d dest: %d\n", name.size(), this -> g_name.size());
return true; //FAIL
}
///--------------------------------------------------------------------------
/// BODY
///--------------------------------------------------------------------------
//Copy name
std::copy( name.begin(), name.end(), this -> g_name.begin() );
//append terminator
this -> g_name[ name.size() ] = '\0';
///--------------------------------------------------------------------------
/// FINALIZATIONS
///--------------------------------------------------------------------------
//Trace Return
DRETURN();
return false; //OK
} //end method: set_name | std::string
/****************************************************************************
*****************************************************************************
** GETTERS
*****************************************************************************
****************************************************************************/
/****************************************************************************
** Public Getter
** get_gender | void
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
****************************************************************************/
bool Human::get_gender( void )
{
///--------------------------------------------------------------------------
/// STATIC VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// LOCAL VARIABILE
///--------------------------------------------------------------------------
bool f_ret;
///--------------------------------------------------------------------------
/// CHECK
///--------------------------------------------------------------------------
//Trace Enter
DENTER();
///--------------------------------------------------------------------------
/// INITIALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// BODY
///--------------------------------------------------------------------------
f_ret = this -> g_f_male;
///--------------------------------------------------------------------------
/// FINALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// RETURN
///--------------------------------------------------------------------------
//Trace Return
DRETURN_ARG( "%s\n" ,GENDER_TO_STR( f_ret ));
return f_ret;
} //end function:
/****************************************************************************
** Public Getter
** get_age | void
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
****************************************************************************/
int Human::get_age( void )
{
///--------------------------------------------------------------------------
/// STATIC VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// LOCAL VARIABILE
///--------------------------------------------------------------------------
int age;
///--------------------------------------------------------------------------
/// CHECK
///--------------------------------------------------------------------------
//Trace Enter
DENTER();
///--------------------------------------------------------------------------
/// INITIALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// BODY
///--------------------------------------------------------------------------
age = this -> g_age;
///--------------------------------------------------------------------------
/// FINALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// RETURN
///--------------------------------------------------------------------------
//Trace Return
DRETURN_ARG("age: %d\n", age);
return age;
} //end function: get_age | void
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment