To understand the question....

This is a discussion on To understand the question.... within the C++ Programming forums, part of the General Programming Boards category; Code: class Date { //data public: Date(int =1,int=1,int=1900);//default constructor Date &setDate(int,int,int); Date &setMonth(int); //set month Date &setDay(int); //set day Date ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    5

    To understand the question....

    Code:
    class Date
    { //data
    public:
    	Date(int =1,int=1,int=1900);//default constructor
    	
    	Date &setDate(int,int,int);		
    	Date &setMonth(int); //set month
    	Date &setDay(int); //set day
    	Date &setYear(int); //set year
    
    	int getMonth() const;
    	int getDay() const;
    	int getYear() const;
    	void print() const;  
    	
    
    protected:
    	int month;
    	int day;
    	int year;
    
    	
    
      //data
    
    };
    	
    ///////////////////////////////////////////////////////////////////////////
    
    	// Date constructor with range checking
    	Date::Date(int m, int d, int y)	
    	{
    		month= (m > 0 && m<=12)? m:1;
    		day=(d>=1 && y<=31)?y:1; 
    		year=(y>=1900 && y <2500)? y:1900;
    	}
    	
    	
    	
    	Date &Date::setDate(int m,int d,int y)
    	{
    		month= (m > 0 && m<=12)? m:1;
    		day=(d>=1 && d<=31)?d:1; 
    		year=(y>=1900 && y <2500)? y: 1900;
    		return *this;
    	}
    
    	//Set function
    	Date &Date::setMonth(int m)
    	{
    		month=(m > 0 && m<=12)? m:1;
    		return *this; //enables chaining
    	}
    
    	Date &Date::setDay(int d)
    	{
    		day=(d>=1 && d<=31)?d:1; 
    		return *this; //enables chaining
    	}
    
    	Date &Date::setYear(int y)
    	{
    		year=(y>=1900 && y <2500)? y: 1900;
    		return *this; //enables chaining
    	}
    
    	//Get function
    	int Date::getMonth() const
    	{ return month; }
    
    	int Date::getDay() const
    	{ return day;}
    
    	int Date::getYear() const
    	{ return year;}
    
    	//Display print function
    	void Date::print() const
    	{
    		cout<<month<<" "<< day<<" " << year<<"\n";
    	}
    
    //Just give me brief explaination and ideas.. to do.these .Thanks	
    //A method that takes two dates as arguments
    //and return true(or 1)provided the first date
    //occurs before the second date else return false(or 0)
    
    	//class earlier:public Date
    	//just tell me what should i do ? 
                   //do i need to get user keyin for two dates?
    	
    //A method  Christmas which given a date, should return 
    //the number of days until the next Christmas day(December,25)
    	
    	
    	//class christmas:public Date
    	//just tell me what should i do?
    
    //Given two date,return no. of days between the given two dates.
    //For e.g. daysBetween(Date(12,4,1970),Date(22,4,1970) is 10.
    //The program should cope with dates having different months.
    	
    	
    	//class Compare:public Date
    	//just tell me what should i do...?
    //////////////////////////////////////////////////////////////////	
    main()
    {
    	 Date d1;
    	 d1.setMonth(07).setDay(27).setYear(1982);
    	 cout<<"Henry Birthday: ";
    	 d1.print();
    	 
    		 return 0;
    }

    Please use [code][/code]Tags

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Check here.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21