Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given below are parts of the code segment actually written by two students for d

ID: 639609 • Letter: G

Question

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

Explanation / Answer


#include <iostream.h>
#include <conio.h>


int main()
{

int day,dd,mm,yy,num;
char ans;
clrscr();

do{
cout<<"Enter Month: ";
cin>> mm;

}while (mm<1||mm>12);

do{
cout<<"Enter Day: ";
cin>> dd;

}while (dd<1||dd>31);

do{
cout<<"Enter Year: ";
cin>> yy;
}while (yy<1||yy==num);



// validation

switch (mm){
case 1: if (1,3,5,7,8,10,12);
day=31;
break;
case 2: if (4,6,9,11);
day=30;
break;
case 3 :
if(((yy%4==0)&&(yy%100!=0))||(yy%400==0))
day=29;
else
day=28;

}


if (dd, mm, yy)
cout<<"The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is VALID!"<<endl;
else
cout<< "The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is INVALID!"<<endl;

do{
cout<<"do you want to try again?? (Y/N) "<<endl;
cin>>ans;
} while (ans!='n'&&ans!='N');



return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote