/****************************************************************************************** ex6.cpp extended OOP object in a "traditional" array, input from a user-supplied file ******************************************************************************************/ #include <iostream> #include <string> #include <fstream> using namespace std; //class definition class name { public: string first; string last; int age; }; // prototypes void readFile(string filename, name array[], int size); void main() { int i; const int maxsize=6; name family[maxsize]; string filename; cout << "Enter the file to read: "; cin >> filename; readFile(filename, family, maxsize); for (i=0; i < maxsize; i++) { cout << family[i].last << ", " << family[i].first << endl << " Aged " << family[i].age << " years." << endl; } return; } //------- fill each person in the list from a file ------ void readFile(string filename, name array[], int size) { ifstream fin(filename.c_str); for (i=0; i < size; i++) { fin >> family[i].first >> family[i].last >> family[i].age; } return; }