Question

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 (scalene triangle), identify test cases to verify the boundary. Part b: For the boundary condition A = C case (isosceles triangle), identify test cases to verify the boundary. Part c: For the boundary condition A = B = C case (equilateral triangle), identify test cases to verify the boundary. Part d: For the boundary condition A2 +B2 = C2 case (right-angle triangle), identify test cases to verify the boundary.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find my implementation in C++.

// Triangle.cpp : Defines the entry point for the console application.
//

//Include header file
//#include "stdafx.h"
#include<iostream>

//Add namespace
using namespace std;

//Declare the class
class Triangle
{
   //Declare variables
   float a, b, c;
public:
   //Declare the required member functions
   void input();
   void TriangleType();
};


//Method to check the type of the triangle
void Triangle::TriangleType()
{
   //Test case to check whether the triangle is equilateral
   if (a == b == c)
       cout << "\nTriangle is equilateral Triangle.\n";

   //Test case to check whether the triangle is isocles
   else if ((a == b) || (a == c) || (c == b))
       cout << "\nTriangle is isoceles Triangle.\n";

   //Test case to check whther the triangle is right angled triangle
   else if (((a * a) + (b*b) == c*c) || ((a * a) + (c * c) == b*b)
               || ((c * c) + (b * b) == a * a))
       cout << "Triangle is Right Angled Triangle.\n";

   //Test case to check whether we are unable to make a triangle
   else if (((a + b) < c) || (c + b) < a || (a + c) < b)
       cout << "\n These sides are unable to make a triangle. Pls try again.";

   //Test case to check the scalene triangle
   else
       cout << "\nTriangle is Scalene Triangle.\n";
}

//Method to take input
void Triangle::input()
{
   cout << "Enter the sides of the triangle.";
   cout<<"Values should be between 1 to 50:\n ";
   cout << "\na is : ";
   //Test case to take the positive input
   try
   {
       cin >> a;
       if (a < 0)
           throw a;
       else if (a > 50){
           cout << "\nPlease enter the value within 1-50 : ";
            cin >> a;
        }
   }
   //catch block to handle the exception
   catch (float num)
   {
       cout << "\nNegative numbers are not allowed.";
       cout<<"\nPls again enter the value : ";
       cin >> a;
   }
   cout << "\nb is : ";

   //Test case to take the positive input
   try
   {
       cin >> b;
       if (b < 0)
           throw b;
       else if (b > 50){
           cout << "\nPlease enter the value within 1-50 : ";
          cin >> b;
        }
   }
   //catch block to handle the exception
   catch (float num)
   {
       cout << "\nNegative numbers are not allowed.";
       cout<<"\n Pls again enter the value : ";
       cin >> b;
   }
   cout << "\nc is : ";

   //Test case to take the positive input
   try
   {
       cin >> c;
       if (c < 0)
           throw c;
       else if (c > 50){
           cout << "\nPlease enter the value within 1-50 : ";
            cin >> c;
          }
   }
   //catch block to handle the exception
   catch (float num)
   {
       cout << "\nNegative numbers are not allowed.\nPls again enter the value: ";
       cin >> c;
   }
}

//Define the main function
int main()
{
   //create object of the class
   Triangle ob;
   char ch;
   //start do-while loop
   do
   {
       //call the methods
       ob.input();
       ob.TriangleType();
       cout << "Do you want to continue (y/n):";
       cin >> ch;
   } while (ch != 'n');
   //pause the system for a while
   system("pause");
   return 0;
}

thirdweek thirdweek thirdweek g++ TriangleClassification.cpp thirdweek ./a.out Enter the sides of the triangle.Values should

Add a comment
Know the answer?
Add Answer to:
Consider again the triangle classification program with a slightly different specification: The program reads floating values...
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
  • 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...

  • 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...

  • ***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 C program #include<stdio.h> Task is to implement the Triangle Program in C. The specification for...

    In C program #include<stdio.h> Task is to implement the Triangle Program in C. The specification for the program is: The triangle program accepts three strings, a, b, and c (the sides of a triangle) as command line parameters. The sides of the triangle must be integers. The sides a, b, and c must satisfy the following conditions: c1. 1 ≤ a ≤ 200 c2. 1 ≤ b ≤ 200 c3. 1 ≤ c ≤ 200 c4. a < b +...

  • 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...

  • 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...

  • 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...

  • Consider a program that takes three numbers as input and prints the values of these numbers...

    Consider a program that takes three numbers as input and prints the values of these numbers in descending order. Its input is a triple of positive integers (say x, y and z) and values are from interval [300,700]. Generate boundary value and robust test cases.

  • 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...

  • C Programming QUESTION 9 Write a program that prompts for and reads four integer input values,...

    C Programming QUESTION 9 Write a program that prompts for and reads four integer input values, then a single character command. Submit your program as a .c file named midterm_prog2.c. Note that, similarly to your programming assignments, some percentage of your grade will depend on proper programming style. Your program will calculate and print a new value based on the command that's entered, as follows: 'A' or 'a': Calculate the average of the four input values 'S' or 's': Calculate...

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