Results 1 to 2 of 2

Thread: calendar code Please Help Me :(

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    61

    calendar code Please Help Me :(

    Question: Develop a functional decomposition and write a C++ program to print a calendar for one year, given the year and the day of the week that January 1 falls on. It may help to think of this task as printing 12 calendars, one for each month, given the day of the week on which a month starts and the number of days in the month. Each successive month stars on the day of the week that follows the last day of the preeding month. Days of the week should be numbered 0 through 6 for Sunday through Saturday. Years that are divisible by 4 are leap years. (Determining leap years actually is more complicated that this, but for this program it will suffice.) Here is a sample run for an interactive program:

    What year do you want a calendar for?
    2002
    What day of the week does January 1 fall on?
    (Enter 0 for Sunday, 1 for Monday, et.c)
    2

    2002
    January
    S M T W T F S
    1 2 3 4 5
    6 7 8 9 10 11 12
    .
    .
    .
    .
    .

    December
    S M T W T F S
    1 2 3 4 5 6 7

    My code: But I get stuck ....

    Int Print_Month(int month, int weekstart, int no_of_days)

    Void point month header(int month);

    Int iweekstart; //global variable

    Int main()
    {
    int year;
    cin >> year;
    cin >> iweekstart;

    for (int k = 1; k <= 12; k++)
    {
    if (k ==1 || k == 3 || k ==5 || k ==7 || k ==8 || k == 10 || k == 12)

    print month (k, iweekstart, 31)

    if ( k == 4 || k == 6 || k == 9 || k == 11)

    print month ( k, iweekstar, 30)

    if ( k == 2)
    {

    if ( year % 4 == 0)

    print month ( k, iweekstart, 29)

    else print month (k, iweekstart, 28);

    }

    return 0;

    }

    {

    char space [4] = “…..”;

    print month header (month);

    for (int i=1; i<=weekstart; i++)
    count<<space;

    for (int j = 1; j <= no_of_days; j++)

    {

    cout << setw(3);

    cout << j;

    if ( j + weekstart = (weekstar – 1) + no_of_days) % 7;

    flush (count);

    return 0;

    }

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    So? We won't solve your school assignments. With which part do you have problems?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width