// ------------------------------------------------------------------- // // C++ program illustrates the use of nesting classes. // This program calculates the wages for the employee named. // Copyright (c) Chris H. Pappas and William H. Murray, 1990 // // Adapted from Borland C++ Handbook, 3rd ed., McGraw Hill, 1992. // #include < iostream.h > char newline; // ------------------------------------------------------------------- // // Layout the primary class structure // class emp_class { char first[20]; char middle[20]; char last[20]; double hours; double reg_sal; double ot_sal; public: void info_in(void); void info_out(void); }; // ------------------------------------------------------------------- // Define the member function info_in() void emp_class::info_in(void) { cout << "Enter first name: "; cin >> first; cin.get(newline); // flush carriage return cout << "Enter middle name or initial: "; cin >> middle; cin.get(newline); cout << "Enter last name: "; cin >> last; cin.get(newline); cout << "Enter hours worked: "; cin >> hours; cout << "Enter hourly wage: "; cin >> reg_sal; cout << "Enter overtime wage: "; cin >> ot_sal; cout << "\n\n"; } // ------------------------------------------------------------------- // // Define the member function info_out() void emp_class::info_out(void) { cout.setf(ios::fixed); cout.precision(2); cout << first << " " << middle << " " << last << "\n"; if (hours <= 40) cout << "Regular Pay: $" << hours * reg_sal << endl; else { cout << "Regular Pay: $" << 40 * reg_sal << endl; cout << "Overtime Pay: $" << (hours-40) * ot_sal << endl; } } // ------------------------------------------------------------------- // // Main function for the program int main() { emp_class widget; //associate the variable named widget with class widget.info_in(); //invoke a member function widget.info_out(); //invoke a member function return(0); }