Question

In: Computer Science

Write an interactive C++·program to have a user input their three initials and the length of...

Write an interactive C++·program to have a user input their three initials and the length of three sides of a triangle. Allow the user to enter the sides in any order.

Determine if the entered sides form a valid triangle.The triangle may not have negative sides.The sum of any two sides must be greater than the third side to form a triangle.

Determine if the entered sides are part of a scalene, isosceles, or equilateral triangle. Using the

Pythagorean Theorem, determine if the scalene triangle is also right triangle. (A^2+ B^2= C^2, where C is the hypotenuse.)Adequately check entered data for validity.

Use adequate test data to process all valid data and representative combinations of invalid data.Label output clearly.

Be sure your output printout contains user prompts and what was entered by the user in addition to the results of your program processing.

Examples

of test data

3 4 5

1 2 0

7 -3 5

6 6 4

7 7 7

2 2 4

Solutions

Expert Solution

#include <iostream>
#include <fstream>

using namespace std;

bool isValid(int a, int b, int c) {
        if(a < 0 || b < 0 || c < 0) {
                return false;
        }
        if(a > (b + c)) {
                return false;
        }
        if(b > (a + c)) {
                return false;
        }
        if(c > (a + b)) {
                return false;
        }
        return true;
}

void processTriangle(int a, int b, int c) {
        if(!isValid(a, b, c)) {
                cout << "Invalid triangle" << endl;
        } else {
                if(a == b == c) {
                        cout << "equilateral triangle" << endl;
                } else if(a == b || a == c || b == c) {
                        cout << "isosceles triangle" << endl;
                } else {
                        if(a > b && a > c && (a*a == (b*b + c*c))) {
                                cout << "Right triangle" << endl;
                        } else if(b > a && b > c && (b*b == (a*a + c*c))) {
                                cout << "Right triangle" << endl;
                        } else if(c > b && c > a && (c*c == (b*b + a*a))) {
                                cout << "Right triangle" << endl;
                        } else {
                                cout << "Scalene triangle" << endl;
                        }                       
                }
        }
}

int main() {
        ifstream f("input.txt");

        if(f.fail()) {
                cout << "File input.txt not found." << endl;
        } else {

                int a, b, c;

                while(f >> a >> b >> c) {
                        processTriangle(a, b, c);
                }
        }
}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write an interactive C program that asks a user to enter a sentence from the keyboard,...
Write an interactive C program that asks a user to enter a sentence from the keyboard, and prints the sentence with all the words spelled backwards. Note: you may assume that each sentence will have at most 50 characters and each word is separated by a space. Sample code execution: bold information entered by user enter a sentence: hello ece 175 class olleh ece 571 ssalc continue (q to quit)? y enter a sentence: May the force be with you...
You are required to write an interactive JS program that prompts the user for three numbers...
You are required to write an interactive JS program that prompts the user for three numbers and then finds the sum, average, smallest, and the largest value of the numbers and prints the results labeling properly.
C++ Question: write a program that prompts the user for the length and width of a...
C++ Question: write a program that prompts the user for the length and width of a rectangle in inches.  The program then uses functions to compute the perimeter and area of the rectangle and to convert those to meters and square meters respectively. Sample output from one instance of the program is shown below: ```html Welcome to the Foot-To-Meter Rectangle Calculator ================================================= Enter the rectangle length in feet: 2 Enter the rectangle width in feet: 3 The rectangle dimensions are: 0.61...
Write an interactive program in c++ that allows the user toenter 2-15 vectors (use the...
Write an interactive program in c++ that allows the user to enter 2-15 vectors (use the if statement). Display the resultant on the screen.
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT