Question

Could you script in Matlab : Script Name General Algorithm AddNewEmployee Display all of the ID...

Could you script in Matlab :

Script Name

General Algorithm

AddNewEmployee

  1. Display all of the ID numbers currently in use

  2. Read in a new ID number

  3. If the ID number read in is already in use

    1. Report this fact

    2. End this script

  4. Else (this is a new ID number)

    1. Read in:

      1. Years with the company

      2. Salary

      3. Vacation days

      4. Sick days

    2. Add this new employee to the database (by appending a new row to the end of the EmployeeData matrix)

      Note that this command should alter, not only the EmployeeData matrix, but also the EmployeeData.mat file (i.e. it should automatically save to the MAT-file)

DeleteEmployee

  1. Display all of the ID numbers currently in use

  2. Read in an ID number

  3. If the ID number exists, delete that employee

    Note that this command should alter, not only the EmployeeData matrix, but also the EmployeeData.mat file (i.e. it should automatically save to the MAT-file)

  4. Else tell the user that that employee ID does not exist

PrintEmployees

  1. Print out a table showing all of the current employees and all of their respective data

ShowEmployeeDataStatistics

  1. Print out statistics about the current employees including:

    1. The number of employees

    2. The average, minimum, and maximum values of:

      1. Years at the company

      2. Salary

      3. Vacation days

      4. Sick days

FindMaxEmployee

  1. Find and report the employee ID with the maximum value of either:

    1. Years at the company

    2. Salary

    3. Vacation days

    4. Sick days

    If more than one employee has that maximum value, show all of the ID numbers with that maximum

FindMinEmployee

  1. Find and report the employee ID with the minimum value of either:

    1. Years at the company

    2. Salary

    3. Vacation days

    4. Sick days

    If more than one employee has that minimum value, show all of the ID numbers with that minimum

To make the process a little easier to start with, you are being provided an initial employee database. The database is stored in a matrix variable named EmployeeData .

oading this MAT-file will give you an initial EmployeeData variable with value:

EmployeeData =

           1          27      100000          24          13
           2          24       94000          27           9
           3          18       79000          18           5
           4          12       80000          32           9
           5          12       28000          35          14
           6           6       53000          38           9
           7           1       42000          15          11
           8           6       58000          37           5
           9           6       45000          16           6
          10           2       34000          26           5

Homework Answers

Answer #1

AddNewEmployee.m

if isfile('EmployeeData.mat')
        EmployeeData = load('EmployeeData.mat').EmployeeData;
        disp("ID number already in use:")
        EmployeeData(:,1)'
else
        disp("No ID number in use.");
        EmployeeData = [];
end

new_id = input("Enter ID: ");
if size(EmployeeData) > 0 && any(new_id == EmployeeData(:,1))
        disp("Error: ID number is already in use")
        exit(1)
end
new_ywc = input("Years with the company: ");
new_sal = input("Salary: ");
new_vac = input("Vacation days: ");
new_sick = input("Sick Days: ");

EmployeeData = [EmployeeData; [new_id, new_ywc, new_sal, new_vac, new_sick]];
save('EmployeeData.mat', 'EmployeeData');

DeleteEmployee.m

if isfile('EmployeeData.mat')
        EmployeeData = load('EmployeeData.mat').EmployeeData;
        disp("ID number already in use:")
        EmployeeData(:,1)'
else
        disp("Error: Empty Employee List. (no file)");
        exit(1)
end

del_id = input("Enter ID: ");

for i = 1:size(EmployeeData(:, 1))
        id = EmployeeData(1, i)
        if id == del_id;
                EmployeeData(i, :) = []
                save('EmployeeData.mat', 'EmployeeData');
                exit(0);
        end
end

disp("Error: Employee ID not found.")

PrintEmployees.m

if isfile('EmployeeData.mat')
        EmployeeData = load('EmployeeData.mat').EmployeeData;
else
        disp("Empty File");
        exit(1);
end

header = ['ID','   Y W C ',' Salary ',  ' Vacation ', ' Sick'];
[header ;num2str(EmployeeData)]

ShowEmployeeDataStatistics.m

if isfile('EmployeeData.mat')
        EmployeeData = load('EmployeeData.mat').EmployeeData;
else
        disp("No Data File");
end

n = size(EmployeeData, 1);
printf("Number of Employee(s): %d \n", n)

printf("\nAverage:\n")
printf("The Years at the company: %d \n", (sum(EmployeeData(:, 2)) / n))
printf("Salary: %d \n", (sum(EmployeeData(:, 3)) / n))
printf("Vacation days: %d \n", (sum(EmployeeData(:, 4)) / n))
printf("Sick days: %d \n", (sum(EmployeeData(:, 5)) / n))

printf("\nMinimum:\n")
printf("The Years at the company: %d \n", min(EmployeeData(:, 2)))
printf("Salary: %d \n", (min(EmployeeData(:, 3))))
printf("Vacation days: %d \n", (min(EmployeeData(:, 4))))
printf("Sick days: %d \n", (min(EmployeeData(:, 5))))

printf("\nMaximum:\n")
printf("The Years at the company: %d \n", max(EmployeeData(:, 2)))
printf("Salary: %d \n", (max(EmployeeData(:, 3))))
printf("Vacation days: %d \n", (max(EmployeeData(:, 4))))
printf("Sick days: %d \n", (max(EmployeeData(:, 5))))

FindMaxEmployee.m

if isfile('EmployeeData.mat')
        EmployeeData = load('EmployeeData.mat').EmployeeData;
else
        disp("No Data File");
end

n = size(EmployeeData, 1);

max_ywc = max(EmployeeData(:, 2));
max_sal = max(EmployeeData(:, 3));
max_vac = max(EmployeeData(:, 4));
max_sick = max(EmployeeData(:, 5));

