// pgm39 // 12/7/16 class example // Payroll Program // Array of objects #include #include using namespace std; // Class Declaration -- like a blueprint NO MEMORY is allocated // this creates a new user defined Data Type class PersonName { public: string first; char middleinit; string last; }; class Address { public: int housenumber; string street; string city; string state; int zipcode; }; class Employee { public: PersonName name; Address a; double hours; double rate; int idnum; }; // prototypes void readEmployee(Employee&); void displayEmployee(Employee); double calcPay(Employee); int main() { // instantiate objects of type Employee Employee emparr[5]; double pay; for (int i=0; i<5; i++) { readEmployee(emparr[i]); displayEmployee(emparr[i]); pay = calcPay(emparr[i]); cout << "Pay for emp " << i << " is: " << pay << endl; } return 0; } // display all of the info of an Employee object void displayEmployee(Employee emp1) { cout << "Name: " << emp1.name.first << ' ' << emp1.name.last << "\nHours: " << emp1.hours << "\nRate: " << emp1.rate << "\nidnum: " << emp1.idnum << endl; cout << "Address: " << emp1.a.housenumber << ' ' << emp1.a.street << ' ' << emp1.a.city << endl; } // read in data members for an Employee object void readEmployee(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 first name: "; cin >> emp1.name.first; cout << "enter last name: "; cin >> emp1.name.last; cout << "enter middle initial: "; cin >> emp1.name.middleinit; // read in address also cout << "Enter house number: "; cin >> emp1.a.housenumber; cout << "Enter street: "; cin >> emp1.a.street; cout << "Enter city: "; cin >> emp1.a.city; // do this for all members } // this function calculates the pay for an Employee // and returns the pay double calcPay(Employee emp) { double pay; pay = emp.hours * emp.rate; return pay; } /* LAB: Use nested classes with Vehicle class. Design a class for Brand of a car. Brand is going to store: make and model of a car. You also had year, mileage and price as part of the Vehicle class. After you modify and TEST the class by using individual variables, you are going to instantiate an array of 3 Vehicle objects. Read in and display data for the objects in the array. */