Printing the date from starting date to ending date

Discussion in 'C++' started by bashamsc, Apr 18, 2008.

  1. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai

    Printing the date from starting date to ending date



    The program takes the starting date and ending date as inputs and prints the dates in between them.This program is useful if u r dealing with dates.

    The code



    I have used four date functions i.e date1() , date2() , date3() , date4(). When the starting year and ending year is same it performs date1() function.If the month is equal to starting month then it performs date2() function.If the month is equal to ending month it performs date3() function.If the year is in between starting and ending year then it performs date4() function.

    Code:
    
    #include<iostream>
    using namespace std;
    
    int date1(int , int , int , int , int , int);
    
    int date2(int , int , int , int );
    
    int date3(int , int , int , int );
    
    int date4(int , int );
    
    main()
    {
    	
    	cout<<"Enter the starting date, month and year"<<endl;
    	
    	int sd,sm,sy,ed,em,ey;
    	
    	cin>>sd>>sm>>sy;
    	
    	cout<<"Enter the ending date, month and year"<<endl;
    	
    	cin>>ed>>em>>ey;
    	
    	int i,j,k=0,n,m;
    	
    	n = ey - sy;
    	
    	m=sm-em;
    	
    	if(sy>ey)
    	{
    		cout<<"Starting year cannot be greater than ending year"<<endl;
    		exit(1);
    	}
    	if(n==0&&sm>em)
    	{
    		cout<<"Date entered is wrong"<<endl;
    		exit(1);
    	}
    	
    	if(n==0&&sm>em&&sd>ed)
    	{
    		cout<<"Date entered is wrong"<<endl;
    		exit(1);
    	}
    	
    	if(n==0&&sm==em&&sd>ed)
    	{
    		cout<<"Date entered is wrong"<<endl;
    		exit(1);
    	}
    	
    	if(n==0&&m==0)
    	{
    		cout<<"Month "<<sm<<" Year "<<sy<<endl;
    		for(j=sd;j<=ed;j++)
    			cout<<j<<" "<<endl;
    		exit(1);
    	}
    	
    	if(n==0&&m==0&&sd==ed)
    	{
    		cout<<"Month "<<sm<<" Year "<<sy<<endl;
    		cout<<j<<" "<<endl;
    		exit(1);
    	}
    	
    	if(n==0&&m!=0)
    	{
    		for(j=sm;j<=em;j++)
    		{
    			date1(j,sy,sm,em,sd,ed);
    		}
    	}
    	
    	else
    	{//2
    		
    		for(i=0;i<=n;i++)
    		{//3
    			
    			if(i==0)
    			{
    				for(j=sm;j<=12;j++)
    					date2(j,sy,sm,sd);
    			}
    			
    			if(i==n)
    			{
    				for(j=1;j<=em;j++)
    					date3(j,ey,em,ed);
    			}
    			
    			if(i!=0&&i!=n)
    			{
    				for(j=1;j<=12;j++)
    					date4(j,k);
    			}
    			
    			k=sy+1;
    			
    		}//3
    		
    	}//2
    	
    }//1
    
    int date1(int a , int sy , int sm , int em , int sd , int ed )
    {//
    	//cout<<"1"<<endl;
    	int i;
    	if(a==2&&sy%4==0&&(a==sm||a==em))
    	{//1
    		
    		cout<<"Month  "<<a<<" Year  "<<sy<<endl;
    		if(a==sm)
    		{
    			for(i=sd;i<=29;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    		if(a==em)
    		{
    			for(i=1;i<=ed;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    	}//1
    	
    	if(a==2&&sy%4==0&&a!=sm&&a!=em)
    	{
    		cout<<"Month  "<<a<<" Year  "<<sy<<endl;
    		
    		for(i=1;i<=29;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a==2&&sy%4!=0&&(a==sm||a==em))
    	{//2
    		
    		cout<<"Month  "<<a<<" Year  "<<sy<<endl;
    		if(a==sm)
    		{
    			for(i=sd;i<=28;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    		if(a==em)
    		{
    			for(i=1;i<=ed;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    	}//2
    	
    	if(a==2&&sy%4!=0&&a!=sm&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=1;i<=28;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2==0&&(a==sm||a==em))
    	{//3
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		if(a==sm)
    		{
    			for(i=sd;i<=30;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    		if(a==em)
    		{
    			for(i=1;i<=ed;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    	}//3
    	
    	if(a<8&&a!=2&&a%2!=0&&(a==sm||a==em))
    	{//4
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		if(a==sm)
    		{
    			for(i=sd;i<=31;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    		if(a==em)
    		{
    			for(i=1;i<=ed;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    	}//4
    	
    	if(a<8&&a!=2&&a%2==0&&a!=sm&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		for(i=1;i<=30;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2!=0&&a!=sm&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=1;i<=31;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2==0&&(a==sm||a==em))
    	{//5
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		if(a==sm)
    		{
    			for(i=sd;i<=31;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    		if(a==em)
    		{
    			for(i=1;i<=ed;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    	}//5
    	
    	if(a>=8&&a!=2&&a%2!=0&&(a==sm||a==em))
    	{//6
    		
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		if(a==sm)
    		{
    			for(i=sd;i<=30;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    		if(a==em)
    		{
    			for(i=1;i<=ed;i++)
    				cout<<i<<" ";
    			cout<<endl;
    		}
    		
    	}//6
    	
    	if(a>=8&&a!=2&&a%2==0&&a!=sm&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=1;i<=31;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2!=0&&a!=sm&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=1;i<=30;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    }//
    
    int date2(int a , int sy , int sm , int sd )
    {//
    	//cout<<"2"<<endl;
    	int i;
    	if(a==2&&sy%4==0&&a==sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=sd;i<=29;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a==2&&sy%4==0&&a!=sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=1;i<=29;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a==2&&sy%4!=0&&a==sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=sd;i<=28;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a==2&&sy%4!=0&&a!=sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=1;i<=28;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2==0&&a==sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=sd;i<=30;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2==0&&a!=sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=1;i<=30;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2!=0&&a==sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=sd;i<=31;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2!=0&&a!=sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=1;i<=31;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2==0&&a==sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=sd;i<=31;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2==0&&a!=sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=1;i<=31;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2!=0&&a==sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=sd;i<=30;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2!=0&&a!=sm)
    	{
    		cout<<"Month  "<<a<<"Year  "<<sy<<endl;
    		
    		for(i=1;i<=30;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    }//
    
    int date3(int a , int ey , int em , int ed )
    {//
    	//cout<<"3"<<endl;
    	int i;
    	if(a==2&&ey%4==0&&a==em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=ed;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a==2&&ey%4==0&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=29;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a==2&&ey%4!=0&&a==em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=ed;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a==2&&ey%4!=0&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=28;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2==0&&a==em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=ed;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2==0&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=30;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2!=0&&a==em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=ed;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2!=0&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=31;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2==0&&a==em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=ed;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2==0&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=31;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2!=0&&a==em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=ed;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2!=0&&a!=em)
    	{
    		cout<<"Month  "<<a<<"Year  "<<ey<<endl;
    		
    		for(i=1;i<=30;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    }
    
    int date4(int a , int b )
    {//
    	//cout<<"4"<<endl;
    	int i;
    	if(a==2&&b%4==0)
    	{
    		cout<<"Month  "<<a<<"Year  "<<b<<endl;
    		
    		for(i=1;i<=29;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a==2&&b%4!=0)
    	{
    		cout<<"Month  "<<a<<"Year  "<<b<<endl;
    		
    		for(i=1;i<=28;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2==0)
    	{
    		cout<<"Month  "<<a<<"Year  "<<b<<endl;
    		
    		for(i=1;i<=30;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a<8&&a!=2&&a%2!=0)
    	{
    		cout<<"Month  "<<a<<"Year  "<<b<<endl;
    		
    		for(i=1;i<=31;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2==0)
    	{
    		cout<<"Month  "<<a<<"Year  "<<b<<endl;
    		
    		for(i=1;i<=31;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    	if(a>=8&&a!=2&&a%2!=0)
    	{
    		cout<<"Month  "<<a<<"Year  "<<b<<endl;
    		
    		for(i=1;i<=30;i++)
    			cout<<i<<" ";
    		cout<<endl;
    	}
    	
    }//
    
    
    After entering the starting date and ending date the program checks whether the dates are valid or not.
     
  2. GAURAV SABOO

    GAURAV SABOO New Member

    Joined:
    Apr 13, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    cant i do it in some easy way.if yas then do it ina easy way
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
  4. GAURAV SABOO

    GAURAV SABOO New Member

    Joined:
    Apr 13, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    no response have been given from your side
    please do it in an easy wayin c.its urgent.i am trying this but i cant do it.so please do it and post it to my email id
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Can you please be specific as to what you mean by easy because what could be easy for you could be tough for me and its all relative.
     
  6. GAURAV SABOO

    GAURAV SABOO New Member

    Joined:
    Apr 13, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    as you have done it in c++ language and i only know c language so i cant understand that solution.so if you will do the solution of that problem iin c language then i will be able to understand that.
     
  7. imrantechi

    imrantechi New Member

    Joined:
    Feb 12, 2008
    Messages:
    116
    Likes Received:
    4
    Trophy Points:
    0

    Whatever in post.. It's only in C. Can you read article once more time? there is no code of c++ in this article.
    Please atleast read article and then comment.
     
  8. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai
    Hi gaurav i have written another method for printing the date check it.

    u can implement this program in c also.First read whole article and understand logic behind the program and try to implement ur own logic for that.
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice