C/C++の宿題片付けます 133代目
■ このスレッドは過去ログ倉庫に格納されています
0883デフォルトの名無しさん
2010/01/17(日) 15:08:40Circle::getCPがグダグダ実装だけどw
Circle::Circle(string nm, double x, double y, double d)
: name(nm), cx(x), cy(y), rd(d) {}
int Circle::getCP(const Circle &x) const {
double d = sqrt((cx - x.cx) * (cx - x.cx) + (cy - x.cy) * (cy - x.cy));
int cp;
double penetration = rd + x.rd - d;
double padding = fabs(rd - x.rd) - d;
if (0 < padding) {
cp = 0;
} else if (padding == 0 || penetration == 0) {
cp = 1;
} else if (0 < penetration) {
cp = 2;
} else {
cp = 0;
}
return cp;
}
string Circle::getName(void) const {return name;}
double Circle::getRD(void) const {return rd;}
double Circle::getCX(void) const {return cx;}
double Circle::getCY(void) const {return cy;}
あと、リンク先のは誤字がある。以下のようにしないとコンパイルできない。
cout<<"円"<<p[i].getName()<<"と";
cout<<"円"<<p[j].getName()<<"の共有点の数は";
check_CP(c,sz);
■ このスレッドは過去ログ倉庫に格納されています