/* Person.cpp */ #include #include #include #include #include Person::Person(void) { emptyvalues(); } Person::Person(char* ln, int a) { emptyvalues(); strcpy(lastname, ln); age = a; } Person::Person(char* ln, char* fn, int a, float f) { emptyvalues(); strcpy(lastname, ln); strcpy(firstname, fn); age = a; worth = f; } void Person::emptyvalues(void) { lastname[0] = '\0'; firstname[0] = '\0'; age = 0; worth = 0; } char* Person::display(void) { static char temp[256]; sprintf(temp, "Last Name '%s',\nFirst Name '%s',\nAge '%d',\nNet Worth $ %1.2f.\n",lastname, firstname, age, worth); return temp; } int Person::update(char* data) { char temp[1024] = "\0"; char* ptr = NULL; int err = 0; strcpy(temp, data); ptr = strtok(temp, "\n"); if (ptr == NULL) return -1; err = isalpha(*ptr); /* err check ptr */ if (err == 0) return 1; strcpy(lastname, ptr); ptr = strtok(NULL, "\n"); if (ptr == NULL) return -1; err = isalpha(*ptr); /* err check ptr */ if (err == 0) return 1; strcpy(firstname, ptr); ptr = strtok(NULL, "\n"); if (ptr == NULL) return -1; err = isdigit(*ptr); /* err check ptr */ if (err == 0) return 1; age = atoi (ptr); ptr = strtok(NULL, "\n"); if (ptr == NULL) return -1; /* err check ptr */ /* use valsdec */ worth = (float) atof(ptr); return 0; }