H2 solutions 3182012 employeestring firstname string

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

View Full Document Right Arrow Icon
H2 Solutions 3/18/2012 Employee(string firstName, string lastName, char gender, int dependents, double salary) { // use the THIS keyword to identify the class attributes this ->lastName = lastName; this ->firstName = firstName; this ->gender = gender; this ->dependents = dependents; this ->salary = salary; } // setter (also called mutator) functions void setLastName(string name) { lastName = name; } void setFirstName(string name) { firstName = name; } void setGender( char gen) { switch (gen) { case 'f' : case 'F' : case 'M' : case 'm' : gender = gen; break ; default : gender = 'N' ; // 'N' not defined } } void setDependents( int dep) { dependents = dep; } void setSalary( double salary) { this ->salary = salary; } // 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; } 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; } };
Image of page 5

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

View Full Document Right Arrow Icon
CIS-247C OOP/C++ H2 Solutions 3/18/2012 //************************************************************** ******** // 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; } //-------------------------------------------------------------- ----- // the "main" function //-------------------------------------------------------------- ----- int main() { // Display lab informaiton cout << "Welcome to Lab 2 of CIS-247C:\n" ; // use a utility method to keep a consistent output format 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" ); //
Image of page 6
Image of page 7
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