Need help with C++ Program

Need help with C++ Program

Post by Kip » Fri, 02 May 2003 12:32:07



HERE IS WHAT I HAVE TO DO:
Define a structure called DATE with three fields, each of which is an
integer: one for the month, one for the day and one for the year, and
write a function called increment that accepts a date structure,
increments the date by one day and returns the new date. If the date
is the last day of the month, then the month field also must be
changed. If the month is 12 (December) and the day is 31, then the
value of the year field must also be changed. (Remember a year is a
leap year if it is evenly divisible by 4 but not by 100 or it is
evenly divisible by 400.) Finally, build a complete program that reads
a particular date and prints the next date.

HERE IS WHAT I HAVE DONE:
#include <iostream.h>
#include <iomanip.h>

   struct DATE_1
   {
      int month;
      int day;
      int year;
   };

   void increment_date(DATE_1 &date)

int main()
{
   DATE_1 date;  

   date.year;
   date.day;
   date.month;

   switch(month)
   {
      case1: case 3: case 5: case 7: case 8: case 10: case 12:
      {
         if(date.day < 31)
         {
            date.day++;
         }
         else
         {
            date.day = 1;
            date.month++;
         }
      }break;
      case 4: case 6: case 9: case 11:
      {
         if(date.day < 30)
         {
            date.day++;
         }
         else
         {
            date.day = 1;
            date.month++;
         }
      }break;
      case 2:
      {
         if(((date.year % 4) == 0) && ((date.year % 100) != 0)
         {
            if((date.year % 400) == 400)
         }
         if(date.day < 28)
         {
            date.day++;
         }
         else
         {
            date.day = 1;
            date.month++;
         }
      return 0;

Quote:}

 
 
 

Need help with C++ Program

Post by David Whit » Fri, 02 May 2003 12:50:37


Whether you post from Google or AOL, it's the same newsgroup. Starting 3
threads for the same question is not the way to ask for help. All you are
doing is annoying the very people who might have helped.

David

 
 
 

Need help with C++ Program

Post by Xu Chua » Fri, 02 May 2003 14:14:14


I always implement it in this way. You can write the main function by
yourself.

int daycount[2][12] = {
        {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
        {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

struct Date {
        int month, day, year;

Quote:};

int isleapyear(int year)
{
        return !(year % 400) || (year % 100 && !(year % 4));

Quote:}

Date increment(Date d)
{
        if (++d.day > daycount[isleapyear(d.year)][d.month - 1]) {
                d.day = 1;
                if (++d.month > 12) {
                        d.month = 1;
                        ++d.year;
                }
        }
        return d;

}



Quote:> HERE IS WHAT I HAVE TO DO:
> Define a structure called DATE with three fields, each of which is an
> integer: one for the month, one for the day and one for the year, and
> write a function called increment that accepts a date structure,
> increments the date by one day and returns the new date. If the date
> is the last day of the month, then the month field also must be
> changed. If the month is 12 (December) and the day is 31, then the
> value of the year field must also be changed. (Remember a year is a
> leap year if it is evenly divisible by 4 but not by 100 or it is
> evenly divisible by 400.) Finally, build a complete program that reads
> a particular date and prints the next date.

> HERE IS WHAT I HAVE DONE:
> #include <iostream.h>
> #include <iomanip.h>

>    struct DATE_1
>    {
>       int month;
>       int day;
>       int year;
>    };

>    void increment_date(DATE_1 &date)

> int main()
> {
>    DATE_1 date;

>    date.year;
>    date.day;
>    date.month;

>    switch(month)
>    {
>       case1: case 3: case 5: case 7: case 8: case 10: case 12:
>       {
>          if(date.day < 31)
>          {
>             date.day++;
>          }
>          else
>          {
>             date.day = 1;
>             date.month++;
>          }
>       }break;
>       case 4: case 6: case 9: case 11:
>       {
>          if(date.day < 30)
>          {
>             date.day++;
>          }
>          else
>          {
>             date.day = 1;
>             date.month++;
>          }
>       }break;
>       case 2:
>       {
>          if(((date.year % 4) == 0) && ((date.year % 100) != 0)
>          {
>             if((date.year % 400) == 400)
>          }
>          if(date.day < 28)
>          {
>             date.day++;
>          }
>          else
>          {
>             date.day = 1;
>             date.month++;
>          }
>       return 0;
> }

 
 
 

Need help with C++ Program

Post by Thomas Matthew » Fri, 02 May 2003 23:54:41



> HERE IS WHAT I HAVE TO DO:
> Define a structure called DATE with three fields, each of which is an
> integer: one for the month, one for the day and one for the year, and
> write a function called increment that accepts a date structure,
> increments the date by one day and returns the new date. If the date
> is the last day of the month, then the month field also must be
> changed. If the month is 12 (December) and the day is 31, then the
> value of the year field must also be changed. (Remember a year is a
> leap year if it is evenly divisible by 4 but not by 100 or it is
> evenly divisible by 400.) Finally, build a complete program that reads
> a particular date and prints the next date.

[code snipped]

By the way, the rule for leap years is not correct.


and you will find a plethera of information about calculating dates.

Sometimes there is more information than one wants to know. :-)

--
Thomas Matthews

C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq:   http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html

 
 
 

1. I NEED HELP IN C++ PROGRAM

HI, I am a high school student, and right now, I am doing a required extra
credit.--> oxymorons, required extra credit. anyway, I have to make a
connect four program in c++, with only apmatrix.h, and apstring, iostream,
stdlib, and no others. So if you would kindly gimme suggestions or programs,
thank you very much!!!

2. WTB Megahertz 14.4 Xjack modem

3. Beginner: Need Help with C++ program

4. Aweb3.3 workaround

5. Need help with C++ program

6. HEWLETT-PACKARD SECURITY BULLETIN: #00008

7. Help needed in Scottsdale - Mac help needed using C++

8. A Couple Tech Questions About Cellular Phones

9. Need Help on installing a printer driver on the local computer using c++ program

10. Student needing help in C++ winsock programming

11. Q: Help on graphical programming in C++ needed

12. URGENT: Help needed with visual C++ program 4 Windows