Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Date: 20 / 01 / 2014 PRACTICAL - 1

AIM WRITES A PROGRAM IN C/C++ TO FIND THE ROOTS OF A QUADRATIC EQUATION AND PERFORM THE
FOLLOWING ON IT: BOUNDARY VALUE ANALYSIS (BVA).

#include <bits/stdc++.h> using namespace std; int main() { //Variable Declaration char ans; string str1,str2,str3; int a,b,c,i=0; double discriminant; //Get The Input Value do { LOOP:cout<<"Enter The Value of 'A':\t"; cin>>str1; i=0; while(str1[i]) { if(isdigit(str1[i])) i++; else if(str1[i] == '-') { cout<<"Enter The Value In Range( 0<= A <=100 ):\n"; goto LOOP; } else { cout<<"Enter The Only Integer Value:\n"; goto LOOP; } } stringstream(str1)>>a; if(a>=0 && a<=100) { if(a == 0) cout<<"Equation Is Not Quadratic:\n"; else { LOOP1: cout<<"Enter The Value of 'B':\t"; cin>>str2; i=0; while(str2[i]) { if(isdigit(str2[i])) i++; else if(str2[i] == '-') { cout<<"Enter The Value In Range( 0<= B <=100 ):\n"; goto LOOP1; }
1

else { cout<<"Enter The Only Integer Value:\n"; goto LOOP1; } } stringstream(str2)>>b; if(b>=0 && b<=100) { LOOP2: cout<<"Enter The Value of 'C':\t"; cin>>str3; i=0; while(str3[i]) { if(isdigit(str3[i])) i++; else if(str3[i] == '-') { cout<<"Enter The Value In Range( 0<= C <=100 ):\n"; goto LOOP2; } else { cout<<"Enter The Only Integer Value:\n"; goto LOOP2; } } stringstream(str3)>>c; if(c>=0 && c<=100) { discriminant=((b*b) - 4 * a * c); if(discriminant == 0) cout<<"Roots Are Real And Equal:\n"; else if (discriminant <= 0) cout<<"Roots Are Imaginary:\n"; else cout<<"Roots Are Real And Distinct:\n"; } else { cout<<"Enter The Value In Range( 0<= C <=100 ):\n"; goto LOOP2; } } else { cout<<"Enter The Value In Range( 0<= B <=100 ):\n"; goto LOOP1; } } } else { cout<<"Enter The Value In Range( 0<= A <=100 ):\n"; goto LOOP;
2

} LOOP3:cout<<"Test for Another Test Cases:( Press 'Y' For Yes and 'N' for NO ):\t"; cin>>ans; if(!(ans == 'Y' || ans == 'N')) { cout<<"Enter Valid Value:\n"; goto LOOP3; } }while(ans == 'Y'); return 0; } OUTPUT SCREEN

You might also like