Question

Consider the following program which classifies triangles as one of a scalene, isosceles, right or equilateral...

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)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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


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

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);
}
}
}

Add a comment
Know the answer?
Add Answer to:
Consider the following program which classifies triangles as one of a scalene, isosceles, right or equilateral...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Your math professor asked you to determine whether triangles are equilateral, isosceles, or scalene triangles. You...

    Your math professor asked you to determine whether triangles are equilateral, isosceles, or scalene triangles. You need to write a MATLAB program that accepts the side lengths for sides A, B, and C of a triangle and compares the side lengths in order to determine if the triangle is equilateral, isosceles, or scalene. Each triangle will only be classified as a single type based on the definitions below: 1. An equilateral triangle is a triangle in which all three sides...

  • Consider again the triangle classification program with a slightly different specification: The program reads floating values...

    Consider again the triangle classification program with a slightly different specification: The program reads floating values from the standard input. The three values A, B, and C are interpreted as representing the lengths of the sides of a triangle. The program then prints a message to the standard output that states whether the triangle, if it can be formed, is scalene, isosceles, equilateral, or right angled. Determine the following for the above program: Part a: For the boundary condition A+B>Ccase...

  • ***IN PYTHON: Scalene triangle: All sides have different lengths Isosceles triangle: Two sides have the same...

    ***IN PYTHON: Scalene triangle: All sides have different lengths Isosceles triangle: Two sides have the same length Equilateral triangle: All sides are equal Write a program to ask for the length of 3 sides a, b and c. Ask for three sides at a time Determine the type of triangle given three sides Handle all kinds of errors - 1. not integers, int() conversion fails 2. not enough args, 3. too many arguments HINT: use the len() function to check...

  • In 1 to 5 please circle one choice from the ( ) and explain the statement...

    In 1 to 5 please circle one choice from the ( ) and explain the statement in your own words and add your definition of the item discussed. White box testing is done while (coding, compiling, running) Equivalence class testing is (domain-based, range-based) Verification is done in (specification, implementation) Great testers focus on (finding the incident, finding the failure) a b c Expected 5 5 5 Equilateral 2 2 3 Isosceles 3 4 5 Scalene 4 1 2 Not a...

  • Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3:...

    Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3: 5 Enter the base: 5 Enter the height: 8 --------------------- The triangle is Isosceles since it has two equal length sides. Isosceles triangle also has two equal angles The area is: 20 The permimeter is: 13 Continue? (y/n): y Enter length 1: 10 Enter length 2: 10 Enter length 3: 10 Enter the base: 10 Enter the height: 7 --------------------- The triangle is Equilateral...

  • PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP...

    PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP AND FORMAT: #include <iostream> using namespace std; int main() { //variables here    do { // program here             }while (true);    } Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++.program to have a user input the length of three sides of a triangle. Allow the user to enter the sides...

  • help im alittle lost my teacher posted all this its suppose to be in C++ language....

    help im alittle lost my teacher posted all this its suppose to be in C++ language. can yoh leave comments ans type the code thank you Write a C++ program that accepts the lengths of three sides (a,b,c) of a triangle as input from the user Validate the user input, so that sides a, b, c can only be POSITIVE. The program output should indicate whether or not the triangle is an Equilateral Triangle, a Right Triangle, Isosceles which is...

  • Question 1: Consider the following specification for a program. The program reads two inputs from the...

    Question 1: Consider the following specification for a program. The program reads two inputs from the user: a string s and an integer number n. The program concatenates s with itself n-1 times, if the following conditions are satisfied: 1- s consists of 3 characters. 2- The first character in s is a letter. 3- s consists of letters (A-Z a-z) and digits only (0-9) 4-0< n<5 If any of these conditions is not satisfied, the program terminates and prints...

  • 1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the are...

    1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the area of a triangle and counts total number of areas program has computed Program should have two functions sfun(): sfun receives the values of a, b and c then computes and returns the value ofs as areafun 0: areafun receives the value of s and computes and return the area of a triangle to main program using below formulae...

  • Question 2 Use a switch statement to write the following program: Using C++ The program prompts...

    Question 2 Use a switch statement to write the following program: Using C++ The program prompts the user for a letter grade (of type char). The list of valid letter grades is: A B C D E F The program should consider both lower and upper case The program will then display the following messages: For grade ‘A’: display “Excellent” For grade ‘B’: display “Good” For Grade ‘C’: display “Average” For grade ‘D’ or ‘E’: display “Below Average” For Grade...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT