Homework – Zeller’s Algorithm Pt2 Zeller’s algorithm computes the day of the week on which a...

50.1K

Verified Solution

Question

Programming

Homework – Zeller’s Algorithm Pt2

Zeller’s algorithm computes the day of the week on which a givendate will fall (or fell). You are provided this algorithm inCANVAS. In this task, you must transform the provided solution to a“Defined Function”

Function Name

zelleralg

Input Parameters

• month • day
• year

Return Values

The result from the algorithm. This is a number (0-6) thatcorresponds to the day of the week, where 0 represents Sunday, 1 isMonday, . . ., 6 is Saturday.

Information collected from the input NONE (all user inputs fromMAIN script) command
Output to the screen NONE (all outputs printed from MAINscript)

On the main script, welcome the user, ask for his/her name, andDOB (date of birth). Then call the “defined function” and print-outa formatted output.

   

USER INPUT

USER INPUT

FORMATTED OUTPUT

Finally ask if the user if he/she wants to RERUN. If yes, loopyour code all-over. If not, just display a goodbye message.

]

(Below is the solution for the code. you just have to developthe user defined function and the rest of the instructions areabove. when finished it should look like the larger text)

clear

clc

% Welcome message

fprintf('Welcome. This program uses the Zeller''s algorithm tocompute\n')

fprintf('the day of the week for a given date. Outputs are givenas\n')

fprintf('numbers between 0 - 6:\n')

fprintf('(0) - Sun \t(1)- Mon \t(2)- Tue \t(3)- Wed \t(4)- Thu\t(5)- Fri')

fprintf('\t(6)- Sat\n')

fprintf('\nINPUT THE DATE:\n')

% Input section

Month = input('Month: ');

Day = input('Day: ');

Year = input('Year: ');

% A = 1 plus the remainder of (the month number plus 9) dividedby 12

A = 1+mod(Month+9,12);

% B = the day of the month

B = Day;

% C = the year of the century PLUS the ROUND DOWN from theequation: (0.09*Month-

0.27).

C = (mod( Year , 1000 ))+floor(0.09*Month-0.27);

%D = the century

D = floor( Year / 100 );

% Additional integers necessary for the calculation

W = floor((13*A-1)/5);

X = floor(C/4);

Y = floor(D/4);

Z = W+X+Y+B+C-2*D;

% R is the day of the week, where 0 represents Sunday, 1 isMonday, . . ., 6 is

Saturday

R = mod( Z, 7 );

fprintf('\nOUTPUT:\n')

fprintf('%d/%d/%d = %d\n', Month, Day, Year, R );

Answer & Explanation Solved by verified expert
4.2 Ratings (600 Votes)
zelleralg function function R zelleralgMonth Day Year A 1 plus the remainder of the month number plus 9 divided by 12 A 1modMonth912 B the day of the month B Day C the year of the century PLUS the ROUND DOWN from the equation 009Month027    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students