#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
struct point2D
{
int x;
int y;
};
float max(float a, float b)
{
if (a>b)
return a;
else
return b;
}
void inputPoint(vector<point2D> point)
{
int i;
int n;
point2D temp;
cout << "Hay nhap so diem: ";
cin >> n;
point.resize(n);
for (i=1;i<=(n);i++)
{
cout << "Hay nhap diem thu " << i << endl ;
cin >> temp.x >> temp.y;
point.push_back(point2D()); //emplace_back()
point[i-1].x=temp.x;
point[i-1].y=temp.y;
}
cout << "Complete";
}
float distance(point2D pt1, point2D pt2)
{
return sqrt(pow(double(pt1.x-pt2.x),2)+pow(double(pt1.y-pt2.y),2));
}
float findDis(vector<point2D> point)
{
int size=point.size();
float maximum=0;
int i,j;
for (i=0;i<size;i++)
for (j=0;j<size;i++)
maximum=max(maximum,distance(point[i],point[j]));
return maximum;
}
int main()
{
vector<point2D> point;
int n;
inputPoint(point);
cout << "Khoang cach lon nhat la: " << findDis(point);
getchar();
getchar();
return 0;
}
bị báo lỗi nhưng em không biết sửa sao cả :((
làm thử theo bên này mà không được http://stackoverflow.com/questions/8067338/c-vector-of-structs-initialization

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?