// Demonstration C++ program from class 25th Feb 1999 // slightly corrected, but only to fix typos. #include int num_people=0; class Person { public: int memnum; char *title; // Mr, Ms, Mrs, Miss, Dr, etc char *lname; // Bloggs, Smith, Jones, etc char *fname; // Jilly, Billy, Frogalina, etc char *straddr; // 123 SW Ant St #222, etc char *city; // Antville, Knoxville, Jacksonville, etc char *state; // NE, WV, ME, etc char *zip; // 13131, 64174, etc char *phone; // 3051112222, 4078886655, etc Person(char *ti, char *ln, char *fn, char *sa, char *ci, char *st, char *zi, char *ph); Person(char *ti, char *ln, char *fn); Person(void); Person(char *alldata); void set_name(char *ti, char *ln, char *fn); void set_address(char *sa, char *ci, char *st, char *zi); void print(void); void print(char *intro); void save_in(FILE *f); }; Person::Person(char *ti, char *fn, char *ln, char *sa, char *ci, char *st, char *zi, char *ph) { num_people+=1; memnum=num_people; title=ti; lname=ln; fname=fn; // should use new char[] straddr=sa; city=ci; state=st; zip=zi; // and strcpy for assignments phone=ph; } Person::Person(char *ti, char *fn, char *ln) { num_people+=1; memnum=num_people; title=ti; lname=ln; fname=fn; // use new char[] and strcpy straddr=""; city=""; state=""; zip=""; phone=""; } Person::Person(void) { num_people+=1; memnum=num_people; title=""; lname="NoName"; fname="X"; // use new char[] and strcpy straddr=""; city=""; state=""; zip=""; phone=""; } int split(char *s, char *r[]) { return 0; } // Your function goes here Person::Person(char *alldata) { char *parts[20]; int n; n=split(alldata, parts); if (n!=9) { printf("error in Person data \"%s\"\n", alldata); return; } sscanf(parts[0],"%d",&memnum); title=parts[1]; lname=parts[2]; fname=parts[3]; straddr=parts[4]; city=parts[5]; state=parts[6]; zip=parts[7]; phone=parts[8]; } void Person::set_name(char *ti, char *ln, char *fn) { title=ti; // use new char[] and strcpy lname=ln; fname=fn; } void Person::set_address(char *sa, char *ci, char *st, char *zi) { straddr=sa; // use new char[] and strcpy city=ci; state=st; zip=zi; } void Person::print(void) { printf("#%d: %s %s %s, %s, %s %s %s (%s)\n", memnum, title, fname, lname, straddr, city, state, zip, phone); } void Person::print(char *intro) { printf("%s: #%d %s %s %s, %s, %s %s %s (%s)\n", intro, memnum, title, fname, lname, straddr, city, state, zip, phone); } void Person::save_in(FILE *f) { fprintf(f,"%d:%s:%s:%s:%s:%s:%s:%s:%s\n", memnum, title, lname, fname, straddr, city, state, zip, phone); } void main(void) { Person p1("Mrs","Frogalina","Jones","12 Ant St","Abacus","AK","77665","4532136"); Person p2("Mr","Jonas","Jones","12 Ant St","Abacus","AK","77665","4532136"); Person p3("Ms","Jane","Jones","12 Ant St","Abacus","AK","77665","5873924"); Person p4("Mr","Arthur","Aardvark"); Person p5("Miss","Elfie","Gnomeson","41 Bat Av","Abacus","AK","77624","7389294"); printf("\nPrinting p1 to p5\n"); p1.print(); p2.print(); p3.print(); p4.print(); p5.print(); p4.set_address("32 Ant St","Abacus","AK","77665"); Person all_people[6]; all_people[0]=p1; all_people[1]=p2; all_people[2]=p3; all_people[3]=p4; all_people[4]=p5; printf("Printing the array\n"); for (int i=0; i<=5; i+=1) { printf("a[%d] = ", i); all_people[i].print(); } }