设计线段类Line,成员数据包括线段两个端点的坐标(double startx,starty,endx,endy)。根据给定的main函数设计必要的成员函数。 main函数已给定,提交时只需要提交main函数外的代码部分。 #include<iostream> #include<cmath> using namespace std; //你提交的代码在这里 int main() { Line L1; cout<<"Show object L1:"; L1.Show(); double x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; Line L2(x1,y1,x2,y2); cout<<"Show object L2:"; L2.Show(); cin>>x1>>y1>>x2>>y2; cout<<"Reset and Show object L1:"; L1.Set(x1,y1,x2,y2); L1.Show(); cout<<"Reset and Show object L2:"; L2.Set(); L2.Show(); return 0; }
时间: 2024-03-23 20:40:37 浏览: 165
MFC箭头画法及给定起点端点坐标后绘制
```cpp
#include<iostream>
#include<cmath>
using namespace std;
class Line{
private:
double startx, starty, endx, endy;
public:
Line(){
startx = 0;
starty = 0;
endx = 0;
endy = 0;
}
Line(double x1, double y1, double x2, double y2){
startx = x1;
starty = y1;
endx = x2;
endy = y2;
}
void Set(double x1, double y1, double x2, double y2){
startx = x1;
starty = y1;
endx = x2;
endy = y2;
}
void Set(){
cin >> startx >> starty >> endx >> endy;
}
void Show(){
cout << "(" << startx << "," << starty << ")" << "--(" << endx << "," << endy << ")" << endl;
}
};
int main() {
Line L1;
cout<<"Show object L1:";
L1.Show();
double x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
Line L2(x1,y1,x2,y2);
cout<<"Show object L2:";
L2.Show();
cin>>x1>>y1>>x2>>y2;
cout<<"Reset and Show object L1:";
L1.Set(x1,y1,x2,y2);
L1.Show();
cout<<"Reset and Show object L2:";
L2.Set();
L2.Show();
return 0;
}
```
阅读全文