I'm trying to get back into the groove of writing C++. I have written a class called person. It contains two accessor methods for each of my attributes, a constructor and destructor, and method that shows my info. I want to make a method that enables the person to "grow older"(each time the method is called, the person should age by one year basically)...just something simple.. I can't find the right way to create a growOlder() Method.... that when called makes my person age one year. Any help would be cool..and yeah I know my code is sloppy I'm out of practice!...yikes!!!
Code:
#include<iostream>
#include<string>
using namespace std;
class person {
private:
string fname;
string lname;
int age;
char sex;
public:
void setfName(string _fname);
void setlName(string _lname);
void setAge(int _age);
void setSex(char _sex);
string getfName();
string getlName();
int getAge();
char getSex();
person(string, string, int, char);
~person();
void showInfo();
};
person::person(string _fname, string _lname, int _age, char _sex)
{
fname = _fname;
lname= _lname;
age = _age;
sex = _sex;
}
person::~person(){
}
void person::setfName(string _fname)
{
fname = _fname;
}
string person::getfName()
{
return fname;
}
void person::setlName(string _lname)
{
lname = _lname;
}
string person::getlName()
{
return lname;
}
void person::setAge(int _age)
{
age = _age;
}
int person::getAge()
{
return age;
}
void person::setSex(char _sex)
{
sex = _sex;
}
char person::getSex()
{
return sex;
}
void person::showInfo()
{
cout<<"First Name: "<<fname<<endl<<"Last Name: "<<lname<<endl<<"Age: "<<age<<endl<<"Sex : "<<sex<<endl;
}
int main(){
person John("John","Cavender",25,'M');
John.showInfo();
return 0;
}