#include #include #include #include class Student { private: char first_name[80]; char middle_initial; char last_name[80]; int year_in_school; int age; int resident; // used as a boolean long student_id; char major[80]; float gpa; public: void query_user(void); void print_info(void); }; void error(char estring[]); void Student::query_user(void) { // Get student's name cout << "First name: "; cin >> first_name; cout << "Middle initial: "; cin >> middle_initial; cout << "Last name: "; cin >> last_name; cout << "age: "; cin >> age; if((age <= 0) || (age > 99)) { error("Age must be between 1 and 99"); } cout << "Year in school (0 = freshman, 1 = sophomore, etc.): "; cin >> year_in_school; if(year_in_school < 0) { error("Year in school must be positive"); } cout << "Resident(enter 1) or Non-resident (enter 0): "; cin >> resident; if( (resident != 0) && (resident != 1)) { error("Resident must be 0 or 1"); } cout << "Student Id (without -'s): "; cin >> student_id; cout << "Major (abbreviation, e.g. CSCI): "; cin >> major; cout << "GPA: "; cin >> gpa; if((gpa < 0.0) || (gpa > 4.0)) { error("GPA must be between 0.0 and 4.0"); } } void Student::print_info(void) { clrscr(); cout << "Name: " << first_name << " " << middle_initial << " " << last_name << "\n"; cout << "Age: " << age << "\n"; cout << "Year: " << year_in_school << "\n"; cout << "Resident/Non-resident: " << resident << "\n"; cout << "Student Id: " << student_id << "\n"; cout << "Major: " << major << "\n"; cout << "GPA: " << gpa << "\n"; cout << "\n\nEnter any key to exit\n"; getch(); } void main(void) { Student stu; stu.query_user(); stu.print_info(); } void error(char estring[]) { cout << "\n" << estring << "\n"; sleep(5); exit(-1); }