| CSCI 240 | Spring 2026 |
For this assignment, implement a class called Employee that will be used to hold the information for an employee.
The cpp file that is submitted for grading must be named assign10.cpp.
The definition for the Employee class should be placed at the top of a CPP file while the constructor and methods should be written after the closing curly brace for int main().
The data members for the class are:
an array of 30 characters to hold the employee's name
an array of 8 characters to hold the employee's identification number
a double to hold the employee's salary
The default constructor (the constructor that takes no arguments) for the class should initialize the data members so that employee name is "None", the identification number is "ACB1234", and the salary is 0.00.
The alternate constructor for the class should initialize the data members using values that are passed to the constructor. It takes 3 arguments: an array of constant character with an employee name, an array of constant character with the employee identification number, and a double that holds the employee salary.
Use the setID and setSalary methods to initialize the identification number and salary, respectively. Use the strcpy function to initialize the name.
The set methods do not rely on a default value for a data member when invalid information is passed to the method. Therefore, make sure to initialize the identification number ("ABC1234") and salary (0.0) before calling the methods in the alternate constructor.
The following methods are required for the Employee class.
This method displays the employee information.
It takes no arguments and returns nothing.
The name and id number should be displayed on a single line. The salary should be displayed on the line below.
The name should be left justified in a field 30 characters wide. The id number should be right justified in a field 10 characters wide. The salary should be displayed with two digits after the decimal point and a leading dollar sign. For example:
Barney Rubble NIU4865 $6782.40
This method increases an employee's salary.
It takes one argument: a double that represents the amount to increase the employee's salary. It returns nothing.
If the passed in amount is invalid (less than or equal to 0), display an error message and do not make any changes to the employee's salary. If the passed in amount is valid, use it to increase the employee's salary.
Error message format:
Error: salary increase ($[increase]) is invalid. Salary was not changed.
where [increase] is replaced by the invalid argument value. The message should start and end with a single newline character.
This method changes an employee's identification number.
It takes one argument: an array of constant characters that holds the updated employee identification number. It returns nothing.
Error checking is required. A valid identification number is exactly 7 characters in length. The first 3 characters must be alphabetic. The remaining 4 characters must be digits.
If the argument value is not exactly 7 characters in length, display an error message that the new identification number is not the correct length and do not make any change to the object. If the first 3 characters are not alphabetic, display an error message and do not make any change to the object. If the last 4 characters are not digits, display an error message and do not make any change to the object.
Once the argument has been validated, use it to change the identification number data member.
Error messages:
Error: new id ([ID]) is invalid - not 7 characters. ID was not changed. Error: new id ([ID]) is invalid - first 3 characters are not alphabetic. ID was not changed. Error: new id ([ID]) is invalid - last 4 characters are not digits. ID was not changed.
where [ID] is replaced by the invalid argument value. The messages should start and end with a single newline character.
This method changes an employee's salary.
It takes one argument: a double that represents the new employee salary. It returns nothing.
If the passed in salary is less than or equal to 0, display an error message and do not make a change to the salary data member. Otherwise, update the employee's salary.
Error message format:
Error: new salary ($[salary]) is invalid - negative or 0.00. Salary was not changed.
where [salary] is replaced by the invalid argument value. The message should start and end with a single newline character.
This method returns an employee's name. It takes no arguments.
The return data type shown above indicates that an address of a character should be returned. This can be satisfied by returning the name of a character array.
This method returns an employee's identification number. It takes no arguments.
This method returns an employee's salary. It takes no arguments.
The goal for int main() is to test the Employee class.
Create an Employee object using the constructor that takes 4 arguments. Use "Victor E. Huskie" for the employee name, an identification number of "NIU2468" , and a salary of 53948.61.
Display the first Employee object with the label "The first Employee object" (a single newline at the end), increase the salary by $125.15, and re-display the updated object.
Create a second Employee object. Use the default constructor.
Display the second Employee object with the label "The second Employee object" (two newlines before and one at the end), increase the salary by $-2200.00, and re-display the object.
Create a third Employee object. Use the constructor that takes 4 arguments. Use "Blanche Devereaux" for the employee name, an identification number of "TGG1985", and a salary of 820.12
Display the third Employee object with the label "The third Employee object" (two newlines before and one at the end), change the salary to $82.88, change the identification number to "TGP1992", and re-display the updated object.
Create a fourth Employee object. Use the constructor that takes 4 arguments. Use "Grace Hopper" for the employee name, an identification number of "UNI1950", and a salary of 2468.00
Display the fourth Employee object with the label "The fourth Employee object" (two newlines before and one at the end), change the identification number to "COBOL1959", "COB59!!", and "1959COB", increase the salary by $9517.53, display only the name and salary, and, finally, re-display the object.
Name and salary display format:
After updating salary by $9517.53, [name] has a salary of $[salary]
where [name] and [salary] are replaced by the values returned from the get methods. The message should start and end with a single newline character.
Create a fifth Employee object. Use the constructor that takes 4 arguments. Use "Charlie Hudson" for the employee name, an identification number of "REX2332", and a salary of 71940.76
Display the fifth Employee object with the label such as "The fifth Employee object" (two newlines before and one at the end), change the salary to $-10000.01, display only the identification number, and re-display the object.
Identification number display format:
Employee 5 has an identification number of [ID]
where [ID] is replaced by the value returned from the get method. The message should start and end with a single newline character.
Make sure to include <cstring> and <cctype> with the other #include statements so the string and character functions can be used.
Each constructor/method must have a documentation box like a function.
Hand in a copy of the source code on the autograder and Blackboard.
The first Employee object: Victor E. Huskie NIU2468 $53948.61 Victor E. Huskie NIU2468 $54073.76 The second Employee object: None ABC1234 $0.00 Error: salary increase ($-2200.00) is invalid. Salary was not changed. None ABC1234 $0.00 The third Employee object: Blanche Devereaux TGG1985 $820.12 Blanche Devereaux TGP1992 $82.88 The fourth Employee object: Grace Hopper UNI1950 $2468.00 Error: new id (COBOL1959) is invalid - not 7 characters. ID was not changed. Error: new id (COB59!!) is invalid - last 4 characters are not digits. ID was not changed. Error: new id (1959COB) is invalid - first 3 characters are not alphabetic. ID was not changed. After updating salary by $9517.53, Grace Hopper has a salary of $11985.53 Grace Hopper UNI1950 $11985.53 The fifth Employee object: Charlie Hudson REX2332 $71940.76 Error: new salary ($-10000.01) is invalid - negative or 0.00. Salary was not changed. Employee 5 has an identification number of REX2332 Charlie Hudson REX2332 $71940.76