Problem: In the code below, Employee class stores employee name, age and password. But there are some
conditions for employee class object that are
1. Employee age must be greater than 18
2. Password must have followed following rules
• Password must contain at least one lower case alphabet
• Password must contain at least one upper case alphabet
• Password must contain at least 1 number
• Password must contain at least one special character.
While class EmployeeList is used to store new employee objects. It’s AddEmployee function create new objects of
employee class and store them in the list. If during creation of employee objects input data is not according to
conditions, you must through an exception. For this purpose,
1. create two classes ageException and passwordException. Each have a data member msg of string type and a
parameterized constructor to initialize msg.
2. Throw these classes objects with proper msgs as exceptions from check age and check password functions.
3. Add employee function will use try and catch blocks to capture these exceptions. Function must display the
exception msg to the user.
a. Incase exception thrown is ageException then delete the dynamically created object of employee
and display msg that this employee can’t be added.
b. Incase exception thrown is passwordException then after displaying the exception msg. Prompt user
if he wants to enter password again or to cancel the addition. If he wants to enter again ask him
check the condition and repeat cycle and if he wants to cancel it, then delete the dynamically
created object of employee and display msg that this employee addition failed.
Also implement the class in main function after adding above conditions into the below class
class Employee {
private:
string firstName;
string lastName;
int age;
string password;
public:
Employee(string fn, string ln, int a, string p) :firstName(fn), lastName(ln)
{
checkAge(a);
age = a;
checkPassword(p);
password = p;
cout << “Employee Pbject Created”;
}
~Employee() { cout << “destructor called”; }
string getFirstName() { return firstName; }
string getLastName() { return lastName; }
int getAge() { return age; }
void checkAge(int a) {
}
void checkPassword(string input) {
int n = input.length();
bool hasLower = false, hasUpper = false;
bool hasDigit = false, specialChar = false;
string normalChars = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 “;
for (int i = 0; i < n; i++) {
if (islower(input[i]))
hasLower = true;
if (isupper(input[i]))
hasUpper = true;
if (isdigit(input[i]))
hasDigit = true;
size_t special = input.find_first_not_of(normalChars);
if (special != string::npos)
specialChar = true;
}
}
};
class EmployeeList {
Employee** list;
int capacity;
int count;
public:
EmployeeList(int size) {
capacity = size;
list = new Employee * [size];
count = 0;
}
void addEmployee(string fn, string ln, int a, string p)
{
list[count] = new Employee(fn, ln, a, p);
count++;
}
};
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more