#include #include #include struct person { string fname, lname; // object's variables are MEMBERS. int ssn, bd; // object's functions are called METHODS // a method with no return type and the same name as // the struct is a CONSTRUCTOR. // If you define any constructor, then a constructor // will be called every time an object is created. It // can't be prevented. If none of the constructors are // suitable, the program will not compile. person(int s, string f, string l, int b) { ssn = s; fname = f; lname = l; bd = b; } person() // no parameters: this is the DEFAULT CONSTRUCTOR, it { } // can be used when no other constructor fits. void print() { cout << fname << " " << lname << ", SSN=" << ssn << ", born " << bd << "\n"; } }; person * read_data() { ifstream in("/home/www/class/een118/labs/database1.txt"); if (in.fail()) { cerr << "No file\n"; exit(1); } person * array = new person[1010]; // 1010 person objects were just created. The default // constructor was called 1010 times. int num = 0; while (num < 1010) { int a, b; string c, d; in >> a >> c >> d >> b; if (in.fail()) break; person temp(a, c, d, b); // the normal constructor is called here. array[num] = temp; num += 1; } in.close(); return array; } void main() { person * data = read_data(); int oldest = data[0].bd, oldestpos = 0; for (int i=1; i<1000; i+=1) if (data[i].bd < oldest) { oldest = data[i].bd; oldestpos = i; } cout << "oldest is "; data[oldestpos].print(); cout << "first is "; data[0].print(); }