Boundary Value Analysis : Nature of Roots of a Quadratic equation | C ++ program to check the nature of the roots ; BVA for nature of roots of a quadratic equation ; If a = 0 , D / 2 a will yield exception Hence it is not a valid Quadratic Equation ; If D > 0 , it will be Real Roots ; If D == 0 , it will be Equal Roots ; If D < 0 , it will be Imaginary Roots ; Function to check for all testcases ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void nature_of_roots ( int a , int b , int c ) { if ( a == 0 ) { cout << " Not ▁ a ▁ Quadratic ▁ Equation " << endl ; return ; } int D = b * b - 4 * a * c ; if ( D > 0 ) { cout << " Real ▁ Roots " << endl ; } else if ( D == 0 ) { cout << " Equal ▁ Roots " << endl ; } else { cout << " Imaginary ▁ Roots " << endl ; } } void checkForAllTestCase ( ) { cout << " Testcase " << " TABSYMBOL a TABSYMBOL b TABSYMBOL c TABSYMBOL Actual ▁ Output " << endl ; cout << endl ; int a , b , c ; int testcase = 1 ; while ( testcase <= 13 ) { if ( testcase == 1 ) { a = 0 ; b = 50 ; c = 50 ; } else if ( testcase == 2 ) { a = 1 ; b = 50 ; c = 50 ; } else if ( testcase == 3 ) { a = 50 ; b = 50 ; c = 50 ; } else if ( testcase == 4 ) { a = 99 ; b = 50 ; c = 50 ; } else if ( testcase == 5 ) { a = 100 ; b = 50 ; c = 50 ; } else if ( testcase == 6 ) { a = 50 ; b = 0 ; c = 50 ; } else if ( testcase == 7 ) { a = 50 ; b = 1 ; c = 50 ; } else if ( testcase == 8 ) { a = 50 ; b = 99 ; c = 50 ; } else if ( testcase == 9 ) { a = 50 ; b = 100 ; c = 50 ; } else if ( testcase == 10 ) { a = 50 ; b = 50 ; c = 0 ; } else if ( testcase == 11 ) { a = 50 ; b = 50 ; c = 1 ; } else if ( testcase == 12 ) { a = 50 ; b = 50 ; c = 99 ; } else if ( testcase == 13 ) { a = 50 ; b = 50 ; c = 100 ; } cout << " TABSYMBOL " << testcase << " TABSYMBOL " << a << " TABSYMBOL " << b << " TABSYMBOL " << c << " TABSYMBOL " ; nature_of_roots ( a , b , c ) ; cout << endl ; testcase ++ ; } } int main ( ) { checkForAllTestCase ( ) ; return 0 ; }