Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 2nd, 2006, 11:05 PM   #1
srinivasc_it
Newbie
 
Join Date: Nov 2006
Posts: 1
Rep Power: 0 srinivasc_it is on a distinguished road
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,
srinivasc_it is offline   Reply With Quote
Old Nov 2nd, 2006, 11:11 PM   #2
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 343
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
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
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Nov 3rd, 2006, 8:19 AM   #3
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
>Are there any c++ libraries available for this caluculation?
The ctime header has functions and types that will do what you want.
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Old Nov 4th, 2006, 3:06 AM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
if you like math, think about congruency (modulo-arithmetic).
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Nov 4th, 2006, 5:54 AM   #5
Iftikhar
Programmer
 
Iftikhar's Avatar
 
Join Date: Oct 2006
Location: London
Posts: 40
Rep Power: 0 Iftikhar is on a distinguished road
Send a message via MSN to Iftikhar
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
__________________
Iftikhar Ahmed Khan
For doing an experiment on programmer's mood please visit http://uxisfyp1.brunel.ac.uk/cspgiak
Iftikhar is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
converting string to float beginnerCCC C 22 Oct 3rd, 2006 12:59 AM
[tutorial] Python for programming beginners coldDeath Python 30 Dec 14th, 2005 12:35 PM
Median/Mode in arrays? {Need help} Java|Tera Java 27 Nov 29th, 2005 11:50 AM
Getting Start Date of Week Automatik C# 2 Jul 20th, 2005 5:20 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:33 PM.

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