// 5/6/14 class example // Payroll Program // This is the first version of the employee payroll program with a class. This version // contains only 1 class. #include #include using namespace std; // Class Declaration -- like a blueprint NO MEMORY is allocated class Employee { public: string name; string address; double hours; double rate; int idnum; }; int main() { // instantiate an object of type Employee Employee emp1, emp2; double pay; // process a single employee -- emp1 cout << "Enter an id number of an employee: "; cin >> emp1.idnum; cout << "Enter hours and rate: "; cin >> emp1.hours >> emp1.rate; cout << "enter name: "; cin.ignore(); getline(cin, emp1.name); pay = emp1.hours * emp1.rate; // Display all the info for object emp and the pay // Later we will put this in a function to print an Employee cout << "Name: " << emp1.name << "\nHours: " << emp1.hours << "\nRate: " << emp1.rate << "\nidnum: " << emp1.idnum << endl; cout << "Pay is: " << pay << endl; // NOT allowed: cout << emp1; // process a single employee cout << "Enter an id number of an employee: "; cin >> emp2.idnum; cout << "Enter hours and rate: "; cin >> emp2.hours >> emp2.rate; cout << "enter name: "; cin.ignore(); getline(cin, emp2.name); pay = emp2.hours * emp2.rate; // Display all the info for object emp and the pay cout << "Name: " << emp2.name << "\nHours: " << emp2.hours << "\nRate: " << emp2.rate << "\nidnum: " << emp2.idnum << endl; cout << "Pay is: " << pay << endl; // NOW, set the pay rate for emp1 to be that of emp2 emp1.rate = emp2.rate; Employee newemp; // copy everything from emp1 to newemp // ASSIGNMENT OF OBJECTS IS LEGAL newemp=emp1; // Display all the info cout << "now newemp is identical to emp1...\n"; cout << "Name: " << newemp.name << "\nHours: " << newemp.hours << "\nRate: " << newemp.rate << "\nidnum: " << newemp.idnum << endl; cout << "Pay is: " << pay << endl; return 0; }