Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   caluculate day of week given present date and number of days (http://www.programmingforums.org/showthread.php?t=11790)

srinivasc_it Nov 2nd, 2006 11:05 PM

caluculate day of week given present date and number of days
 
Hi,

I need to write a function in c++ that calculates expiry date of inventory, based on received date and warranty period.

so inputs to function are:-
Date recieved = "10/31/2005" (string)
Warranty period (num of days)= 30 (long)

so output should be "11/29/2005" (string)

i.e "10/31/2005" + 30 days = "11/29/2005"
similarly, 12/31/2005 + 7 days = 01/06/2006
09/11/2005 + 30 days = 10/10/2005
10/31/2005 + 90 days = 01/28/2006


string calculate_expiry_date(string date_recieved, long warranty_period)
{
string date_expire;


return date_expire;
}

Can any one please tell me the logic, are direct me to a web link, were I can find code for this logic from scratch in c++, C or Java or any other link that helps me to develop this.

Are there any c++ libraries available for this caluculation?

Thanks,

mrynit Nov 2nd, 2006 11:11 PM

1. you have to break the expire string into month/day/year

2. added the Warranty period in days.

3. calculated the proper month/day/year based on the calander formula.

4. return new data as string

Narue Nov 3rd, 2006 8:19 AM

>Are there any c++ libraries available for this caluculation?
The ctime header has functions and types that will do what you want.

bl00dninja Nov 4th, 2006 3:06 AM

if you like math, think about congruency (modulo-arithmetic).

Iftikhar Nov 4th, 2006 5:54 AM

There are several other ways to pass input a date in function. There are also structures for date time in C/C++, and doing mathematics with them is easy. Still If you want to continue with the date input as string in functions then you have to carry on the following steps
1. loop through date string until '\' is encountered and save it to another string say s_day chracter by chracter. When \ set null at end.
2. Convert it into an interger by using atoi() function.
3. Similary continue scaning the string and putting month and year in seperate strings and converting them to integers. Now do mathematics with them and convert them again insto string


All times are GMT -5. The time now is 1:13 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC