plase help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 7
Reputation: ar31an is an unknown quantity at this point 
Solved Threads: 0
ar31an ar31an is offline Offline
Newbie Poster

plase help

 
0
  #1
Apr 17th, 2008
Write a program that determines the day number (1 to 366) in a year for a date that is provided as input in the format dd-mm-yyyy. As an example, 01-01-2000 is day 1. 31-12-2001 is day 365. 31-12-2000 is day 366 because 2000 is the leap year. A year is a leap year, if it is divisible by 4. You may assume that user has entered input in correct format and that is a valid gate.

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void main ()
  6. {
  7. string astring;
  8. int b;
  9.  
  10. cout<<"enter the date in format dd-mm--yyyy";
  11. cin>>astring;
  12.  
  13. if (astring.at(2)==0) && (astring.at(3)==1)
  14. b=astring.at(0)*10+astring.at(1)
  15. else
  16. b=astring.at(0)*10+astring.at(1)



please tell me what should i do to make it full program please help me. it is in C++.

thanks.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,485
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: plase help

 
0
  #2
Apr 17th, 2008
First you will need an int array that contains the cumulative number of days in each month. For example:
int days[] = {0, 31, 59, ... };
Next chop up the string into its individual int elements.

Then determine if year is a leap year, if so then add one to days[2] (which is Feb) and each of the other days elements beyond 2.

Now for the actual calculation.
1. Find the number of days from 1 Jan to the start of the specified month. To do that subtract 1 from the month and then get the number of days in that month from the days[] array. Example: January = 1 - 1 and days[0] = 0, Feb = 2 - 1 and days[1] = 31 because there are 31 days between 1 January and 1 February.

2. Finally just add the spefied day to the above total.

If I enter a the date 1 Feb 2008 then first get days from 1 Jan to, but not including, 1 Feb, which is days[1]. If I enter 1 March 2008 then its days[2] = 59 (or 60 if a leap year).

If I enter 17 March 2008 then its days[2] = 59 + 17 = 76.
Last edited by Ancient Dragon; Apr 17th, 2008 at 10:36 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: ar31an is an unknown quantity at this point 
Solved Threads: 0
ar31an ar31an is offline Offline
Newbie Poster

Re: plase help

 
0
  #3
Apr 17th, 2008
Originally Posted by Ancient Dragon View Post
First you will need an int array that contains the cumulative number of days in each month. For example:
int days[] = {0, 31, 59, ... };
Next chop up the string into its individual int elements.

Then determine if year is a leap year, if so then add one to days[2] (which is Feb) and each of the other days elements beyond 2.

Now for the actual calculation.
1. Find the number of days from 1 Jan to the start of the specified month. To do that subtract 1 from the month and then get the number of days in that month from the days[] array. Example: January = 1 - 1 and days[0] = 0, Feb = 2 - 1 and days[1] = 31 because there are 31 days between 1 January and 1 February.

2. Finally just add the spefied day to the above total.

If I enter a the date 1 Feb 2008 then first get days from 1 Jan to, but not including, 1 Feb, which is days[1]. If I enter 1 March 2008 then its days[2] = 59 (or 60 if a leap year).

If I enter 17 March 2008 then its days[2] = 59 + 17 = 76.


thanks but can you please send me the edited code.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,485
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: plase help

 
0
  #4
Apr 17th, 2008
>>thanks but can you please send me the edited code.
Nope, try it and post what you have done so solve this yourself.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 248
Reputation: hammerhead is an unknown quantity at this point 
Solved Threads: 24
hammerhead's Avatar
hammerhead hammerhead is offline Offline
Posting Whiz in Training

Re: plase help

 
0
  #5
Apr 17th, 2008
A year is a leap year, if it is divisible by 4.
That is incorrect. Check this thread for determination of leap year
http://www.daniweb.com/forums/thread118753.html
There are 10 types of people in the world, those who understand binary and those who don't.

All generalizations are wrong. Even this one.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC