My prof has asked me to "Create a person class to represent a person. 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.
"
I have created a class, however, my class prints the wrong name. What "exactly" am I doing wrong?
CODE
#include <iostream>
using namespace std;
char a,b;
class person{
protected:
char first[20];
char last[20];
public:
void get_person( char *f , char *l );
void print_person();
};
void person::get_person( char *f , char *l )
{
*first = *f;
*last = *l;
}
void person::print_person( )
{
cout <<endl<<"first name: "<<*first;
cout <<endl<<"last name: "<<*last;
}
int main ()
{
char a[20],b[20];
person one;
cout <<endl<<"first name = ";
cin >> a;
cout <<endl<<"last name = ";
cin >> b;
one.get_person(a,b);
one.print_person();
system ("pause");
return 0;
}