/** * p1.cpp (7-dec-2010/sklar) * * this program motivates the use of simple classes in C++ by using multiple * variables and parallel arrays that are related conceptually, but are not * formally connected by the code structure. * */ #include using namespace std; // function prototypes void readData( string &, string &, string &, string &, string &, string &, int &, int &, int & ); void writeData( string, string, string, string, string, string, int, int, int); /** * main function * */ int main() { string last_name[3]; string first_name[3]; string cell_number[3]; string email[3]; string home_number[3]; string work_number[3]; int birth_day[3]; int birth_month[3]; int birth_year[3]; cout << "enter data for 3 people...\n"; for ( int i=0; i<3; i++ ) { readData( last_name[i], first_name[i], cell_number[i], email[i], home_number[i], work_number[i], birth_day[i], birth_month[i], birth_year[i] ); } cout << "here are all the people...\n"; for ( int i=0; i<3; i++ ) { writeData( last_name[i], first_name[i], cell_number[i], email[i], home_number[i], work_number[i], birth_day[i], birth_month[i], birth_year[i] ); } } // end of main() /** * readData() * * this function prompts the user for input and reads their answers. * values entered are returned to calling function using call-by-reference * arguments. * */ void readData( 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 ) { cout << "enter last name: "; cin >> last_name; cout << "enter first name: "; cin >> first_name; cout << "enter cell number: "; cin >> cell_number; cout << "enter email: "; cin >> email; cout << "enter home number: "; cin >> home_number; cout << "enter work number: "; cin >> work_number; cout << "enter birthday (DD MM YY): "; cin >> birth_day; cin >> birth_month; cin >> birth_year; cout << "thanks!" << endl; } // end of readData() /** * writeData() * * this function displays the values of its arguments on the screen, * formatted in a user-friendly way. * */ void writeData( 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 ) { cout << "name: " << first_name << " " << last_name << endl; cout << "phone: " << cell_number << " (C)\n"; cout << " " << home_number << " (H)\n"; cout << " " << work_number << " (W)\n"; cout << "email: " << email << endl; cout << "birthday: " << birth_day << "/" << birth_month << "/" << birth_year << endl; } // end of writeData()