HW5 V1 (2) rences Mailings Review View AaBbCcDdEe AaBbCcDdEe AaBbCcDc Aa Normal
ID: 3588542 • Letter: H
Question
HW5 V1 (2) rences Mailings Review View AaBbCcDdEe AaBbCcDdEe AaBbCcDc Aa Normal No Spacing Heading 1 Write a script Time that will prompt the user to enter the current time as a vector of two elements [hours minutes) and the time zone (HST, AKST, PST, MST, CST, and EST) as a string. Based on the values entered, the script must calculate and display the standard time in the other time zones based on the conversion of the given Table. If another time zone is entered, the program must display a message of invalid entry and ask the user to try again. You can assume a 24-hour clock, so for example if the standard time in CST is [12 40], it would be [13 40] in MST, etc. see the Table below. The script must not display any negative times, for example if the HST time is 1:10 am it must be 24 in KST and 23 in PST, etc. Using fprintf, the output must be displayed as Time in HSTi40 Time in KST is 24:40 Time in PST is 23:40 Time in MST is 22:40 Time in CST is 21:40 Time in EST is 20:40, Use your script to find the following times in all time zones: a) 2:30 pm in HST b) 10:50 pm in EST c) 2:20 am in KST d) 4:40 am in HST e) 1:10 am in FST (FST is not a predefined time zone) Table: Standard time and daylight saving time Time Zone Standard Time Hawall Time Zone HST (UTC-10:00 Alaska Time Zone KST (UTC-09:00) Pacific Time Zone PST (UTC-08:00) Mountain Time Zone MST (UTC-07:00) ral Time Zone CST (UTC-06:00) Eastern Time Zone |EST (UTC-05:00) AN) FExplanation / Answer
Remark: Please check the example provided. If HST is 1:40 then utc becomes 11:40. So, KST will be 2:40, PST will be 3:40, MST as 4:40 and so on.
Below code, input is case sensitive and enter the time as [hours mins]
Copy and paste the code in the matlab script file and run it. It will ask the inputs. Enter inputs accordingly. You can get the outputs for the time you wish.
MATLAB CODE
% %%%% start of code
clc
clear all
s1 = input('Select from below menu(case sensitive) HST KST PST MST CST EST:','s');
A = input('time(please enter in the format [hours mins]:)');
s2 = {'HST','KST','PST','MST','CST','EST'};
x = strcmp(s1,s2);
time = A;
if s1 == 'HST'
utc = time(1) +10 ;
elseif s1 == 'KST'
utc = time(1) +9 ;
elseif s1 == 'PST'
utc = time(1) +8 ;
elseif s1 == 'MST'
utc = time(1) +7 ;
elseif s1 == 'CST'
utc = time(1) +6 ;
elseif s1 == 'EST'
utc = time(1) +5;
else
display('Wrong entry');
end
sav_HST = [utc-10 time(2)];
if sav_HST(1) >= 24 && sav_HST(2)>0
sav_HST(1) = sav_HST(1) - 24;
elseif sav_HST(1) < 0
sav_HST(1) = 24 - sav_HST(1);
end
sav_KST = [utc-9 time(2)];
if sav_KST(1) >= 24 && sav_KST(2)>0
sav_KST(1) = sav_KST(1) - 24;
elseif sav_HST(1) < 0
sav_KST(1) = 24 - sav_KST(1);
end
sav_PST = [utc-8 time(2)];
if sav_PST(1) >= 24 && sav_PST(2)>0
sav_PST(1) = sav_PST(1) - 24;
elseif sav_PST(1) < 0
sav_PST(1) = 24 - sav_PST(1);
end
sav_MST = [utc-7 time(2)];
if sav_MST(1) >= 24 && sav_MST(2)>0
sav_MST(1) = sav_MST(1) - 24;
elseif sav_PST(1) < 0
sav_MST(1) = 24 - sav_MST(1);
end
sav_CST = [utc-6 time(2)];
if sav_CST(1) >= 24 && sav_CST(2)>0
sav_CST(1) = sav_CST(1) - 24;
elseif sav_PST(1) < 0
sav_CST(1) = 24 - sav_CST(1);
end
sav_EST = [utc-5 time(2)];
if sav_EST(1) >= 24 && sav_EST(2)>0
sav_EST(1) = sav_EST(1) - 24;
elseif sav_PST(1) < 0
sav_EST(1) = 24 - sav_EST(1);
end
fprintf('time in HST is %d:%d ',sav_HST(1),sav_HST(2));
fprintf('time in KST is %d:%d ',sav_KST(1),sav_KST(2));
fprintf('time in PST is %d:%d ',sav_PST(1),sav_PST(2));
fprintf('time in MST is %d:%d ',sav_MST(1),sav_MST(2));
fprintf('time in CST is %d:%d ',sav_CST(1),sav_CST(2));
fprintf('time in EST is %d:%d ',sav_EST(1),sav_EST(2));
%%%%%%%%%%%%% end of code
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.