/** * p2.cpp (7-dec-2010/sklar) * * this program demonstrates the use of simple classes in C++. the example is * similar to p1.cpp, but instead of using separate variables, we group the * related variables together into a single class. * */ #include #include using namespace std; // class definition 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; }; // end of person class definition // function prototypes void readData( person & ); void writeData( person ); int main() { person natalie; readData( natalie ); writeData( natalie ); } // end of main() /** * readData() * * this function prompts the user for input and reads their answers. * values entered are returned to calling function using a call-by-reference * "person" object argument. * */ void readData( person &chris ) { cout << "enter last name: "; cin >> chris.last_name; cout << "enter first name: "; cin >> chris.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() /** * writeData() * * this function displays the values of its arguments on the screen, * formatted in a user-friendly way. * */ 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()