// 5/8/14 class example // Payroll Program // This version uses an array of objects // i.e. each element in the array is an object of type Employee #include #include using namespace std; // Class Declarations class Address { public: int housenumber; string street; string city; string state; string country; string zipcode; }; class Name { public: string first; string middle; string last; }; class Employee { public: Name name; Address a; double hours; double rate; int idnum; }; //prototypes void printEmployee(Employee); // pass by value void readinEmployee(Employee&); // pass by reference int main() { // initialize a running sum double sum=0, pay; // instantiate an array of objects of type Employee Employee employeelist[25]; for (int i=0; i<2; i++) { // read in using the function that accepts an object by reference readinEmployee(employeelist[i]); printEmployee(employeelist[i]); pay = employeelist[i].hours * employeelist[i].rate; cout << "Pay is: " << pay << endl; sum += pay; } cout << "The total pay is: " << sum << endl; return 0; } // an object is by default PASS BY VALUE void printEmployee(Employee e) { cout << "\nin the function printEmplyee: " << endl; // Display all the info for an employee object emp cout << "Name: " << e.name.first << ' ' << e.name.last << endl << "Address: " << e.a.housenumber << ' ' << e.a.street << ' ' << e.a.city << endl << "\nHours: " << e.hours << "\nRate: " << e.rate << "\nidnum: " << e.idnum << endl; } // read in one employee object and put into reference parameter void readinEmployee(Employee &e) { cout << "Enter an id number of an employee: "; cin >> e.idnum; cout << "Enter hours and rate: "; cin >> e.hours >> e.rate; cout << "enter first name: "; cin >> e.name.first; cout << "enter last name: " ; cin >> e.name.last; // read in address cout << "Enter house number: "; cin >> e.a.housenumber; cout << "Enter street: "; cin >> e.a.street; cout << "Enter city: "; cin >> e.a.city; // do this for all members } Employee readinEmployee2() { Employee e; cout << "Enter an id number of an employee: "; cin >> e.idnum; cout << "Enter hours and rate: "; cin >> e.hours >> e.rate; cout << "enter first name: "; cin >> e.name.first; cout << "enter last name: " ; cin >> e.name.last; // read in address cout << "Enter house number: "; cin >> e.a.housenumber; cout << "Enter street: "; cin >> e.a.street; cout << "Enter city: "; cin >> e.a.city; // do this for all members return e; } /* LAB 1 for today: Declare 2 classes: Brand: make and model Car: Brand b, year, mileage, price In main, instantiate 2 objects of type Car. Read in values for both objects and print them. Then, print the one with the cheaper price. LAB 2: Define an array of cars. Read in values for at least 3 cars in the array. Then, allow the user to enter a year. Print all cars whose year is later than (or the same) as the entered year. */