May 2, 2016 at 2:19am UTC
Please help me with the following code. I need to return both first and last name respectively using the string class. The code below only return the last name. Need to return both first and last name. The output only returns "Johnson".
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class statusName
{
public:
statusName ();
statusName(string &first, string &last);
~statusName ();
void setName(string &fn, string &ln);
string getName();
void print();
private:
string firstname;
string lastname;
};
statusName ::statusName (string &m, string &n)
{
//setName(m, n);
firstname = m;
lastname = n;
}
statusName ::~statusName ()
{
}
void statusName::setName(string &o, string &p)
{
firstname = o;
lastname = p;
}
string statusName::getName()
{
return(firstname, lastname);
}
void statusName::print()
{
cout <<"What is your name " << getName();
cout << endl;
}
int main()
{
string x = "Mike";
string y = "Johnson";
statusName myname(x, y);
myname.print();
return 0;
}
May 2, 2016 at 2:46am UTC
And PLEASE learn to use code tags, it makes reading your source much easier.
http://www.cplusplus.com/articles/jEywvCM9/
May 2, 2016 at 3:01am UTC
Thank you so much FurryGuy. I really appreciate your help.