[SOLVED] LC-3: CPS2390 lab 5

$25

File Name: LC-3:_CPS2390_lab_5.zip
File Size: 178.98 KB

5/5 - (1 vote)

Department of Computer Engineering
Wenzhou-Kean University
CPS2390, Fall 2016
Changjiang Zhang , Instructor

Due Date: Nov 29, 2016

Calendar

Introduction: Prompt the user for a day (1 31), month (1 12), and year (1753 9999) and print out the day corresponding to that datethat is, Sunday, Monday, Tuesday, etc. After printing the day of the week, your program should exit.

The bold text below represents user input. You may assume correct user input.

Example: Enter day: 1
Enter month: 1
Enter year: 2003
January 1, 2003 is a Wednesday.

Specifications:
There is an easy way to find the day of the week given a date known as Zellers Rule. The rule is as follows:
f = {day + [((13*month)-1)/5] + D + [D/4] + [C/4] 2*C} mod 7.

Anything within [] should be rounded down (to the smaller integer). Here, month is an integer from 1 to 12, with March being 1, April being 2, . . . , Jan being 11, and Feb being 12. Jan and Feb count as the 11th and 12th months of the previous year, respectively. D is the last 2 digits of the year and C is the first 2 digits of the year. For January 28, 2034, for example, D is 33 (not 34), C is 20, and month is 11(not 1). Sunday corresponds to f = 0, Monday is f = 1, etc. If f is negative, you must add 7.

Zellers Rule
The following formula is named Zellers Rule after a Reverend Zeller. [x] means the greatest integer that is smaller than or equal to x. You can find this number by just dropping everything after the decimal point. For example, [3.79] is 3. Heres the formula:
f = k + [(13*m-1)/5] + D + [D/4] + [C/4] 2*C.
k is the day of the month. Lets use January 29, 2064 as an example. For this date, k = 29.
m is the month number. Months have to be counted specially for Zellers Rule: March is 1, April is 2, and so on to February, which is 12. (This makes the formula simpler, because on leap years February 29 is counted as the last day of the year.) Because of this rule, January and February are always counted as the 11th and 12th months of the previous year. In our example, m = 11.
D is the last two digits of the year. Because in our example we are using January (see previous bullet) D = 63 even though we are using a date from 2064.
C stands for century: its the first two digits of the year. In our case, C = 20.
Now lets substitute our example numbers into the formula.
f = k + [(13*m-1)/5] + D + [D/4] + [C/4] 2*C
= 29 + [(13*11-1)/5] + 63 + [63/4] + [20/4] 2*20
= 29 + [28.4] + 63 + [15.75] + [5] 40
= 29 + 28 + 63 + 15 + 5 40
= 100.
Once we have found f, we divide it by 7 and take the remainder. Note that if the result for f is negative, care must be taken in calculating the proper remainder. Suppose f = -17. When we divide by 7, we have to follow the same rules as for the greatest integer function; namely we find the greatest multiple of 7 less than -17, so the remainder will be positive (or zero). -21 is the greatest multiple of 7 less than -17, so the remainder is 4 since -21 + 4 = -17. Alternatively, we can say that -7 goes into -17 twice, making -14 and leaving a remainder of -3, then add 7 since the remainder is negative, so -3 + 7 is again a remainder of 4.
A remainder of 0 corresponds to Sunday, 1 means Monday, etc. For our example, 100 / 7 = 14, remainder 2, so January 29, 2064 will be a Tuesday.
See http://mathforum.org/dr.math/faq/faq.calendar.html for more information.

If you decide to do this assignment, please follow the instructions below
Writing and testing your program

Your code should have a comment block at the beginning of the file containing your name, your student number, and a brief description of the program.
Your description should serve as a general summary of your programs approach to the problem and will aid in grading. It will also serve as a guideline for assigning partial credit. It is in your best interest to make all of your ideas clear through this summary and through commenting within your code.

You will write this program from scratch. You must call your source file (c_lab1.c).
Use Cygwin to compile it.
Type the following Command:
lcc o c_lab1c_lab1.c
You will get a c_lab1.obj file
Use LC3 simulator to run it.

What to turn in

Your c source file:c_lab1.c
Your LC3 object file: c_lab1.obj
Your readme.txt to describe your design ideas and test results.

Please put all your files in a zip file and send it to [email protected] before due date.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] LC-3: CPS2390 lab 5
$25