CS2263/Final/FinalCode/polymorphism/triangle.h

25 lines
489 B
C
Raw Permalink Normal View History

2023-05-22 23:28:51 -03:00
#ifndef triangle_h
#define triangle_h
#include <stdlib.h>
#include <math.h>
#include "shape.h"
double triangleArea(Shape* triangle) {
double side = triangle->perimeter / 3;
double area = (sqrt(3) / 4) * (side * side);
return area;
}
Shape* newTriangle(double perimeter) {
Shape* triangle = malloc(sizeof(Shape));
triangle->numSides = 4;
triangle->perimeter = perimeter;
triangle->area = triangleArea;
return triangle;
}
#endif