- 230 名前:デフォルトの名無しさん mailto:sage [2008/08/14(木) 21:49:25 ]
- #include <iostream>
using namespace std; class Point{ private: double L1Point[2]; double L2Point[2]; double L1Slope, L2Slope; double num[2]; public: Point(); void lineIntersect(); void show(); }; //メンバ関数の定義 Point::Point(){ L1Point[0] = 9; L1Point[1] = 6; L2Point[0] = 5; L2Point[1] = 6; L1Slope = 2; L2Slope = 1; num[0] = 0; num[1] = 0; } void Point::lineIntersect(){ num[0] = (L1Slope * L1Point[0] - L2Slope * L2Point[0] + L2Point[1] - L1Point[1]) / (L1Slope - L2Slope); num[1] = L1Slope * (num[0] - L1Point[0]) + L1Point[1]; } void Point::show(){ cout << "答えは(x=" << num[0] << ",y=" << num[1] << ")です\n";} int main(){ Point pt; pt.lineIntersect(); pt.show(); return 0;} 227さんのレスを見て自分なりにコードを書いてみました。無事実行できました。コードで直したほうがいいところがあったら指摘お願いします。
|

|