Untitled

mail@pastecode.io avatar
unknown
c_cpp
21 days ago
596 B
0
Indexable
Never
#include <iostream>
#include <math.h>

struct Rectangle {
	std::pair<float, float> coordinate[4];
	float Perimeter() {
		int P{};
		for (int i = 0; i < 4; i++) {
			int cx = abs(coordinate[i].first - coordinate[(i + 1) % 4].first);
			int cy = abs(coordinate[i].second - coordinate[(i + 1) % 4].second);
			P += std::sqrt(cx * cx + cy * cy);
		}
		return P;
	}
};

int main() {
	Rectangle rec;
	float P{};
	float x, y;
	for (int i = 0; i < 4; i++) {
		std::cin >> rec.coordinate[i].first >> rec.coordinate[i].second;
	}
	std::cout << "Perimeter: " << rec.Perimeter();
}
	
Leave a Comment