Thread: Date Program Help!!

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    2

    Exclamation Date Program Help!!

    Hi, im trying to make this program to this monday so i need your help rush plz!. First this program has 2 .cpp and 1 .h; the purpose of this program is to enter day,month and year using "Date.h and Date.cpp " from my professor. i have 2 problems first if you enter any month the program always says "11"; in the same way for year always says 2010. maybe is a small error but i can't see it thanks for all!

  2. #2
    Registered User
    Join Date
    Jun 2008
    Posts
    54
    The functions you've made to check the validity of date ranges have many errors in them and are the causes of your two (stated) problems. They also add unnecessary clutter to your class, and seem to be redundant since you perform similar checks (which are similarly broken) again right after you call them.

    As a specific example, the logic in the excerpt below is incorrect because it excludes the range of numbers between 1 and 12 as valid values. And you probably wanted to assign the result of checkMonth() to "this->month," not "this->day," though I recommend you remove those checking functions entirely and just do the checking in the setXXX functions.
    Code:
    void Date::setMonth(int tempMonth)
    {
    	this-> day = checkMonth(tempMonth); //checkmonth ?
    
    
    	if (tempMonth <1 || tempMonth >12)
    	{
    		month = tempMonth;
    	}
    	else
    		 throw invalidMonth ();
    
    
    
    }
    Try this instead:
    Code:
    if(tempMonth >= 1 && tempMonth <=12)
    The functions for the other parts of the date are broken in the same way.

    Your copy constructor could be deleted, since it isn't doing anything that the default copy constructor wouldn't (the compiler makes one for you if one is not supplied). Your copy assignment operator seems fine, though is probably also unnecessary - the only data members you have in the class are three integers.

    I'm guessing that the try-catch blocks and the operator overload functions have been mandated by your professor. You shouldn't use exception handling to do what you can do using local logic, but keep it in there if it's necessary to satisfy him.

    The friend operator overload functions seem to be functional (though they don't perform checking on date ranges as you have them):
    Code:
    Day/Month/Year: 1/21/2011
    La fecha es 21/1/2011
    La fecha es 21/1/2011
    Finally, in Date.h, please change your constructor declaration to something like:
    Code:
    Date(int m=11,int d=17,int y=2010);
    Last edited by Boxknife; 02-06-2011 at 01:46 AM.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    2
    Thanks!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  2. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

Tags for this Thread