Question

In: Computer Science

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

Homework – Zeller’s Algorithm Pt2

Zeller’s algorithm computes the day of the week on which a given date will fall (or fell). You are provided this algorithm in CANVAS. 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) that corresponds to the day of the week, where 0 represents Sunday, 1 is Monday, . . ., 6 is Saturday.

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

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

   

USER INPUT

USER INPUT

FORMATTED OUTPUT

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

]

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

clear

clc

% Welcome message

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

fprintf('the day of the week for a given date. Outputs are given as\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) divided by 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 the equation: (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 is Monday, . . ., 6 is

Saturday

R = mod( Z, 7 );

fprintf('\nOUTPUT:\n')

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

Solutions

Expert Solution

% zelleralg function

function R = zelleralg(Month, Day, Year)
% A = 1 plus the remainder of (the month number plus 9) divided by 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 the equation: (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 is Monday, . . ., 6 is Saturday
R = mod( Z, 7 );

end

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

% MAIN script

clear
clc

% Welcome message
fprintf('Welcome. This program uses the Zeller''s algorithm to compute\n')
fprintf('the day of the week for a given date. Outputs are given as\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: ');

% function zelleralg called
R = zelleralg(Month, Day, Year)

% print the output
fprintf('\nOUTPUT:\n')
fprintf('%d/%d/%d = %d\n', Month, Day, Year, R );

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Output:

Welcome. This program uses the Zeller's algorithm to compute
the day of the week for a given date. Outputs are given as
numbers between 0 - 6:
(0) - Sun (1)- Mon (2)- Tue (3)- Wed (4)- Thu (5)- Fri (6)- Sat

INPUT THE DATE:
Month: 3
Day: 31
Year: 2020
R = 2

OUTPUT:
3/31/2020 = 2


Related Solutions

Use Java (Science: day of the week) Zeller’s congruence is an algorithm developed by Christian Zeller...
Use Java (Science: day of the week) Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is : h = (q + 26(m+1)/10 + k + k/4 + j/4 + 5j) % 7 where - h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). - q is the day of the month. - m is the month (3: March,...
Discrete Math Problems: From the below algorithm (linear search) construct the function f(n) which computes the...
Discrete Math Problems: From the below algorithm (linear search) construct the function f(n) which computes the number of steps the algorithm executes for a list of n integers and compute O(f) using the definition                     ALGORITHM 2 The Linear Search Algorithm.                 procedure linear search(x: integer, a1, a2,…, an: distinct integers)                 i := 1                 while (i ≤ n and x ≠ ai)                i := i + 1                if i ≤ n then location := i               ...
What day of the week is a given date? i.e. On what day of the week...
What day of the week is a given date? i.e. On what day of the week was 5 August 1967? if it is given that 1 January 1900 was a tuesday Write a function is leap() which takes 1 input argument, an integer representing a year, and returns True if the year was a leap year, and False if it was not. .Then, write a function days_since() which takes 3 input integers day, month, year, representing a date (after 1st...
STAT 200 Week 1 Homework Problems 1.1.4 To estimate the percentage of households in Connecticut which...
STAT 200 Week 1 Homework Problems 1.1.4 To estimate the percentage of households in Connecticut which use fuel oil as a heating source, a researcher collects information from 1000 Connecticut households about what fuel is their heating source. State the individual, variable, population, sample, parameter, and statistic 1.1.8 The World Health Organization wishes to estimate the mean density of people per square kilometer, they collect data on 56 countries. State the individual, variable, population, sample, parameter, and statistic 1.2.4 You...
Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode...
Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode for a solution of the following problem. This solution will include the use of arrays needed to complete all parts of the logic. You have requested to develop a program that will record and process the rainfall totals of a 12 month period. You would use an array to store each months total. Once all 12 months amounts are entered then your solution need...
Which Sorting algorithm are in place algorithm and which are not? Is it advantageous to design...
Which Sorting algorithm are in place algorithm and which are not? Is it advantageous to design in place sorting algorithm? How this in place term is related to the time complexity and space complexity of the program?
Write a query to return the date and day of the week of the first day...
Write a query to return the date and day of the week of the first day of the month two years from today. If today is 10/16/20, then the expect output is 10/01/2022 and the day of the week is thursday. I am using postgresql.
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
WEEK 1 HOMEWORK (based on your week 1 assignment) Please answer the following questions in complete...
WEEK 1 HOMEWORK (based on your week 1 assignment) Please answer the following questions in complete sentences. Identify and define at least 5 fallacies about racism. What areas of life does racism affect? Define the two types of racism (institutional and interpersonal). What is symbolic violence when it comes to race? At one time Jews dominated basketball; now it is a game almost exclusively for African Americans. The text authors identify at least two reasons why both of these groups...
Are phone calls equally likely to occur any day of the week? The day of the...
Are phone calls equally likely to occur any day of the week? The day of the week for each of 392 randomly selected phone calls was observed. The results are displayed in the table below. Use an αα = 0.10 significance level. Complete the rest of the table by filling in the expected frequencies: Frequencies of Phone Calls for Each Day of the Week Outcome Frequency Expected Frequency Sunday 55 Monday 54 Tuesday 64 Wednesday 50 Thursday 58 Friday 57...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT