Question

In: Computer Science

I need a program which tells me if three individual straight line segments form a plane...

I need a program which tells me if three individual straight line segments form a plane two-dimensional triangle. All three segments will have positive lengths. For example, the three segments 2.5, 3.4 and 5.3 will form a triangle but 1.7, 2.4 and 7.5 will not. If the user enters a zero value, it will be rejected. But if a negative number is entered, it will be changed to the corresponding positive value. Please keep in mind that the length of the longest segment must be less than the sum of the lengths of the other two segments.

The program will accept the three lengths of the segments using the iostream acceptance and testing syntax. Then, it will use a C++ class and a C++ object of that class to find the longest of the three segments and to test whether the three segments will form a triangle. If the three segments will form a triangle the method of your class will return the Boolean value true to the program’s main. Otherwise, it will return the Boolean value false to the program’s main. Then the program’s main will report the result as a text answer to the user, either “true” or “false” and then terminate.

Solutions

Expert Solution

#include<iostream>
using namespace std;

class Triangle{
private:
float side1,side2,side3;
public:
Triangle(float a, float b, float c){
side1 = a;
side2 = b;
side3 = c;
}

bool isTriangle(){
if(side1 + side2 <= side3 || side2 + side3 <= side1 || side3 + side1 <= side2){
return false;
}
return true;
}
};

int main(){
float a,b,c;
cout<<"Please enter three sides of triangle(one at a time)\n";
cin>>a;
while (a==0){
cout<<"Invalid input 0! Please enter again\n";
cin>>a;
}

if(a<0)
a = -a;

cin>>b;
while (b==0){
cout<<"Invalid input 0! Please enter again\n";
cin>>b;
}
if (b<0)
b = -b;

cin>>c;
while (c==0){
cout<<"Invalid input 0! Please enter again\n";
cin>>c;
}
if (c<0)
c = -c;

Triangle triangle(a,b,c);

if(triangle.isTriangle()){
cout<<"true\n";
}
else{
cout<<"false\n";
}
return 0;
}

Output:


Related Solutions

I need to make this program which supposed to accept the date form the user in...
I need to make this program which supposed to accept the date form the user in format of YYYY-MM-DD and output the corresponding date in its expanded format. output should be something like: Enter the date in YYYY-MM-DD: 2020-10-03 October o3, 2020 (in C++) I have this program but there are some errors that I couldn't find. // Lab3_Project_jk.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include<iostream> #include<string> using namespace std; int main()...
You drop a package from a plane flying at constant speed in a straight line. Without...
You drop a package from a plane flying at constant speed in a straight line. Without air resistance, the package will. (Hint: think about the velocity along the x direction, think about what type of motion you have along x direction). A) quickly lag behind the plane while falling. B) remain vertically under the plane while falling. C) move ahead of the plane while falling. D) not fall at all.
Which of the following is not true about straight-line deprecaition? Question 37 options: Straight-line depreciation requires...
Which of the following is not true about straight-line deprecaition? Question 37 options: Straight-line depreciation requires the s imples data and calculations. Straight-line depreciation assumes equal productivity each period. Straight-line depreciation is the most common depreciation method used by companies. Straight-line depreciation ignores the salvage value of an asset.
Citano Company has a used executive charter plane that originally cost $850,000. Straight-line depreciation on the...
Citano Company has a used executive charter plane that originally cost $850,000. Straight-line depreciation on the plane has been recorded for six years, with an $85,000 expected salvage value at the end of its estimated eight-year useful life. The last depreciation entry was made at the end of the sixth year. Eight months into the seventh year, Citano disposes of the plane. Required Prepare journal entries to record: a. Depreciation expense to the date of disposal. b. Sale of the...
I am trying to make a program in Python that opens a file and tells you...
I am trying to make a program in Python that opens a file and tells you how many lines, vowels, consonants, and digits there are in the file. I got the print out of lines, digits, and consonants, but the if statement I made with the vowels list isn't recognizing them. How can I make the vowels go through the if statement with the list? Am I using the wrong operator? Here is my program #Assignment Ch7-1 #This program takes...
Which of the following transactions is NOT reported on Form 8949 but is carried straight to...
Which of the following transactions is NOT reported on Form 8949 but is carried straight to Schedule D instead? Connor received a Form 1099-B reporting a wash sale of $371. Laquisha received a Form 1099-B with the basis not reported to the IRS for stock sale proceeds of $4,123. Malachi received a Form 1099-B reporting a short-term loss of $679 with the basis reported to the IRS. Zachary did not receive a Form 1099-B for the $248 he received when...
can someone make me a shopping cart for me ? i need to make a shopping...
can someone make me a shopping cart for me ? i need to make a shopping cart ,but i have no idea about how to do this i have made 3 line of items , this is one of the pruduct line line 1 ------------------------------------- <!DOCTYPE html> <html lang="en"> <head> <style> .div1 { border: 2px outset red; background-color: lightblue; text-align: center; } </style> </head> <!-- body --> <body style="background-color:silver; "class="main-layout position_head"> <!-- loader --> </li> </ul> </section> </nav> </section> </header>...
I need to write PYTHON program which is like a guessing game using randint function which...
I need to write PYTHON program which is like a guessing game using randint function which is already done, the user has to guess a number between 1 and 1000 and the game musn't end until you guess the number, if you input a smaller number you must get hints, the same goes if your input is bigger than the wining number , also you must get notified if you repeat a number (example, you pick 1 and in the...
1. Let R be the rectangle formed by going along line segments from 1 to i...
1. Let R be the rectangle formed by going along line segments from 1 to i to -1 to -i and back to 1. If f(z)=1/(z-5i) then the integral around R of f(z) has value of? 2. Let C be the circle of radius fifty centered at the origin with positive orientation. Then the integral around C of f(z) = 1/(z-4) has value of? 3. Let C be the circle of radius fifty centered at the origin with positive orientation...
Please I need a clear explanation and clear handwriting with explanaing this for me because I...
Please I need a clear explanation and clear handwriting with explanaing this for me because I am realy confused and need help. Thanks in advance My lab was about  Magnets and Magnetic fields. This is the question I need to answer for! R3: Explain how a speaker works by explaining why each part is required. after that Summarize R3’s answer by explaining why the proffesor homemade earbud is so much superior to the one that you made.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT