#include #include #include using namespace std; class person // STATIC !!! { public: string * items; static const int lname = 0, fname = 1, address = 2, phone = 3; person(string f, string l, string a, string p); ~person(); string get(int i); virtual void relocate(string newa, string newp); virtual void print(); }; person::person(string f, string l, string a, string p) { items = new string[4]; items[fname] = f; items[lname] = l; items[address] = a; items[phone] = p; } person::~person() { delete [] items; } string person::get(int i) { if (i>=0 && i<4) return items[i]; return ""; } void person::relocate(string newa, string newp) { items[address] = newa; items[phone] = newp; } void person::print() { cout << items[fname] << " " << items[lname] << ", of " << items[address] << ", phone " << items[phone]; } void look_at(person p) { cout << p.items[person::fname] << " at " << "area code " << p.items[person::phone].substr(0, 3) << "\n"; } void main() { cout << "size of person is " << sizeof(person) << " bytes\n"; vector A; A.push_back(new person("Lavinia", "Leopard", "55 Frog St.", "4046662233")); A.push_back(new person("Jim", "James", "987 Horse Rd.", "7364536475")); A.push_back(new person("Joe", "Jones", "123 Cat St.", "3051112222")); A.push_back(new person("Jemimah", "Jones", "123 Cat St.", "3051112222")); A.push_back(new person("Jimmy", "Jones", "123 Cat St.", "3051234321")); // put first one here // later change 3 to 2 A.push_back(new person("Jilly", "Jones", "123 Cat St.", "3053242315")); A.push_back(new person("Anathema", "Hamsoup", "234 Dog Av.", "3057651243")); look_at(*A[3]); look_at(*A[5]); look_at(*A[3]); for (int i = 0; i < A.size(); i += 1) { cout << i << ": "; A[i]->print(); cout << "\n"; } }