/** * p4.cpp * 07-may-2007/sklar * * this program demonstrates arrays of simple classes in C++. * */ #include using namespace std; class name { public: string last; string first; }; class person { public: name my_name; string cell_number; string email; string home_number; string work_number; int birth_day; int birth_month; int birth_year; }; void readData( person &p ) { cout << "enter last name: "; cin >> p.my_name.last; cout << "enter first name: "; cin >> p.my_name.first; cout << "enter cell number: "; cin >> p.cell_number; cout << "enter email: "; cin >> p.email; cout << "enter home number: "; cin >> p.home_number; cout << "enter work number: "; cin >> p.work_number; cout << "enter birthday (DD MM YY): "; cin >> p.birth_day; cin >> p.birth_month; cin >> p.birth_year; cout << "thanks!" << endl; } // end of readData() void writeData( person p ) { cout << "name: " << p.my_name.first << " " << p.my_name.last << endl; cout << "phone: " << p.cell_number << " (C)\n"; cout << " " << p.home_number << " (H)\n"; cout << " " << p.work_number << " (W)\n"; cout << "email: " << p.email << endl; cout << "birthday: " << p.birth_day << "/" << p.birth_month << "/" << p.birth_year << endl; } // end of writeData() int main() { person p[3]; int i; cout << "enter data for 3 people...\n"; for ( i=0; i<3; i++ ) { readData( p[i] ); } cout << "here are all the people...\n"; for ( i=0; i<3; i++ ) { writeData( p[i] ); } cout << "here are just the people's names...\n"; for ( i=0; i<3; i++ ) { cout << p[i].my_name.first << " " << p[i].my_name.last << endl; } } // end of main()