Thread: Please help me with my c++ homework!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25

    Thumbs up Please help me with my c++ homework!

    Background

    Zeller’s Congruence is a formula that calculates the day of the week on which any date falls, given the month, day, and year. Zeller’s Congruence is:

    (D + floor((M+1)*26/10) + Y + floor(Y/4) + floor(C/4) - 2*C) mod 7

    where C is the century (the left-most two digits of the year, for example, 19 if the year is 1948), Y is the year within the century (0-99), D is the day number (1-31), and M is determined from the month by:

    January M = 13, and subtract 1 from the year before computing C and Y.
    February M = 14, and subtract 1 from the year before computing C and Y.
    March M = 3
    April M = 4
    ... ...
    November M = 11
    December M = 12

    The value that results from Zeller’s Congruence is an integer in the range 0-6, where 0=Saturday, 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, and 6=Friday.

    The mod operator

    The mod operator in the formula refers to the mathematical modulo operation, as in modular arithmetic. It is closely related to the % operator in C++, but it is not identical. If integers A and B are both positive, then (A mod B) is the same as (A%B). However, if A is negative and B is positive, then (A mod B) is the same as (A%B)+B.

    In Zeller’s Congruence, the first operand of mod may be negative. You may write a function to implement this operation, if you wish.

    Assignment

    Write a C++ function called weekday that uses Zeller’s Congruence to calculate the day of the week on which a chosen date falls. The parameters of the function are three integers that indicate the chosen month (1-12), day (1-31), and year, for example, 7, 4, and 1776 for July 4, 1776. The return value of the function is an integer in the range 0-6 to indicate the weekday on which the date falls.

    Your program must repeatedly read a month, day, and year number, call the function to compute the day of the week, and call a void function to display the resulting day name. You must write the void function.

    Make your screen look like the sample below. Terminate the program when the user enters zero for a month number.


    Disclaimer

    Zeller’s Congruence is based upon the Gregorian calendar, which was gradually adopted across the Western world beginning on October 15, 1582. It does not produce correct weekdays before the adoption of the Gregorian calendar.

    Sample Run

    Here is a sample to illustrate how the screen must appear when your program runs. You must strictly follow this format, wording, spacing, and alignment. The characters in blue are typed by the user. The other characters are output by the program.


    Month----3
    Day------21
    Year-----1685
    Weekday--Wednesday

    Month----7
    Day------4
    Year-----1776
    Weekday--Thursday

    Month----12
    Day------7
    Year-----1941
    Weekday--Sunday

    Month----1
    Day------26
    Year-----1900
    Weekday--Friday

    Month----4
    Day------4
    Year-----2006
    Weekday--Tuesday

    Month----0
    Last edited by dmeyers81; 10-27-2010 at 11:54 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-03-2001, 04:39 PM
  2. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 04:49 PM
  3. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 03:16 PM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 01:26 PM

Tags for this Thread