#include #include #include struct person { string fname, lname; // object's variables are MEMBERS. int ssn, bd; // object's functions are called METHODS void print() { cout << fname << " " << lname << ", SSN=" << ssn << ", born " << bd << "\n"; } person(int s, string f, string l, int b) { ssn = s; fname = f; lname = l; bd = b; } }; template struct database { protected: T * data; int size, nextfreeslot; public: database() { size = 100; nextfreeslot = 0; data = new T [size]; } ~database() // destrcutor. always called automatically // when something ceases to exist. { delete [] data; data = NULL; } protected: void makeitgrow() { int newsize = size+100; T * newa = new T [newsize]; for (int i=0; inextfreeslot) { cout << "Error in put\n"; return; } if (pos==nextfreeslot) nextfreeslot += 1; if (pos>=size) makeitgrow(); data[pos] = ptr; } T get(int pos) // also checks { if (pos<0 || pos>=nextfreeslot) { cout << "Error in get\n"; return NULL; } return data[pos]; } }; void main() { database DB; database A; database numbers; DB.insert(new person(12, "a", "b", 34)); DB.insert(new person(13, "c", "b", 34)); DB.insert(new person(14, "d", "e", 34)); A.insert("asdasd"); A.insert("bdfgd"); A.insert("crtyhtfh"); A.insert("dhjkkk"); A.insert("ehkmhm"); A.insert("kyukufyh"); numbers.insert(111); numbers.insert(2222); numbers.insert(33333); numbers.insert(444444); for (int i=0; iprint(); for (int i=0; i