// ------------------------------------------------------------------- // // 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. // // Modified by Brian Reithel 9/2/1999 #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 employee[50]; //associate the variable named widget with class // // here is the format for the for statement // // for(initstatement;testcondition;incr_activity) statement; // // remember that the "statement" above could be a compound statement // (in other words, several statements between braces) // int empnum; for(empnum=0;empnum<50;empnum=empnum+1 ) { employee[empnum].info_in(); employee[empnum].info_out(); } for(empnum=0;empnum<50;empnum++) employee[empnum].info_out(); return(0); }