P a g e 4 getter also called accessor functions

Info icon This preview shows pages 4–5. Sign up to view the full content.

View Full Document Right Arrow Icon
P a g e | 4 // getter (also called accessor) functions string getLastName() { return lastName; } string getFirstName() { return firstName; } char getGender() { return gender; } int getDependents() { return dependents; } double getSalary() { return salary; } staticint getEmployees() { return employees; } void getEmployee() { cout << "Employee Information\n" ; cout << "Name: \t\t" << firstName << " " ; cout << lastName << "\n" ; cout << "Gender:\t\t" << gender << "\n" ; cout << "Dependents: \t" << dependents << "\n" ; cout << "Annual Salary:\t" ; cout << setprecision(2) << showpoint << fixed; cout << salary << "\n" ; cout << "Weekly Salary:\t" ; cout << setprecision(2) << showpoint << fixed; cout << calculatePay() << endl; } // Other functions double calculatePay() { return salary/12.0; } }; int Employee::employees=0; //************************************************************** ***** // The "main" and the other functions //************************************************************** ***** void displayDivider(string message) { cout<< "\n*************** " + message + " *********************\n" ;} string getInput(string message) { string mystring; cout<< "Please enter your " <<message << ": " ; getline(cin, mystring); return mystring; } //--------------------------------------------------------------
Image of page 4

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CIS-247C 3/18/2012 OOP/C++ H3 Solutions P a g e | 5 ----- // the "main" function //-------------------------------------------------------------- ----- int main() { // Display lab informaiton cout << "Welcome to Lab 3 of CIS-247C:\n" ; // Display employee header displayDivider( "Employee 1" ); // create an employee object by using 5-argument constructor Employee employee1( "Mary" , "Noia" , 'F' , 2, 150000); // display the first employee object employee1.getEmployee(); // create another Employee objects displayDivider( "Employee 2" ); // declare another employee object Employee employee2; // prompt user for employee date, // then use setter function to save employee date employee2.setFirstName(getInput( "First Name " )); employee2.setLastName(getInput( "Last Name " )); string str = getInput( "Gender " ); // pick the first character from input string char gender = str.at(0); employee2.setGender(gender); // input string & convert it into integer employee2.setDependents(atoi( getInput( "Dependents " ).c_str())); // input string & convert it into double value. employee2.setSalary(atof(getInput( "Annual Salary " ).c_str())); // display the second employee object employee2.getEmployee(); // display the total count of all employees cout << "\nTotal number of employees : " ; cout << Employee::getEmployees() << endl; cout << "\n\nThe program will end now!\n" ; return 0; } H32 Output:
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern