CS2263/Final/FinalCode/polymorphism/square.h

25 lines
430 B
C
Raw Permalink Normal View History

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