CS2263/Final/FinalCode/polymorphism/triangle.h
2023-05-22 23:28:51 -03:00

25 lines
489 B
C

#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