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

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

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

  • Write a C program that … reads a sequence of one or more double values from...

    Write a C program that … reads a sequence of one or more double values from standard input, one-after-another stops reading double values as soon as a negative value is entered then prints (to standard output & with precision 2) … the average of the positive values that were entered

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

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

  • Java Please - Design and implement a class Triangle. A constructor should accept the lengths of...

    Java Please - Design and implement a class Triangle. A constructor should accept the lengths of a triangle’s 3 sides (as integers) and verify that the sum of any 2 sides is greater than the 3rd(i.e., that the 3 sides satisfy the triangle inequality). The constructor should mark the triangle as valid or invalid; do not throw an exception. Provide get and set methods for the 3 sides, and recheck for validity in the set methods. Provide a toString method...

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
ADVERTISEMENT