| | |
plase help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2008
Posts: 7
Reputation:
Solved Threads: 0
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.
please tell me what should i do to make it full program please help me. it is in C++.
thanks.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; void main () { string astring; int b; cout<<"enter the date in format dd-mm--yyyy"; cin>>astring; if (astring.at(2)==0) && (astring.at(3)==1) b=astring.at(0)*10+astring.at(1) else 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.
First you will need an int array that contains the cumulative number of days in each month. For example:
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.
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.
•
•
Join Date: Apr 2008
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
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.
•
•
•
•
A year is a leap year, if it is divisible by 4.
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.
All generalizations are wrong. Even this one.
![]() |
Similar Threads
- How to manage .edb files? (MS Access and FileMaker Pro)
- Hi first time to this site (Community Introductions)
- more information about python (Python)
- How to manage the .edb files (MySQL)
- convert .edb file to MySQ (Oracle)
- Windows 2000 server not allowing ASP access. (ASP)
- Can Some One Help Me To Unistall Xp (Windows NT / 2000 / XP)
- class polynomial (C++)
- Tracking cookie (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: C++ Programming problem
- Next Thread: Constructor overloading question
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






