![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 1
Rep Power: 0
![]() |
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, |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#3 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 3
![]() |
>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. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#5 |
|
Programmer
|
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| converting string to float | beginnerCCC | C | 22 | Oct 2nd, 2006 11:59 PM |
| [tutorial] Python for programming beginners | coldDeath | Python | 30 | Dec 14th, 2005 11:35 AM |
| Median/Mode in arrays? {Need help} | Java|Tera | Java | 27 | Nov 29th, 2005 10:50 AM |
| Getting Start Date of Week | Automatik | C# | 2 | Jul 20th, 2005 4:20 PM |