Avatar of KalluMama
KalluMama

asked on 

Date constructor

when i initialize zot with this date: 10,9,2002...it only picks up the month...10...but gets junk for the rest ....why do u think that is the case??

Thanks!

=======================

Date::Date(int mon, int day, int year):julianDate(0)
{
      bool result;
      result = isValidDate(mon,day,year);
      if (result == 1)
      {
            month = mon;
            day = day;
            year = year;
      };
}

=====================

bool
Date::
isValidDate(int month, int day, int year)
{
      if (day < 1 || day > 31 || month < 1 || month > 12)
            return false;
      if (month == 2 && year%4 == 0 && day > 29)
            return false;
      if (month = 2 && year%4 != 0 && day > 28)
            return false;
      if (month == 4 || month == 6 || month == 9 || month == 11 && day > 30)
            return false;
      if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 && day > 31)
            return false;
      if (month = 0 && day == 0 && year == 0)
            return true;
      
      return true;
}

=====================

      cout << "\ninitialization constructor  Date zot(10,9,2002)";
      Date zot(10,9,2002);      // conversion constructor
      cout << endl
             << zot
             << " zot "
             << endl;

==========================
C++

Avatar of undefined
Last Comment
KalluMama
Avatar of avizit
avizit

I dont have a compiler to try out at the moment but btw your logic is a bit wrong

 if (month == 2 && year%4 == 0 && day > 29)
          return false;
     if (month = 2 && year%4 != 0 && day > 28)
          return false;


month == 2 and day > 29 is wrong whatever be the year .. no need for any check at all .
also btw feb , 1900 is of 28 days :) so check the actual condition ..

also you have have the day, month , years as unsigned int to be on safer side


ASKER CERTIFIED SOLUTION
Avatar of avizit
avizit

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of efn
efn

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of KalluMama
KalluMama

ASKER

Thanks guys...that really helped!!!
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo