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

Consider the following program which classifies triangles as one of a scalene, i

ID: 671835 • Letter: C

Question

Consider the following program which classifies triangles as one of a scalene, isosceles, right or equilateral triangle and computes its area. Suppose it is initially tested using the first 4 test cases provided in the following table. T5 is added to the test case and program incorrectly computes the area. Debugging reveals an error in Statement 11. It uses expression a*2 instead of a*a. Suppose the fault is corrected and new program must be rerun to verify that it produces the correct output. Recommend a regression test case to reevaluate the program.

Program Code:

S1: read (a, b, c);
S2: class = scalene;
S3: if a=b or b=a
S4:    class=isosceles;
S5: if a*a=b*b + c*c
S6:    class=right;
S7: if a=b=c
S8   class= equilateral
S9: case class of
S10: right: area=b*c/2
S11: equilateral: area= a*2*sqrt(3)/4;
S12: otherwise: s= (a+b+c)/2;
S13:   area= sqrt(s*(s-a)*(s-b)*(s-c));
end;
S14: write (class, area)

Test Cases:

Test Case Input Output a b c Class Area T1 2 2 2 Equi 1.73 T2 4 4 3 Isosceles 5.56 T3 5 4 3 Right 6.00 T4 6 5 4 Scalene 9.92 T5 3 3 3 Equi 2.60 (error)

Explanation / Answer

#include <stdio.h>
#include<math.h>


int main() {
double a,b,c;
printf("Enter all sides of the triangle: ");

scanf("%lf",&a);

scanf("%lf",&b);

scanf("%lf",&c);

int flag=3;//three denote scalene
if(a==b&&b==c){
flag=1;//equilateral
}else if(a==b||a==c||b==c){
flag=2;//isosceles
}else{
flag=3;//scalene
}
if(a*a==b*b+c*c){
flag=4;//right angle triangle
}
double area,s;
if(flag==1){
area=a*a;

area=area*(sqrt(3)/4.00);
printf("Area of given equilateral triangle: %.2lf",area);
}else if(flag==4){
area=(b*c)/2.00;
printf("Area of given right triangle: %.2lf",area);
}else{
s=a+b+c;
s=s/2.00;
area=sqrt(s*(s-a)*(s-b)*(s-c));
if(flag==2){
printf("Area of given isosceles triangle: %.2lf",area);
}else{
printf("Area of given scalene triangle: %.2lf",area);
}
}
}