A quadratic equation a(x2)+bx+c=0 with input as three positive integers a, b, c having values ranging from an interval [0,100].
Objective of this Tutorial: There are two objectives of the tutorial like:
Objective –1: To write a Program in C++ for the determining the nature of roots of the above quadratic equation. The program output may have one of the following words:
"Not a Quadratic Equation", "Real Roots", "Imaginary Roots" or "Roots are Equal"
Objective –2: Boundary Value Testing by designing Test Cases which would use input variables at their Minimum Values, Just above Minimum Values, at Nominal Value, Just below Maximum and Minimum Values.
Solution Part – 1: Program in C++
#include #include void main( ) { clrscr( ); int a,b,c,d; cout<<"The quadratic equation is of the type a(x2)+bx+c=0"<cout<<"Enter the value of a:"<cin>>a; cout<<"Enter the value of b:"<cin>>b; cout<<"Enter the value of c: "<cin>>c; d = (b*b)-4*a*c; if((a<0)||(b<0)||(c<0)||(a>100)||(b>100)||(c>100)) cout«"Invalid input"«end1; elseif(a==0) cout<<"Not a quadratic equation"<elseif(d==0) cout<<"Roots are equal"<else if(d<0) cout<<"Imaginary roots"<else cout<<"Real roots"<getch(); }
Solution Part – 2: Design Boundary Value Test Cases
In the above program, we consider the values as 0 (Minimum), 1 (Just above Minimum), 50 (Nominal), 99 (Just below Maximum) and 100 (Maximum)
Test Case ID
a
b
c
Expected Output
1
50
50
0
Real Roots
2
50
50
1
Real Roots
3
50
50
50
Imaginary Roots
4
50
50
99
Imaginary Roots
5
50
50
100
Imaginary Roots
6
50
0
50
Imaginary Roots
7
50
1
50
Imaginary Roots
8
50
99
50
Imaginary Roots
9
50
100
50
Equal Roots
10
0
50
50
Not a Quadratic Equation
11
1
50
50
Real Roots
12
99
50
50
Imaginary Roots
13
100
50
50
Imaginary Roots
Some of the screenshots with different outputs are as under:
1) Screenshot with Output as " Imaginary Roots" is as under
2) Screenshot with Output as "Real Roots" is as under
3) Screenshot with Output as "Roots are Equal" is as under
4) Screenshot with Output as "Not a Quadratic Equation" is as under
Comments :
# 1 Garrett on 2012-10-10 06:21:55
which i am going to convey in school.
Leave Your Comments: (*) Marked Fields are Mandatory
You can apply basic formatting to the text