for i = 1:n
        if EmployeeData(i, 2) == max_ywc
                printf("Max year with company (ID): %i\n", EmployeeData(i, 1));
        end
end

for i = 1:n
        if EmployeeData(i, 3) == max_sal
                printf("Max Salary (ID): %i\n", EmployeeData(i, 1));
        end
end

for i = 1:n
        if EmployeeData(i, 4) == max_vac
                printf("Max Vacation days (ID): %i\n", EmployeeData(i, 1));
        end
end

for i = 1:n
        if EmployeeData(i, 5) == max_sick
                printf("Max Vacation sick (ID): %i\n", EmployeeData(i, 1));
        end
end

FindMinEmployee.m

if isfile('EmployeeData.mat')
        EmployeeData = load('EmployeeData.mat').EmployeeData;
else
        disp("No Data File");
end

n = size(EmployeeData, 1);

min_ywc = min(EmployeeData(:, 2));
min_sal = min(EmployeeData(:, 3));
min_vac = min(EmployeeData(:, 4));
min_sick = min(EmployeeData(:, 5));

for i = 1:n
        if EmployeeData(i, 2) == min_ywc
                printf("Min year with company (ID): %i\n", EmployeeData(i, 1));
        end
end

for i = 1:n
        if EmployeeData(i, 3) == min_sal
                printf("Min Salary (ID): %i\n", EmployeeData(i, 1));
        end
end

for i = 1:n
        if EmployeeData(i, 4) == min_vac
                printf("Min Vacation days (ID): %i\n", EmployeeData(i, 1));
        end
end

for i = 1:n
        if EmployeeData(i, 5) == min_sick
                printf("Min Vacation sick (ID): %i\n", EmployeeData(i, 1));
        end
end

EmployeeData.mat is empty by default and will be created on AddNewEmployee.m.

Here is a sample of that file. (On can create the rest using the AddNewEmployee.m)

# name: EmployeeData
# type: matrix
# rows: 2
# columns: 5
 1 27 100000 24 13
 2 24 94000 27 9
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
A study was done to look at the relationship between number of vacation days employees take...
A study was done to look at the relationship between number of vacation days employees take each year and the number of sick days they take each year. The results of the survey are shown below. Vacation Days 0 1 4 9 13 13 15 1 6 9 Sick Days 9 12 10 5 5 1 0 6 4 6 Find the correlation coefficient: r=r=   Round to 2 decimal places. The null and alternative hypotheses for correlation are: H0:? r μ...
Write Linux command lines to do the following: 1. Create a directory with name “yourName_ID” 2....
Write Linux command lines to do the following: 1. Create a directory with name “yourName_ID” 2. Create a file with name “yourLastName.txt” inside the directory created in step.1 3. Write inside the created file exactly the following content (you may use editors such as vim, pico, ….): Linux Lab Lab. ToDo#1 Summer Semester 2019/2020# 4. Display the first 2 lines of the file. 5. Change the permission of the file to read write and execute for owner, groups and others....
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects....
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects. The charges are based on the hours each employee works on each project. The structure and contents of the Ch08_ConstructCo database are shown in Figure P8.1. Use this database to answer the following problems. Database Schema The schema for the Ch08_ConstructCo database is shown below and should be used to answer the next several problems. Click this image to view it in its own...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL CPTR HIST MATH RELB Data Type Text Text Text Text Text Number Currency Date/Time Text DEPT_TITLE Biology Computer Science History Mathematics Religion    Field Name DEPT_CODE DEPT_TITLE Data Type Text Text INSTRUCTIONS Use SQL commands to create the tables and enter the data shown above using MS Access. Write the following SQL statement given below: 1. 2. 3. 4. 5. 6. 7. 8. 9....
You are a database consultant with Ace Software, Inc., and have been assigned to develop a...
You are a database consultant with Ace Software, Inc., and have been assigned to develop a database for the Mom and Pop Johnson video store in town. Mom and Pop have been keeping their records of videos and DVDs purchased from distributors and rented to customers in stacks of invoices and piles of rental forms for years. They have finally decided to automate their record keeping with a relational database. You sit down with Mom and Pop to discuss their...
Employee Handbook Presentation Assignment to be presented. This week, you have received the following email from...
Employee Handbook Presentation Assignment to be presented. This week, you have received the following email from a friend of yours, Helen Mayer. Helen is the owner of a local eco-friendly toy store, EcoGioco. There are two locations now open and each store employs 22 employees. You help Helen with her HR and employee issues in your spare time. She doesn’t have enough legal-related issues to justify hiring a full-time HR professional but does need guidance on what to do to...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
This will be my third time submitting this question. THERE SHOULD BE NO USE OF CSS...
This will be my third time submitting this question. THERE SHOULD BE NO USE OF CSS OR SWITCH STATEMENTS IN THE JAVASCRIPT. Even though there is stylesheet in the HTML file do no create a new one. Project Standards: Students will use click events to capture user input. Students will use variables to store information needed by their application and keep track of their program’s state. Students will use conditionals to control project flow. Project Task You will be building...
Yeah, Science! Pinkman Inc. (“Pinkman”) is a wholly owned subsidiary of an SEC registrant. Pinkman has...
Yeah, Science! Pinkman Inc. (“Pinkman”) is a wholly owned subsidiary of an SEC registrant. Pinkman has a contract (the “Contract”) with the Heisenberg Institute (“Heisenberg”), which is a privately funded research institute with the stated mission of developing a cure for narcolepsy and other wide-spread sleep disorders. Under the Contract (which has a term of ten years), Pinkman serves as the administrator of the “Lab,” which is a multiple-unit campus consisting of recreational vehicles that Heisenberg uses to conduct research....