#include<iostream> #include<vector> #include<cmath> using namespace std; class point { private: int x,y; public: point(int x=0,int y=0):x(x),y(y){} void coutt () { cout << "[" <<x<<","<<y<<"]"<< endl; } }; int main() { int i,n; vector<int>x(100); vector<int>y(100); vector<point>m(100); for(i=0;i<100;i++) { cin >>x[i]>>y[i]; m[i]=point(x[i],y[i]); } n=x.size()-1; for(;n>=0;n--) m[n].coutt; return 0; } 有什么错
时间: 2024-01-14 16:02:12 浏览: 79
这段代码存在以下问题:
在使用
m[n].coutt
输出点的坐标时,应该加上小括号,即m[n].coutt()
。在使用
n=x.size()-1
计算向量x
的长度时,应该使用n=x.size()-1;
,即在语句的结尾加上分号。在
point
类中,应该将x
和y
成员变量声明为public
,否则在主函数中无法直接访问。
下面是修改后的代码:
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
class point {
public:
int x, y;
point(int x = 0, int y = 0) : x(x), y(y) {}
void coutt() {
cout << "[" << x << "," << y << "]" << endl;
}
};
int main() {
int i, n;
vector<int> x(100);
vector<int> y(100);
vector<point> m(100);
for (i = 0; i < 100; i++) {
cin >> x[i] >> y[i];
m[i] = point(x[i], y[i]);
}
n = x.size() - 1;
for (; n >= 0; n--)
m[n].coutt();
return 0;
}
阅读全文
相关推荐














