Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Zeller s congruence ( source:Click _ here _ for _ more ) is an algorithm devised by Christian Zeller to calculate the day of the

Zellers congruence (source:Click_here_for_more) is an algorithm devised by Christian Zeller to calculate
the day of the week for any calendar date. For todays Gregorian calendar, Zellers congruence is
G =(q +(m +1)13
5+ U + U
4+ V
42 V ) mod 7(1)
where G is the day of the week (0 means Saturday, 1 means Sunday, 2 means Monday, ...), q is the day of
the month (1<= q <=31), m is the month (1<= m <=12), and y is the year of the calendar date (1582<= y <=2099).
Further, the above equation distinguishes V as the century (that is, V = y
100), and U as the year of
the century (that is, U = y mod 100).
Finally, there is an exception in Zellers congruence for the months of January and February which need to
be counted as month 13 and 14, respectively, of the previous year. Thus, if m =1 or m =2, then we need to
add 12 months to the value of m, and subtract 1 year from y before we feed the values into the above equation.
Your weekday calculation program should contain the following sections:
3.1 Input Section:
Prompt the user to enter a valid calendar date in the following format:
Please enter a calendar date:
Day, q =17
Month, m =1
Year, y =2024
We assume that the user will always enter proper input values, e.g. m, q and y will always be inputted
within the ranges outlined after Eqn. (1). Therefore, there is no need to handle any invalid input in your
program.
3.2 Data Preprocessing:
Deal with the exception for the months of January and February: if m <3 then add 12 to m and subtract
1 from y.
3.3 Computation:
Use Zellers congruence.
Hint: The floor function is implicit in any integer division. That is, if a and b are both integer variables,
then a
b = a
b .
3.4 Output Section:
For the program output, you should print a numerical identifier (06) to represent the computed weekday,
and you should also print the result as a regular text string, i.e. Saturday, Sunday, Monday, ..., or Friday.
For the example above, the output should look as follows:
3
For the calendar date 1/17/2024, the day of the week is 4.
This is a Wednesday.
The bold lines in steps 3.1. and 3.4. are what you should observe on the terminal.
You should save your program code in file named weekday.c, you should also prepare a text file week-
day.txt briefly explaining how you designed your program and any hardships faced (if any), and prepare a
typescript weekday.script which shows that you compile your program (see section below for compilation
details) and run it. Use the following dates as inputs for your typescript:
1/17/2024(the deadline for this assignment),
1/1/2025(next New Years Day), and
10/4/1965(the first day of classes at UCI).
For instructions on how to create a typescript, see Section 6 Typescript at the end of this document.
4 Compiling Your Code
To test your program, it must be compiled with the gcc command. This command will report any errors in
your code. To call gcc, use the following template:
zuma% gcc sourcefile -o targetfile
Then, simply execute the compiled file by typing the following:
zuma%./targetfile
Below is an example of how you will compile and execute the "weekday" program:
zuma% gcc weekday.c std=c11-Wall -o weekday
zuma%./weekday
NOTE: If you encounter this error: zuma% cc1: error: unrecognized command line option "-std=c11"
Then use this command before using gcc: zuma% scl enable devtoolset-7 tcsh
5 Submit Your Work
To submit your work, you have to be logged in to one of the following servers, zuma or crystalcove. Below
is a checklist of the files you should have.
In the hw1 directory, you should have the following files in your Linux account:
weekday.c
weekday.txt
weekday.script
We do require these exact file names (i.e. do not modify the file names). If you use different file names,
we will not see your files for grading. Now, you should change the current directory to the parent directory
containing the hw1 directory. Then type the command:
zuma% ~eecs22/bin/turnin.sh
which will guide you through the submission process.
You will be asked if you want to submit the script file. Type yes or no. If you type n or no or
just plain return, they will be ignored and be taken as a no. You can keep using the same command to
4
update your submitted files until the submission deadline. After the submission deadline, you CANNOT
modify the submitted files anymore

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions