help on project

Discussion in 'C++' started by Luis, Jul 30, 2003.

  1. Luis

    Luis Guest

    My project is to make a calander which will print out every month depending
    on the year leap year or not) and the first day of the year. this is what i
    have so far, but i don't know how to go about making it go to a new line
    when the end od the current line is reaxched. Please take a look at my code,
    and tell me if you have suggestions. It has no comments, and is pretty raw,
    i am to the point of ust printing only 1 month, not all 12 yet. Please help
    out, if i don't pass this, I may not pass the class.

    #include <iostream>

    using namespace std;

    void getData (int& year , int& firstDay);
    void header (int month);
    void goToFirstDay(int firstDay, int& columnCount);
    void daysInMonth(int month,int year, int& numDaysInMonth );
    bool isLeapYear(int year);
    void printOneMonth(int month , int year,int firstDay);
    void printNumbers (int numDaysInMonth);



    int main ( )
    {
    int month = 2;
    int year; //info given from getData()
    int firstDay ; // info from getData()


    getData (year , firstDay);
    printOneMonth( month, year, firstDay);



    return 0;
    }





    void getData (int& year , int& firstDay)
    {
    cout << "what year do you want the calander for?" ;
    cin >> year;
    cout << "what day of the week does january 1 fall on?" << endl;
    cout << "(enter 0 for sunday , 1 for monday, etc.)";
    cin >> firstDay;
    }




    void header (int month)
    {
    switch (month)
    {

    case 1 : cout << " January" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;

    case 2 : cout << " Febuary" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;

    case 3 : cout << " March" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;

    case 4 : cout << " April" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;

    case 5 : cout << " May" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;

    case 6 : cout << " June" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;

    case 7 : cout << " July" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;

    case 8 : cout << " August" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;
    case 9 : cout << " September" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;

    case 10 :cout << " October" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;

    case 11: cout << " November" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;

    case 12: cout << " December" << endl;
    cout << " S M T W T F S " << endl;
    cout << "--------------------" << endl;
    break;
    }
    }








    void goToFirstDay(int firstDay, int& columnCount )
    {
    int count = 0;



    cout << " ";
    if (firstDay > 0)
    {
    for (count; count < firstDay ;count++)

    {
    cout << " ";


    }
    }

    columnCount = count + (count*3);

    }







    void daysInMonth( int month, int year, int& numDaysInMonth )
    {

    switch (month)
    {
    case 1 :
    case 3 :
    case 5 :
    case 7 :
    case 8 :
    case 10 :
    case 12 : numDaysInMonth = 31;
    break;
    case 4 :
    case 6 :
    case 9 :
    case 11 : numDaysInMonth = 30;
    break;

    case 2 : if (isLeapYear(year))
    {

    numDaysInMonth = 29;

    }
    else if (!isLeapYear(year))
    {
    numDaysInMonth = 28;

    }
    }

    }







    bool isLeapYear(int year)
    {
    if (year % 400 == 0){
    return true;
    }

    if (year % 100 == 0){
    return false;
    }

    if (year % 4 == 0){
    return true;
    }

    return false;
    }










    void printOneMonth(int month,int year,int firstDay)
    {
    int numDaysInMonth;
    int columnCount;

    header(month);
    daysInMonth( month, year, numDaysInMonth );
    goToFirstDay(firstDay,columnCount);
    printNumbers (numDaysInMonth);



    }


    void printNumbers (int numDaysInMonth)
    {
    int count = 1;



    for (count;count<=numDaysInMonth;count++)
    {

    cout << count << " ";
    }
    }
     
    Luis, Jul 30, 2003
    #1
    1. Advertising

  2. On 28/7/03 7:27 pm (UK time), Mike Wahler let loose these words:
    <snip>
    > You cause subsequent output to appear on a 'new line' with
    > the, um, newline character.
    >
    > std::cout << '\n';

    <snip>

    std::endl is better in most cases.

    Stewart.

    --
    My e-mail is valid but not my primary mailbox. Please keep replies on
    on the 'group where everyone may benefit.
     
    Stewart Gordon, Aug 1, 2003
    #2
    1. Advertising

  3. Stewart Gordon wrote:
    > On 28/7/03 7:27 pm (UK time), Mike Wahler let loose these words:
    > <snip>
    >
    >> You cause subsequent output to appear on a 'new line' with
    >> the, um, newline character.
    >>
    >> std::cout << '\n';

    >
    > <snip>
    >
    > std::endl is better in most cases.
    >


    Why? Flushing the stream when it's not necessary is wasteful.

    -Kevin
     
    Kevin Goodsell, Aug 1, 2003
    #3
  4. On 1/8/03 6:52 pm (UK time), Kevin Goodsell let loose these words:

    > Stewart Gordon wrote:

    <snip>
    >> std::endl is better in most cases.
    >>

    >
    > Why? Flushing the stream when it's not necessary is wasteful.


    Mabye "most cases" was a slight exaggeration. But if cout remains
    unflushed when the program exits or user input is requested, there's the
    odd chance of something getting messed up.

    Stewart.

    --
    My e-mail is valid but not my primary mailbox. Please keep replies on
    on the 'group where everyone may benefit.
     
    Stewart Gordon, Aug 1, 2003
    #4
  5. Stewart Gordon wrote:

    > On 1/8/03 6:52 pm (UK time), Kevin Goodsell let loose these words:
    >
    >> Stewart Gordon wrote:

    >
    > <snip>
    >
    >>> std::endl is better in most cases.
    >>>

    >>
    >> Why? Flushing the stream when it's not necessary is wasteful.

    >
    >
    > Mabye "most cases" was a slight exaggeration. But if cout remains
    > unflushed when the program exits or user input is requested, there's the
    > odd chance of something getting messed up.
    >


    I don't know about that... Unless I'm mistaken, cout will be flushed
    when it is destroyed, so the program ending shouldn't be a problem
    (although it could be, depending on how the program ends - but as long
    as it ends correctly it should be fine).

    Also, cout is automatically flushed when cin is used, I think.

    In the case of cout you'll probably want it flushed more frequently than
    other streams, and it probably will be flushed in some cases where you
    don't necessarily want it, but in general streams should only be flushed
    when there's a reason.

    -Kevin
     
    Kevin Goodsell, Aug 1, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Claude seraphin
    Replies:
    12
    Views:
    2,385
    samundersingh1983
    Feb 15, 2014
  2. Ken Stealth
    Replies:
    2
    Views:
    4,322
    =?Utf-8?B?amRneChDb2xvbWJpYSk=?=
    Jan 31, 2004
  3. =?Utf-8?B?dHJlbGxvdzQyMg==?=

    HELP! HELP! HELP! Opening Web Application Project Error

    =?Utf-8?B?dHJlbGxvdzQyMg==?=, Feb 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    776
    =?Utf-8?B?dHJlbGxvdzQyMg==?=
    Feb 20, 2004
  4. Brad
    Replies:
    2
    Views:
    578
    Kevin Spencer
    Apr 1, 2004
  5. Mohanajeeva.D

    need ur help for my Masters project(TASM project)

    Mohanajeeva.D, Jul 2, 2010, in forum: C Programming
    Replies:
    2
    Views:
    877
    Vincenzo Mercuri
    Jul 2, 2010
Loading...

Share This Page