Стигнах до тук |
||||
|
||||
|
|
||||
![]() ![]() |
Изскочиха ми очите вече да го гледам тоя код. Моля ако някой може да помогне. Мисля че почти е довършено вече.
#include <iostream> #include "math.h" #include <algorithm> #include <vector> using namespace std; class Point { private: float x; float y; public: // Contructors Point(); Point(float x, float y); Point(const Point ©); // Getters and setters float GetX(); void SetX(float x); float GetY(); void SetY(float y); // Operators Point& operator=(const Point & b); bool operator==(Point b); bool operator<(Point b); // Methods - member functions float DistanceBetween(Point & p); // Destructors ~Point(); }; Point::Point() { x = 0; y = 0; } Point::Point(float x, float y) { this->x = x; this->y = y; } Point::Point(const Point & copy) { this->x = copy.x; this->y = copy.y; } float Point::GetX() { return x; } void Point::SetX(float x) { this->x = x; } float Point::GetY() { return y; } void Point::SetY(float y) { this->y = y; } Point& Point::operator=(const Point & b) { this->x = b.x; this->y = b.y; return *this; } bool Point::operator==(Point b) { if (this->x == b.x && this->y == b.y) { return true; } return false; } bool Point::operator<(Point b) { if (this->x < b.x || (this->x == b.x && this->y < b.y)) { return true; } return false; } float Point::DistanceBetween(Point &p) { return sqrt(pow(this->GetX() - p.GetX(), 2) + pow(this->GetY() - p.GetY(), 2)); } Point::~Point() { // do nothing, because there is nothing to release, no pointers or other objects inside this object } // 2D cross product. // Return a positive value, if OAB makes a counter-clockwise turn, // negative for clockwise turn, and zero if the points are collinear. float Cross(Point &O, Point &A, Point &B) { return (A.GetX() - O.GetX()) * (B.GetY() - O.GetY()) - (A.GetY() - O.GetY()) * (B.GetX() - O.GetX()); } // Implementation of Monotone Chain Convex Hull algorithm. // Returns a list of points on the convex hull in counter-clockwise order. // Note: the last point in the returned list is the same as the first one. vector<Point> ConvexHull(vector<Point> P) { int n = P.size(), k = 0; vector<Point> H(2 * n); // Sort points lexicographically sort(P.begin(), P.end()); // Build lower hull for (int i = 0; i < n; i++) { while (k >= 2 && Cross(H[k - 2], H[k - 1], P[i]) <= 0) k--; H[k++] = P[i]; } // Build upper hull for (int i = n - 2, t = k + 1; i >= 0; i--) { while (k >= t && Cross(H[k - 2], H[k - 1], P[i]) <= 0) k--; H[k++] = P[i]; } H.resize(k); return H; } void PrintPoints(vector<Point> points) { for (vector<Point>::iterator iter = points.begin(); iter != points.end(); iter++) { cout << "(" << iter->GetX() << ", " << iter->GetY() << ")" << endl; } } Point Centroid(vector<Point> points) { int n = points.size(); float sumX, sumY; sumX = sumY = 0; for (vector<Point>::iterator iter = points.begin(); iter != points.end(); iter++) { sumX += iter->GetX(); sumY += iter->GetY(); } return Point(sumX / n, sumY / n); } float TriangleArea(Point A, Point B, Point C) { float a = sqrt(pow(C.GetX() - B.GetX(), 2) + pow(C.GetY() - B.GetY(), 2)); float b = sqrt(pow(A.GetX() - C.GetX(), 2) + pow(A.GetY() - C.GetY(), 2)); float c = sqrt(pow(B.GetX() - A.GetX(), 2) + pow(B.GetY() - A.GetY(), 2)); float s = (a + b + c) / 2; return sqrt(s * (s - a) * (s - b) * (s - c)); } float Area(vector<Point> convexHullPoints) { int n = convexHullPoints.size(); Point centroid = Centroid(convexHullPoints); float area = 0; for (int i = 0; i < n - 1; i++) { area += TriangleArea(centroid, convexHullPoints[i], convexHullPoints[i + 1]); } return area; } void main() { vector<Point> allPoints; allPoints.push_back(Point(73, 58)); allPoints.push_back(Point(45, 19)); allPoints.push_back(Point(89, 6)); allPoints.push_back(Point(22, 40)); allPoints.push_back(Point(92, 16)); allPoints.push_back(Point(65, 66)); allPoints.push_back(Point(55, 4)); allPoints.push_back(Point(45, 18)); allPoints.push_back(Point(64, 13)); allPoints.push_back(Point(56, 81)); allPoints.push_back(Point(73, 33)); allPoints.push_back(Point(58, 40)); allPoints.push_back(Point(40, 71)); allPoints.push_back(Point(90, 60)); allPoints.push_back(Point(16, 47)); allPoints.push_back(Point(6, 52)); allPoints.push_back(Point(62, 91)); allPoints.push_back(Point(90, 83)); allPoints.push_back(Point(69, 78)); allPoints.push_back(Point(61, 62)); allPoints.push_back(Point(71, 57)); allPoints.push_back(Point(32, 53)); allPoints.push_back(Point(67, 91)); allPoints.push_back(Point(83, 89)); allPoints.push_back(Point(14, 53)); allPoints.push_back(Point(45, 35)); allPoints.push_back(Point(11, 6)); allPoints.push_back(Point(9, 50)); allPoints.push_back(Point(70, 65)); allPoints.push_back(Point(50, 47)); allPoints.push_back(Point(65, 57)); allPoints.push_back(Point(40, 68)); allPoints.push_back(Point(44, 40)); allPoints.push_back(Point(77, 61)); allPoints.push_back(Point(27, 59)); allPoints.push_back(Point(27, 54)); allPoints.push_back(Point(94, 89)); allPoints.push_back(Point(90, 88)); allPoints.push_back(Point(61, 66)); allPoints.push_back(Point(72, 4)); allPoints.push_back(Point(11, 41)); allPoints.push_back(Point(3, 74)); allPoints.push_back(Point(44, 33)); allPoints.push_back(Point(47, 79)); allPoints.push_back(Point(68, 33)); allPoints.push_back(Point(32, 64)); allPoints.push_back(Point(66, 23)); allPoints.push_back(Point(55, 12)); allPoints.push_back(Point(37, 54)); allPoints.push_back(Point(28, 95)); vector<Point> convexHullPoints = ConvexHull(allPoints); PrintPoints(convexHullPoints); cout << "The area of the convex hull amounts: " << Area(convexHullPoints) << endl; } |
|||
|
---------------------------
Потребител от: 14.05.08 | Всички уроци от simeons | Всички скриптове от simeons |
||||
|
|
||||
|
||||
|
|
||||
![]() ![]() ![]() |
Ами виж сега хубаво беше да занем и условието,напарвих един проект във VS 2008 тествах я и виж репорта за грешките сам говори за себе си
1>c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(195) : error C2337: 'SA_Pre' : attribute not found 1>c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(195) : error C2337: 'SA_Pre' : attribute not found 1>c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(195) : error C2337: 'SA_Pre' : attribute not found 1>c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(195) : error C2337: 'SA_Pre' : attribute not found 1>c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(195) : error C2337: 'SA_Pre' : attribute not found 1>c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(195) : fatal error C1003: error count exceeds 100; stopping compilation 1>Build log was saved at "file://c:\Documents and Settings\vanya69.ZAIKONI\My Documents\Visual Studio 2008\Projects\sega da vidim\sega da vidim\Debug\BuildLog.htm" 1>sega da vidim - 137 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Ще видя какво мога да направя да ги понамалим-пооправихме малко положението и не тръгва защото имаш функции които се използват а не са извикани |
|||
|
Това мнение е редактирано от zaikoni на 09.06.2008 16:54
---------------------------
Потребител от: 30.01.08 | Всички уроци от zaikoni | Всички скриптове от zaikoni Човекът,който знае KAK,винаги ще има работа.Човекът който знае ЗАЩО,винаги ще бъде негов ШЕФ. " |
||||
|
|
||||
|
|
||||
![]() ![]() |
Е да май не съм съобразил за условието :)
Дадени са мновество от точки в равнината (в сорса са). Програмата трябва да пресмята следните неща: 1-Минималното разстояние между 2 точки 2-Максималното такова 3-Най-голямото лице на триегълника, който ъгли са му тия точки 4-и графика на изпъкналостта на точките [i]\ [/i] |
|||
|
---------------------------
Потребител от: 14.05.08 | Всички уроци от simeons | Всички скриптове от simeons |
||||
|
|
||||
|
|
||||
![]() ![]() ![]() |
Ами вече не ми дава грешки ето и кода
CODE
|
|||
|
Това мнение е редактирано от zaikoni на 09.06.2008 17:04
---------------------------
Потребител от: 30.01.08 | Всички уроци от zaikoni | Всички скриптове от zaikoni Човекът,който знае KAK,винаги ще има работа.Човекът който знае ЗАЩО,винаги ще бъде негов ШЕФ. " |
||||
|
|
||||
|
|
||||
![]() ![]() |
Абе, няма лошо. Класове, вектори, итератори, предефиниране на оператори - нали трябва да е C++.
Използваме перални за пране на чорапи. Може би с учебна цел. Само като видях инициализацията на точките ми прилоша. А може далеч по-просто да е - без четвъртото условие: http://it-place.net/forum/2/C__C++__.NET/13752/C%2B%2B+%3F%3F%3F |
|||
|
---------------------------
Потребител от: 15.01.08 | Всички уроци от gomaker | Всички скриптове от gomaker |
||||
|
|
||||
| 1 посетител чете тази тема (0 потребители и 1 гост) | |
|
Активни потребители:
---
|
|
|
| |
Още по темата:
php форум,
форум компютри,
flash форум,
html форум,
it форум,
seo форум,
vista форум,
pc форум,
css форум,
java форум,
mysql форум












