C++ program to calculate tomorrow’s date

Q. How do I write C++ program that calculate tomorrow’s date? For example user input a date 30/03/2007, then it should print 31/03/2007. Your program must take care of following issues:
=> Leap year
=> Validate date for month, day etc
=> Change of date/month/year should be handled properly.

A:

Source code : tdate.cpp

Compile and execute code

To compile code under UNIX/Linux, enter:
$ make tdate
OR
$ g++ -o tdate tdate.cpp

To execute code under Linux/UNIX, enter:
$ ./tdate

A note for TC++ 3.0 (DOS version) users

Replace line
#include<iostream>
With
#include<iostream.h>
Save the file and compile/run code from menu.

Please note that above code should work with another compiler (such as VC++) without modification.

Download source code

Click here to download source code.

Author: admin

I like chocolate, gadgets, open source software, photography, traveling and all shades of green colors. I love spending time with fun loving friends and family members. This is my own online journal.

13 thoughts on “C++ program to calculate tomorrow’s date”

  1. How do I write C++ program that tells the day of entered date? For example user input a date 20/08/2008, then it should print the day(in string)like the day on that date is Wednesday.
    As user input any date it tells the current day on that date.(the name of the day should be in character)

  2. I need a function that advances any given date by one day. It is very similar your program. Where is your header file though? Regards!

  3. hi, i am gpradeepkumar. I like the way u answer the questions asked by the visitors of ur site. So please helpme in creating my own blog and the requirements that should be according to google about the site map generator .How to generate the sitemap , how to upload the sitemap ,how to submit the sitemap and how to add google adsense to my site.please give information about the above things.
    I will be very thankful to you

  4. how do i write a programme to calculate certain formula,but if user’s input are not integers (i.e characters), then a message of ‘invalid data’ displayed??

  5. This code has a bug.
    tomorrow() function does not check leap year.

    also the leap year detection function seems peculiar.

  6. How to write your program in “printf, scanf ” replace “cerr ????? please answer me

  7. How do I write C++ program using string that tells the day of entered date? For example user input a date 20/08/2008, then it should print the day like the day on that date is Wednesday.

  8. Why one should write a program? Doesnt C/C++ development systems have readily available function for carrying out date arithmatic? Many O/ses, developemt systems have such funtions available.

Leave a Reply

Your email address will not be published. Required fields are marked *