c programs

Post on 05-Jul-2015

27 Views

Category:

Environment

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

it is and slide contains Save to your mobile device with our new app Don't have time to read now? Save SlideShares to read later or offline - anytime, anywhere. dding more information (description, tags, category) makes it easier for others to find your content. The score increases as you add each item.

TRANSCRIPT

Name : Ejaz khan

Roll no: 1120725

Section CO-5

Doc file is in office 365 it may behave

differently in older versions of ms office

SOFTWARE TESTING LAB

Program 1.

1. cyclometric complexity of a program(graph).

//cyclomatic complexity

#include<iostream>

using namespace std;

int main()

{

int i,j,v,val,edg, arr[50][50];;

cout<<" number of vertices";

cin>>v;

for(i=0;i<v;i++)

{

for(j=0;j<v;j++)

{

cin>>arr[i][j];

}

}

for(i=0;i<v;i++)

{

for(j=0;j<v;j++)

{

if(arr[i][j]==1)

{

edg++;

}

}

}

cout<<"Complexity is:"<<edg-v+2;}

program 2.

2. type of triangle given sides of triangle then perform

boundary case analysis :

//type of triangles and boundary value analysis

#include<iostream>

#include<conio.h> using namespace std;

void triangle (int a,int b,int c)

{ if((a<(b+c))&&(b<(a+c))&&(c<(a+b)))

{

if(a==b&&b==c) {

cout<<"Equilateral Triangle\n";

} else if ((a==b)||(a==c)||(b==c))

{

cout<<"Isosceles Triangle\n";

}

else {

cout<<"Scalene Triangle\n";

}

} else

{

cout<<"Not a Triangle\n"; }

} int main()

