Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q: Hello, I want you to explain me this code in step by step and if possible use commed for explaining blow: Question was: Create

Q: Hello, I want you to explain me this code in step by step and if possible use commed for explaining blow:

Question was:

Create class Triangle, which encapsulates the fields and methods:

double a,b,c; - Length of the edges;

bool Set(double aa, double bb, double cc); - assignes fields values; method Set return true, if a triangle with such edges lengths can exist, and false, if cant exist;

double Perim(); - triangle perimeter;

double Area(); - triangle area;

bool IsRect(); - Checks whether it is a right-angled triangle;

#include #include using namespace std;

class Triangle{ public: Triangle(); bool Set(double aa, double bb, double cc); double Perim(); double Area(); bool isRect();

double a; //triangle sides double b; double c; };

Triangle::Triangle(){ a = b = c = 0; }

double Triangle::Perim(){ return a + b + c; }

double Triangle::Area(){ return (0.5)*a*c; }

bool Triangle::isRect(){ return (((a*a) + (b*b)) == (c*c)) ? true : false; //---checks if this is a right angle triangle, and should return true or false. }

bool Triangle::Set(double aa, double bb, double cc){ // This checks whether this triangle is possible and returns, true or false that should print on the screen.

return (((aa + bb) > cc) && ((aa + cc) > bb) && ((bb + cc) > aa)) ? true : false;

// a + b > c --- if one of these is false, a triangle cannot exist // a + c > b // b + c > a }

main() { Triangle t;

t.a = 10; t.b = 10; t.c = 10;

std::cout << t.Perim() << ' '; std::cout << t.Area() << ' '; std::cout << t.isRect() << ' ';

if (t.isRect()) { std::cout << "Is Right Triangle "; } else { std::cout << "Is NOT Right Triangle "; } std::cout << ' ';

t.a = 3; t.b = 4; t.c = 5;

std::cout << t.Perim() << ' '; std::cout << t.Area() << ' '; std::cout << t.isRect() << ' ';

if (t.isRect()) { std::cout << "Is Right Triangle "; } else { std::cout << "Is NOT Right Triangle "; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions