Пример #1
0
static PyObject *web_heron(PyObject *self, PyObject *args)
{
    double a, b,c;

    /* Parse the input tuple */
    if (!PyArg_ParseTuple(args, "ddd", &a, &b, &c))
        return NULL;

    /* Call the external C function to compute the area. */
    double area = heron(a,b,c);

    /* Build the output tuple */

    PyObject *ret = Py_BuildValue("d",area);
    return ret;
}
Пример #2
0
double area(const Shape& shape)
{
    loc  x,y,z;
    double r,s;

    if (mch::C<Circle>(_,r)(shape))
        return 3.14 * r * r;

    if (mch::C<Square>(_,s)(shape))
        return s * s;

    if (mch::C<Triangle>(x,y,z)(shape))
        return heron(x,y,z);

    XTL_ASSERT(!"Inexhaustive search");
    return 0.0;
}
Пример #3
0
double area(const Shape& shape)
{
    mch::wildcard      _; // Meta variable
    mch::var<loc>  x,y,z;
    mch::var<double> r,s;

    if (mch::C<Circle>(_,r)(shape))
        return 3.14 * r * r;

    if (mch::C<Square>(_,s)(shape))
        return s * s;

    if (mch::C<Triangle>(x,y,z)(shape))
        return heron(x,y,z);

    XTL_ASSERT(!"Inexhaustive search");
    XTL_UNREACHABLE; // To avoid warning that control may reach end of a non-void function
}
Пример #4
0
int main(){
    float x, y;
    int i, n;
    double S;

    n = 0;
    while(scanf("%f,%f", &x, &y)==2){
        V[n].fX = x;
        V[n].fY = y;
        n++;
    }

    S = 0.0;
    for(i=1; i<n-1;i++){
        S += heron(
                distance(V[0], V[i]),
                distance(V[0], V[i+1]),
                distance(V[i], V[i+1]));
    }
    printf("%f\n",S);

    return 0;
}
Пример #5
0
	    virtual void visit(const Triangle& s) { result = heron(s.first,s.second,s.third); }