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()...
I need someone to create a program for me: Create a program that takes as input...
I need someone to create a program for me: Create a program that takes as input an employee's salary and a rating of the employee's performance and computes the raise for the employee. The performance rating here is being entered as a String — the three possible ratings are "Outstanding", "Acceptable", and " Needs Improvement ". An employee who is rated outstanding will receive a 10.2 % raise, one rated acceptable will receive a 7 % raise, and one rated...
I need to write a program in C with the following specification * ​​​​​​​Line one of...
I need to write a program in C with the following specification * ​​​​​​​Line one of the standard input will have the total number of people which must not be greater than 10 * Each of the subsequent lines of input will be the first name of a person and their number (ex. "Adam 85") one space between name and number * Each name must be a maximum of 14 characters * Put the first names into an array called...
Need the correct line of code for c program to solve  this equation . i is a...
Need the correct line of code for c program to solve  this equation . i is a value that the program all ready calculates from user imput. t i = (x*1000)+(y*500)+(z*250
A pilot flies her route in two straight-line segments. The displacement vector A for the first...
A pilot flies her route in two straight-line segments. The displacement vector A for the first segment has a magnitude of 235 km and a direction 30.0o north of east. The displacement vector B for the second segment has a magnitude of 173 km and a direction due west. The resultant displacement vector is R = A + B and makes an angle θ with the direction due east. Using the component method, find (a) the magnitude of R and...
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...
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>...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT