Menu-driven program the will read an employee data and do the following?

4 visualizaciones (últimos 30 días)
I have a data set employee.dat
Name Department Birth_Date Date_Hired Salary Phone_Ext
'Smith, Jane' Service 072267 121298 87333 5188
'Smith, Joe' Sales 072269 121299 77333 5379
'Alkali, Sue' Account 010379 012202 57863 5256
'Mozart, Pat' Sales 033175 012201 65348 5378
'Kochab, Joe' Service 030172 121298 90132 5189
'Polaris, Curt' Account 091971 090102 90712 5255
'Dubhe, Mary' Sales 081370 090101 50365 5377
The program I am trying to make should read the information from the file into a data structure and then display a menu of options. The menu options are:
1. Print the information for all employees in a particular department (from user input).
2. Calculate the total payroll for the company (the sum of the salaries).
3. Find out how many employees have been with the company for N years (N might be 10,
for example).
4. Exit the program.
How do I obtain this?

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Oct. de 2013
See textscan(), and menu()
  2 comentarios
Nora
Nora el 27 de Oct. de 2013
How would I accomplish task #3 on the above list?
Image Analyst
Image Analyst el 27 de Oct. de 2013
Try this:
d = 121298 % Sample date
dstr = num2str(d)
month = str2double(dstr(1:2))
day = str2double(dstr(3:4))
year = str2double(dstr(5:end))
thisYear = str2double(datestr(now, 'YYYY'))-2000
if year > thisYear
year = 1900 + year
else
year = 2000 + year
end
serialDateHired = datenum(year, month, day)
serialDateNow = datenum(now)
daysElapsed = serialDateNow - serialDateHired
if daysElapsed > 365*3
msgbox('More than 3 years');
else
msgbox('Less than 3 years');
end
Of course you need to put in a few tweaks to handle leap years, but I assume you can figure that out.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Standard File Formats en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by