Guys, I really really need help with the following code. It works when I #include "person.cpp", but without it it fusses at me with errors: 15|undefined reference to `Person::setlastName(char*)' and warns: |24|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
If some guru would take time and help me to understand and correct this - I really need help!
Code:#include <iostream> using namespace std; #include "person.h" #include "person.cpp" int main(int argc, char *argv[]) { Person p1; p1.setlastName("Smith"); p1.setfirstName("John"); p1.setmiddleInitial("M"); p1.setdateOfBirth("06.25.1989"); p1.setstreetAddress("205 Nicholas St."); p1.setcity("Dallas"); p1.setstate("TX"); p1.setzipCode("52080"); p1.sethomePhone("755-258-5595"); p1.setworkPhone("755-358-1125"); cout << p1.getlastName() << endl << p1.getfirstName() << endl << p1.getmiddleInitial() << endl << p1.getdateOfBirth() << endl << p1.getstreetAddress() << endl << p1.getcity() << endl << p1.getstate() << endl << p1.getzipCode() << endl << p1.gethomePhone() << endl << p1.getworkPhone() << endl; return 0; }Code:// Person.h #ifndef PERSON_H #define PERSON_H class Person{ char lastName [21]; char firstName [15]; char middleInitial[3]; char dateOfBirth[11]; char streetAddress [25]; char city [20]; char state [3]; char zipCode [11]; char homePhone [13]; char workPhone [13]; public: void setlastName (char *L); char* getlastName(); void setfirstName (char *F); char* getfirstName (); void setmiddleInitial (char *M); char* getmiddleInitial (); void setdateOfBirth (char *D); char* getdateOfBirth (); void setstreetAddress (char *A); char* getstreetAddress (); void setcity (char *C); char* getcity (); void setstate (char *S); char* getstate (); void setzipCode (char *Z); char* getzipCode (); void sethomePhone (char *H); char* gethomePhone (); void setworkPhone (char *W); char* getworkPhone (); }; #endifCode://person.cpp: #include <string.h> #include "person.h" void Person::setlastName(char *L) { strcpy (lastName, L); } char* Person::getlastName() { static char temp[21]; strcpy (temp, lastName); return temp; } void Person::setfirstName(char *F) { strcpy (firstName, F); } char* Person::getfirstName() { static char temp[15]; strcpy (temp, firstName); return temp; } void Person::setmiddleInitial(char *M) { strcpy (middleInitial, M); } char* Person::getmiddleInitial() { static char temp[3]; strcpy (temp, middleInitial); return temp; } void Person::setdateOfBirth(char *D) { strcpy (dateOfBirth, D); } char* Person::getdateOfBirth() { static char temp[11]; strcpy (temp, dateOfBirth); return temp; } void Person::setstreetAddress(char *A) { strcpy (streetAddress, A); } char* Person::getstreetAddress() { static char temp[25]; strcpy (temp, streetAddress); return temp; } void Person::setcity(char *C) { strcpy (city, C); } char* Person::getcity() { static char temp[20]; strcpy (temp, city); return temp; } void Person::setstate(char *S) { strcpy (state, S); } char* Person::getstate() { static char temp[3]; strcpy (temp, state); return temp; } void Person::setzipCode(char *Z) { strcpy (zipCode, Z); } char* Person::getzipCode() { static char temp[11]; strcpy (temp, zipCode); return temp; } void Person::sethomePhone(char *H) { strcpy (homePhone, H); } char* Person::gethomePhone() { static char temp[13]; strcpy (temp, homePhone); return temp; } void Person::setworkPhone(char *W) { strcpy (workPhone, W); } char* Person::getworkPhone() { static char temp[13]; strcpy (temp, workPhone); return temp; }




Reply With Quote
