Sha256: af2681ccc56a57cddaa9e5d9afeabb7b77769817d4bf916e5bc25d1cc3c279cb

Contents?: true

Size: 630 Bytes

Versions: 396

Compression:

Stored size: 630 Bytes

Contents

#include "triangle.h"
#include <stdexcept>

namespace triangle
{

namespace
{

bool triangle_equality(double a, double b, double c)
{
    return a < (b + c)
        && b < (a + c)
        && c < (a + b);
}

}

flavor kind(double a, double b, double c)
{
    if (a == 0 || b == 0 || c == 0) {
        throw std::domain_error("Zero triangle");
    }
    if (a < 0 || b < 0 || c < 0 || !triangle_equality(a, b, c)) {
        throw std::domain_error("Invalid triangle");
    }
    if (a == b && b == c) {
        return equilateral;
    }
    if (a == b || b == c || a == c) {
        return isosceles;
    }
    return scalene;
}

}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.179 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.178 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.177 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.176 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.175 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.174 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.173 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.172 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.171 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.170 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.169 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.167 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.166 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.165 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.164 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.163 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.162 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.161 tracks/cpp/exercises/triangle/example.cpp
trackler-2.2.1.160 tracks/cpp/exercises/triangle/example.cpp