/** * p3.cpp * * this program demonstrates arrays of simple classes in C++, * instead of using parallel arrays of separate variables, * we use a single array of objects. * */ #include using namespace std; class person { public: string last_name; string first_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.last_name; cout << "enter first name: "; cin >> p.first_name; 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.first_name << " " << p.last_name << 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] ); } } // end of main()