Please help me with my c++ homework!

This is a discussion on Please help me with my c++ homework! within the C++ Programming forums, part of the General Programming Boards category; Background Zeller’s Congruence is a formula that calculates the day of the week on which any date falls, given the ...

  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.

  2. #2
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    And...?
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #3
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    How do you do it?....please lol
    Last edited by dmeyers81; 10-27-2010 at 11:55 AM.

  4. #4
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by dmeyers81
    Do it for me....please lol
    I what I heard.

    the answer is no.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  5. #5
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    Well you dont have to do it for me but if you would help me i would be very appreciative

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,743
    So, what have you tried, and where are you stuck?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    1,205
    Attempt to solve the assignment and come back with specifc questions.

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Quote Originally Posted by dmeyers81 View Post
    Well you dont have to do it for me but if you would help me i would be very appreciative
    Hmmm, appreciative, in what way I wonder could that be?
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  9. #9
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    I see, you no speak c++.

    The only way we can help you is to tell you to try to do ANYTHING...
    Code the formula, the program does not even need to compile...
    If we do the easiest and most primitive part of the homework for you, what about the next one? Will you do it yourself? I don't think so...

  10. #10
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    I do know basic c++ but i feel like i took a class that is at a higher level than i should have


    I don't even know what variables to declare or exactly how to write my own functions, i took notes and if i was explained it again maybe in a different sense it would maybe be clearer...i learned it today in class but it is very confusing to me

    If i knew what the different functions i needed to use or exactly what loops i needed to use i believe i could figure out the algorithms to use in the body of those loops.

    That's why i came here because i figured people on here who would be considered maybe experts, or if not, still at least have more experience than me, and would be able to help me out with it.

    This is my fifth programming project and the first of which i came here for help.

    But i guess never mind because everyone is so stuck on the fact that i want someone to type the whole program for me.

  11. #11
    Registered User
    Join Date
    Aug 2003
    Posts
    1,205
    This is what happends when you let others do all the work for you. There is no way you "know basic c++" but dont know how to write your own functions, or what variables to declare on this basic assignment.

    C programming.com - Your Resource for C and C++ Programming has tutorials, start from the beginning and try to learn something this time!

  12. #12
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    I learned about functions for the first time today and they were confusing to me.

    All other programming projects we have had have only used if-statements, while-statements, do-while statements, and thats about the most of it.

    We have also only had to return 0; and this project calls to return more than that.

    This is the first programming project i have had that hasn't made any sense to me.

  13. #13
    Registered User
    Join Date
    Aug 2003
    Posts
    1,205
    Then read the tutorials on the page i linked you! Go read that now! Try to solve the problem on your own and come back with specific problems.

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    We cannot do you the homework for you. And we cannot help you if you took a course that is over your head.
    But we can help you eliminate confusion. But to do that, we need to know what you're confused about.
    Try taking something you're confused about. From your notes, from some we page, from the tutorial--anything. Ask questions. We will answer.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    First input the raw Y M D values and print them out.

    > 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)
    Then calculate C and print that out as well as the modified Y

    > January M = 13, and subtract 1 from the year before computing C and Y.
    Then do this, print C, Y, M, D

    etc etc
    You're about half way there when you've done those steps.

    Then post when you really get stuck.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 1 of 3 123 LastLast
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, 03: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21