Create a person class to represent a person. (You may call the class personType.) To simplify things, have the class have 2 variable members for the person's first and last name. Include 2 constructors. One should be a default constructor and the other should be one with parameters. Include respective functions for:
setting the name,
getting the name, and
printing the name on the screen.
Have your main program call these functions to demonstrate how they work.
Explain how you can replace both constructors with one constructor by using a single constructor with default parameters.
Code:
#ifndef personType_H
#define personType_H
#include <string>
using namespace std;
class personType
{
public:
personType( const string & , const string & );
void setFirstname (const string & );
string getFirstname() const;
void setLastname (const string & );
string getLastname() const;
private:
string firstName;
string lastName;
};
#endif
#include <iostream>
#include "personType.h"
using namespace std;
//constructor
personType::personType ( const string &first, const string &last )
{
firstName = first;
lastName = last;
}
// set first name
void personType::setFirstName ( const string &first )
{
firstName=first;
}
string personType::getFirstName() const
{
return firstName;
}
void personType::setLastName ( const string &last)
{
lastName=last;
}
void personType::print() const
{
cout<<"Who's your Daddy?:" << firstName << '' << lastName
}