Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QUESTION 2: You are asked to write a program file that will be named as 'Q2.m'. This main '.m' file will contain all your work

image text in transcribedimage text in transcribedimage text in transcribed

QUESTION 2: You are asked to write a program file that will be named as 'Q2.m'. This main '.m' file will contain all your work and a template (Q2_Empty.m) will be given to you beforehand to guide you for the asked tasks. In Q2, you are asked to write a main code which identifies the day of January (e.g., Monday, Thursday ....) on any year. To be able to do that task, you will use the Gauss' date formula which is explained below: Gauss' date formula Carl Friedrich Gauss described a method for calculating the day of the week for 1 January in any given year in a handwritten note in a collection of astronomical tables. He never published it. It was finally included in his collected works in 1927. Gauss' method was applicable to the Gregorian calendar. He numbered the weekdays from 0 to 6 starting with Sunday. He defined the following operation: The weekday of 1 January in year number A is R(1+5R(A1,4)+4R(A1,100)+6R(A1,400),7) where R(y,m) is the remainder after division of y by m, or y modulo m. The algorithm for the day-of-week of 1 Jan can be proven using modulo arithmetic. The main point is that because 365mod7=1, each year adds 1 day to the progression. The rest is adjustment for leap year. - In your main "Q2.m" file, you will get the year information (A) from the user. You will also write a function named as "January1Finder" and you will call this function to calculate the corresponding day information (for example Sunday or Wednesday) for the entered year. Additionally, your function must return the index value of the weekday (for example 0 for Sunday and 3 for Wednesday). This index value will be necessary in the second part of your solution in which the same problem will be solved without using "switch-case". - The structure of "January1Finder" function will be like this: [day day1_Jan] = January1Finder(year_val) year_val = is the year entered by the user day = weekday of 1 January for the entered year (e.g. Wednesday or Saturday) day1_Jan = is the index of corresponding weekday (for example 6 for Saturday and 3 for Wednesday). - In your "January1Finder" function you will use switch-case to convert index (day1_Jan) info to weekday (day) info. - After the "January1 Finder" function is called in your main .m file and the [day day1_Jan] values are obtained (as returning values of your function). You will obtain the current year info and print your findings by considering the appropriate grammar for past tense and future tense. Hint : You need to consider the current year and entered year info. - In the Second part, you need to write the code segment which identifies the correct weekday without using switch-case. You will only use the "day1_Jan" variable which is obtained from the "January1Finder" function. "day1_Jan" is the result of Gauss' method calculation whose formulation has already been given above. Do the same identification of weekday by just using index info and print it to the command window. - Sample calls of "Q2.m" file and its findings are given below for validation: please enter the year value that is interested: 2048 - Written by Gorkem - 1 January 2048 will be a Wednesday Second Part - Written by Gorkem - 1 January 2048: Wednesday please enter the year value that is interested: 2010 - Written by Gorkem - 1 January 2010 was a Friday Second Part - Written by Gorkem - 1 January 2010: Eriday You should write a report on your work using the supplied report format. You should be expressive and unique on your explanations and comments. [1] https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week\#Gauss's_algorithm %% clear all, close all, clc \% Ask to the user for entering year information \%your code should be written here %% \% find the corresponding day of the week for entered info by calling your \% function \%your code should be written here %% % find current year \%your code should be written here \% print the information using considering correct grammar! \%your code should be written here %% \% second part: please avoid using the switch-case

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

How would we like to see ourselves?

Answered: 1 week ago