{

int x,y,z, no_of_test=0,i,j; cout<<"Enter the value of sides of triangle in the

range 1-100\n";

cin>>x>>y>>z; triangle (x,y,z);

no_of_test =4*3+1;

int min_range=1,max_range=100; int arr[4]={min_range,min_range+1,max_range-

1,max_range};

int mid=(max_range-min_range)/2; cout<<"No. of boundary cases = "<< no_of_test

<<endl;

for(i=0;i<3;i++) {

for(j=0;j<4;j++)

{ if(i==0)

{

cout<<arr[j] <<" "<<(max_range-min_range)/2<<"

"<<(max_range-min_range)/2<<endl; triangle (arr[j],mid,mid);}

else if(i==1)

{

cout<<(max_range-min_range)/2<<" "<<arr[j] <<" "<<(max_range-min_range)/2<<endl;

triangle (mid,arr[j],mid);}

else

{

cout<<(max_range-min_range)/2<<" "<< (max_range-min_range)/2<<" "<<arr[j]<<endl;

triangle (mid,mid,arr[j]);}

}

}

cout<<(max_range-min_range)/2<<" "<<(max_range-min_range)/2<<" "<<(max_range-min_range)/2<<endl;

triangle (mid,mid,mid);

getch(); }

Program 3.

3. type of triangle given sides of triangle and operate robustness testing :

//type of triangle using robustness testing analysis #include<iostream>

#include<conio.h>

using namespace std;

void triangle (int a,int b,int c) {

if((a<(b+c))&&(b<(a+c))&&(c<(a+b)))

{ if(a==b&&b==c)

{

cout<<"Equilateral Triangle\n"; }

else if ((a==b)||(a==c)||(b==c))

{

cout<<"Isosceles Triangle\n";

} else

{

cout<<"Scalene Triangle\n"; }

}

else {

cout<<"Not a Triangle\n";

}

}

int main() {

int x,y,z, no_of_test =0,i,j;

cout<<"Enter the value of sides of triangle in the

range 1-100\n"; cin>>x>>y>>z;

triangle (x,y,z);

no_of_test =6*3+1; int min_range=1,max_range=100;

int arr[4]={min_range,min_range+1,max_range-

1,max_range}; int mid=(max_range-min_range)/2;

cout<<"No. of boundary cases = "<< no_of_test

<<endl; for(i=0;i<3;i++)

{

for(j=0;j<6;j++) {

if(i==0) {cout<<arr[j] <<" "<<(max_range-

min_range)/2<<" "<<(max_range-min_range)/2<<endl; triangle (arr[j],mid,mid);}

else if(i==1) {cout<<(max_range-min_range)/2<<"

"<<arr[j] <<" "<<(max_range-min_range)/2<<endl;

triangle (mid,arr[j],mid);}

else { cout<<(max_range-min_range)/2<<"

"<< (max_range-min_range)/2<<" "<<arr[j]<<endl; triangle (mid,mid,arr[j]);}

}

}

cout<<(max_range-min_range)/2<<" "<<(max_range-

min_range)/2<<" "<<(max_range-min_range)/2<<endl;

triangle (mid,mid,mid); getch();

}

Program 4

4. find type of triangle and worst case testing : //type of triangle and Worst case analysis

#include<iostream>

#include<conio.h> #include<math.h>

using namespace std;

void triangle(int a,int b,int c) {

if((a<(b+c))&&(b<(a+c))&&(c<(a+b)))

{ if(a==b&&b==c)

{

cout<<"Equilateral Triangle\n"; }

else if ((a==b)||(a==c)||(b==c))

{

cout<<"Isosceles Triangle\n";

} else

{

cout<<"Scalene Triangle\n"; }

}

else {

cout<<"Not a Triangle\n";

}

}

int main()

{ int x,y,z, no_of_test =0,i,j,k;

cout<<"Enter the value of sides of triangle in the

range 1-100\n"; cin>>x>>y>>z;

triangle (x,y,z);

no_of_test =pow(5,3); int min_range=1,max_range=100;

int arr[4]={min_range,min_range+1,max_range-

1,max_range}; int mid=(max_range-min_range)/2;

cout<<"No. of boundary cases = "<< no_of_test endl;

for(i=0;i<5;i++)

{

for(j=0;j<5;j++) {

for(k=0;k<5;k++)

{ cout<<arr[i]<<” “<<arr[j]<<”

“<<arr[k]<<endl;

triangle (arr[i],arr[j],arr[k]); }}}

5. find next date and perform boundary case analysis :

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

using namespace std;

int leap_year_year(int y) {

if(y%400==0||(y%4==0 && y%100!=0))

return 1; else

return 0;

}

void next_date(int d,int m,int y)

{

int

mon1[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int

mon2[12]={31,28,31,30,31,30,31,31,30,31,30,31};

if(leap_year_year) {if(d==31&&m==12)

{

cout<<"1-01-"<<y+1<<endl; return;

}

else if(d==mon2[m-1])

{cout<<1<<"-"<<m+1<<"-"<<y<<endl;

return;

}

else

cout<<d+1<<"-"<<m<<"-"<<y<<endl; return;

}

else

{

if(d==31&&m==12)

{

cout<<"1-01-"<<y+1<<endl; return;

}

else if(d==mon1[m-1])

{cout<<1<<"-"<<m+1<<"-"<<y<<endl;

return;

}

else cout<<d+1<<"-"<<m<<"-"<<y<<endl;

return;

}

}

void next(int d,int m,int y) {

if(d<1) {cout<<"enter a valid date\n";

return;

} else if((d==29&&m==2)&& (!leap_year_year (y)))

{

cout<<"enter a valid date\n"; return;

}

else if(d>=29&&m==2) {

cout<<"enter a valid date\n";

return; }

else

if((d==31&&m==4)||(d==31&&m==6)||(d==31&&m==9)||(d==31&&m==11))

{

cout<<"enter a valid date\n"; return;

}

else if(d>31) { cout<<"enter a valid date\n";

return;

} else if(m<1||m>12)

{ cout<<"enter a valid date\n";

return;

}

next_date(d,m,y);

}

int main() {

int d,m,y,dd,mm,yy,i,j,k; int d1[4]={1,2,30,31};

int mid1=15,mid2=6,mid3=2500;

int m1[4]={1,2,11,12}; int y1[4]={1,2,4999,5000};

cout<<"enter a date:"; cin>>d>>m>>y;

next(d,m,y);

int total_cases=4*3+1; cout<<"No. of boundary cases = "<<total_cases<<endl;

for(i=0;i<3;i++)

{

for(j=0;j<4;j++) {

if(i==0) {cout<<d1[j] <<" "<<mid2<<"

"<<mid3<<" "; next(d1[j],mid2,mid3);}

else if(i==1) {cout<<mid1<<" "<<m1[j]<<"

"<<mid3<<" ";

next(mid1,m1[j],mid3);}

else { cout<<mid1<<" "<< mid2<<"

"<<y1[j]<<" "; next(mid1,mid2,y1[j]);}

}

}

cout<<mid1<<" "<<mid2<<" "<<mid3<<" ";

next(mid1,mid2,mid3); getch();

}

6. WAP to find next date and perform robustness

testing :

#include<iostream>

#include<conio.h> using namespace std;

int leap_year_year (int y) {

if(y%400==0||(y%4==0 && y%100!=0))

return 1;

else

return 0; }

void next_date(int d,int m,int y) {

int mon1[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int

mon2[12]={31,28,31,30,31,30,31,31,30,31,30,31}; if(leap_year_year (y))

{if(d==31&&m==12)

{ cout<<"1-01-"<<y+1<<endl;

return;

}

else if(d==mon2[m-1])

{cout<<1<<"-"<<m+1<<"-"<<y<<endl; return;

} else

cout<<d+1<<"-"<<m<<"-"<<y<<endl;

return; }

else

{

if(d==31&&m==12)

{ cout<<"1-01-"<<y+1<<endl;

return;

}

else if(d==mon1[m-1])

{cout<<1<<"-"<<m+1<<"-"<<y<<endl; return;

} else

cout<<d+1<<"-"<<m<<"-"<<y<<endl;

return; }

}

void next(int d,int m,int y)

{ if(y<0||y>5000)

{

cout<<"enter a valid date\n"; }

if(d<1)

{cout<<"enter a valid date\n"; return;

}

else if((d==29&&m==2)&& (!leap_year_year (y))) {

cout<<"enter a valid date\n";

return; }

else if(d>=29&&m==2)

{ cout<<"enter a valid date\n";

return;

} else

if((d==31&&m==4)||(d==31&&m==6)||(d==31&&m==9

)||(d==31&&m==11)) {

cout<<"enter a valid date\n";

return; }

else if(d>31)

{ cout<<"enter a valid date\n"; return;

} else if(m<1||m>12)

{ cout<<"enter a valid date\n";

return;

}

next_date(d,m,y);

}

int main() {

int d,m,y,dd,mm,yy,i,j,k; int d1[6]={0,1,2,30,31,32};

int mid1=15,mid2=6,mid3=2500;

int m1[6]={0,1,2,11,12,13}; int y1[6]={0,1,2,4999,5000,5001};

cout<<"enter a date:"; cin>>d>>m>>y;

next(d,m,y);

int total_cases=6*3+1; cout<<"No. of boundary cases = "<<total_cases<<endl;

for(i=0;i<3;i++)

{ for(j=0;j<6;j++)

{

if(i==0) {cout<<d1[j] <<" "<<mid2<<"

"<<mid3<<" "; next(d1[j],mid2,mid3);}

else if(i==1) {cout<<mid1<<" "<<m1[j]<<"

"<<mid3<<" ";

next(mid1,m1[j],mid3);}

else { cout<<mid1<<" "<< mid2<<"

"<<y1[j]<<" "; next(mid1,mid2,y1[j]);}

}

}

cout<<mid1<<" "<<mid2<<" "<<mid3<<" ";

next(mid1,mid2,mid3);

}

7. WAP to find next date and perform worst case

analysis : #include<iostream>

#include<conio.h>

using namespace std;

int leap_year(int y)

{ if(y%400==0||(y%4==0 && y%100!=0))

return 1;

else return 0;

}

void find_next(int d,int m,int y)

{

int mon1[12]={31,28,31,30,31,30,31,31,30,31,30,3

1};

int mon2[12]={31,28,31,30,31,30,31,31,30,31,30,31};

if(leap_year(y))

{if(d==31&&m==12) {

cout<<"1-01-"<<y+1<<endl;

return; }

else if(d==mon2[m-1]) {cout<<1<<"-"<<m+1<<"-"<<y<<endl;

return;

}

else

cout<<d+1<<"-"<<m<<"-"<<y<<endl; return;

}

else

{

if(d==31&&m==12)

{

cout<<"1-01-"<<y+1<<endl; return;

}

else if(d==mon1[m-1])

{cout<<1<<"-"<<m+1<<"-"<<y<<endl;

return;

}

else

cout<<d+1<<"-"<<m<<"-"<<y<<endl; return;

}

}

void next(int d,int m,int y) {

if(y<0&&y>5000) {

cout<<"enter a valid date";

return;

}

if(d<1) {cout<<"enter a valid date\n";

return;

} else if((d==29&&m==2)&& (!leap_year(y)))

{

cout<<"enter a valid date\n"; return;

}

else if(d>=29&&m==2)

{ cout<<"enter a valid date\n";

return;

} else

if((d==31&&m==4)||(d==31&&m==6)||(d==31&&m==9

)||(d==31&&m==11)) {

cout<<"enter a valid date\n";

return; }

else if(d>31)

{ cout<<"enter a valid date\n"; return;

} else if(m<1||m>12)

{ cout<<"enter a valid date\n";

return;

}

find_next(d,m,y);

}

int main()

{

int d,m,y,dd,mm,yy,i,j,k;

int d1[5]={1,2,15,30,31}; int mid1=15,mid2=6,mid3=2500;

int m1[5]={1,2,6,11,12};

int y1[5]={1,2,2500,4999,5000};

//cout<<"enter a date:";

//cin>>d>>m>>y; //next(d,m,y);

int total_cases=5*5*5;

cout<<"No. of boundary cases = "<<total_cases<<endl; for(i=0;i<5;i++)

{

for(j=0;j<5;j++) {

for(k=0;k<5;k++)

{ cout<<d1[i]<<"-"<<"-"<<m1[j]<<"-"<<y1[k]<<"

";

next(d1[i],m1[j],y1[k]); }

}

}

8. Check whether the given equation is quadratic and

also check the nature of its roots and preform worst case analysis: #include<iostream>

#include<conio.h> using namespace std;

void quad(int a, int b,int c) {

int d=b*b-4*a*c;

if(a==0)

{

cout<<"Given equation is not quadratic\n"; }

else {

if(d>=0)

{ if(d==0)

cout<<"Roots are real and equal ";

else cout<<"Root are real and distinct ";

float r1,r2; r1=(-b+sqrt(d))/(2*a);

r2=(-b-sqrt(d))/(2*a);

cout<<r1<<" "<<r2<<endl; }

else

cout<<”roots are imaginary\n”; }

}

int main()

{

int a,b,c,total_cases=0,i,j,k;

int min_range=1,max_range=100;

int mid=(max_range-min_range)/2;

int arr[5]={min_range,min_range+1,mid,max_range-1,max_range};

cout<<"enter coefficeint a,b,c of the quadratic equation"<<endl;

cin>>a>>b>>c;

check(a,b,c);

total_cases=5*5*5;

cout<<"No. of boundary cases = "<<total_cases<<endl;

for(i=0;i<5;i++) {

for(j=0;j<5;j++)

{ for(k=0;k<5;k++)

{

cout<<arr[i]<<" "<<arr[j]<<" "<<arr[k]<<" "; check(arr[i],arr[j],arr[k]);

}

}

}

}

top related