Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB script that will build an employee structure array and then sort

ID: 3572143 • Letter: W

Question

Write a MATLAB script that will build an employee structure array and then sort the structure array in ascending order based on salary. The structure should have three fields: name (single string), salary (single number >= 0), and years employed (single number >= 0). When building the structure array, the salary and years employed for the employee should be error checked to ensure they are valid values. Display the sorted structure array at the end of the script. A sample run should resemble the following: >> Enter the number of employees: 3 >> Enter the name of employee 1: Alexander Bell >> Enter the salary of employee 1: 25000 >> Enter the years employed of employee 1: 35 >> Enter the name of employee 2: Thomas Edison >> Enter the salary' of employee 2: -5000 That is an invalid salary >> Enter the salary of employee 2: 35000 >> Enter the years employed of employee 2:27 >> Enter the name of employee 3: Charles Coulomb >> Enter the salary' of employee 3: 17500 >> Enter the years employed of employee 3: -1 That is an invalid number of years >> Enter the years employed of employee 3:13 The employees sorted by salary are: name: 'Charles Coulomb salary: 17500 yearsEmployed: 13 name: 'Alexander Bell' salary: 25000 yearsEmployed: 35 name: 'Thomas Edison' salary: 35000 yearsEmployed: 27

Explanation / Answer

n = input('Enter the number of employees :');

for i=1:n

name = input('Enter the name of employee','s');

salary = input('Enter Salary of employee');

yearsEmployed = input('Enter the years employed of employee');

if (salary>= 0) && (yearsEmployed >=0)

sorted = {[name,salary,yearsEmployed]}

end

end

for j=1:n

final = sort(sorted,2);

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote