The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 3 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Given below are parts of the code segment actually written by two students for date validation. The two student used two different approaches as given in the code segments 6a and 6b. Which of these two would you think is easier from a white box testing discussed in this chapter would be most relevant to apply for 6a and which for 6b? How would you improve the effectiveness of the code in terms of susceptibility to defects in either case and ability to detect defects more easily?
6a.
//Code for Validation A????1 Problem 6 A????1 Segment 6a
int month_days [13] = {0, 31, 28, 31, 30, 31, 30, 31,
                                                31, 30, 31, 30, 31 };
valid = TRUE;
if (is_leap-year(yy))
                month_days [2] = 29;
if (mm < 1 !! mm > 12) valid = FALSE;
else
                if (day < 1 !! day> month(month_legth[month])
                valid = FALSE;
                else if (year < 1)
                valid = FALSE;
return (VALID);
/* In the above, the function is_leap-year is defined as follows */
int is_year-year (int year)
                {
                int result;
                if ((year%4) != 0 ) result = FALSE;
                else (if (( year %400) == 0) result = TRUE;
                                else if ((year %100) == 0) result = FALSE;
                return (result);
}
6b.
// CODE FOR DATE VALIDATION-PROBLEM 6-SEGMENT 6b
if (!(dd > 0 && dd < 32))
     printf ("enter a number between 1 and 32 only\n");
     return (1);
if ((mm=4) !! (mm==6) !! (mm==9) !! (mm==11) && day> 30)
{
     printf ("invalid date; maximum days should be 30");
}
if ((1=(year%100!=0) && (year%4==0) !! (year%400==0)))
           &&       (day<=29)) !!
                                         (day < 29))
     {
       printf ("valid date \n")
               return (0);
     }
    Â
else
     {
       printf("invalid date\n");
             return (1);
     }
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll