std::cout <<"Enter the height of the triangle : ";
std::cin >> h;
std::cout <<"Enter the base of the triangle : ";
std::cin >> b;
std::answer = 0.5*(h*b);
std::cout.fixed;
std::cout.precision(2);
std::cout <<"The Area of the Triangle is : " <<answer;
//driver code
Triangle set1(40, 30, 110);
if(set1.validateTriangle()){
std::cout << "The shape is a valid triangle.\n";
} else {
std::cout << "The shape is NOT a valid triangle.\n";
}
In the C++ programming language, the C++ Standard Library is a collection of classes and functions which are written in the core language and part of the C++ ISO Standard itself - and answer in your code does not belong them :) Using std (and its scope :: ) you can display text in the console (std::cout std::endl), you can use strings or vectors, pairs and more more more. This is the main base of C++
The sum of the angles of any triangle are exactly 180 degrees. If they sum to less or more than they are not angles of a triangle.
#However, as totalAngle is double doing an exact comparison with 180 is not guaranteed to be true even if the angles should add to 180 - due to the way non-integer numbers are represented in binary. The usual way to do such a comparison to check that the absolute value of num1 - num2 is less than a certain value (often called epsilon).
#include <iostream>
#include <cmath>
#include <iomanip>
class Triangle {
private:
double totalAngle {}, angleA {}, angleB {}, angleC {};
public:
Triangle(double A, double B, double C);
void setAngles(double A, double B, double C);
bool validateTriangle() const ;
};
Triangle::Triangle(double A, double B, double C) {
setAngles(A, B, C);
}
void Triangle::setAngles(double A, double B, double C) {
angleA = A;
angleB = B;
angleC = C;
totalAngle = A + B + C;
}
bool Triangle::validateTriangle() const {
return std::fabs(totalAngle - 180.0) < 0.001;
}
int main() {
double h {}, b {};
std::cout << "Enter the height of the triangle : ";
std::cin >> h;
std::cout << "Enter the base of the triangle : ";
std::cin >> b;
constauto area { 0.5 * (h * b) };
std::cout << std::fixed << std::setprecision(2) << "The Area of the Triangle is : " << area << '\n';
const Triangle set1(40, 30, 110);
if (set1.validateTriangle())
std::cout << "The shape is a valid triangle.\n";
else
std::cout << "The shape is NOT a valid triangle.\n";
}
The sum of the angles of any triangle are exactly 180 degrees. If they sum to less or more than they are not angles of a triangle.
That only applies to Euclidean space. A flat plane geometry.
The Real World isn't a flat plane, the Earth's an oblate spheroid. Transform a triangle drawn on that non-Euclidean surface to a Euclidean flat plane and the sum of the triangle's angles are greater than 180.
In non-Euclidean space the sum of the 3 angles of a triangle equal more or less than 180 degrees depending on the curvature of the space. Euclidean space geometry is a localized approximation.
It doesn't really make sense to have a constructor of a triangle with 3 angles as parameters:
(a) because if you have two angles then the third angle is automatic from the requirement to sum to 180 degrees;
(b) because it still doesn't uniquely define the triangle (as you don't know its size).
The only ways that you could define (the possibility of) unique triangles (up to congruence) are:-
- three sides;
- two sides and an angle between them;
- two sides and an angle not between them;
- one side and two angles.
... and then you'd need a fourth parameter to distinguish which of those three-parameter choices you were using!
Hello. You started an interesting conversation about Non-Euclidean space. This subject is one of my favorites since I found a book with some Escher illustrations. Also I read an article about dimensions - which are always the projection of the previous (3D is the projection of the 2D, the 4D is the projection of the 3D, etc). So how many dimensions could exist? An infinity?
About the Non-Euclidean space, I would like (sorry for that) to recommend you ... a video game. No! A fabulous game - The Manifold Garden. The best artistic representation of the Non-Euclidean space. A must have.
However a triangle has always in our world perception 180° as angles sum.
I forgot another game which has been created by an acquaintance of mine - a French guy from Paris. Fragments Of Euclid (for free). Great. If you are not a player, take a look at the video - and you have a clear perspective about what means a Non-Euclidean space ++
Monument Valley is ethereal - quiet delivering good vibes. One of its pros is the astonishing aesthetic. Great. Thanks for the links.
Also I like Antichamber ++