Could you script in Matlab :
Script Name |
General Algorithm |
---|---|
AddNewEmployee |
|
DeleteEmployee |
|
PrintEmployees |
|
ShowEmployeeDataStatistics |
|
FindMaxEmployee |
|
FindMinEmployee |
|
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
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
Get Answers For Free
Most questions answered within 1 hours.