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

조회 수: 4 (최근 30일)
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?

채택된 답변

Walter Roberson
Walter Roberson 2013년 10월 27일
See textscan(), and menu()
  댓글 수: 2
Nora
Nora 2013년 10월 27일
How would I accomplish task #3 on the above list?
Image Analyst
Image Analyst 2013년 10월 27일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by