求懂得人修改下!
时间:2011-12-05
来源:互联网
#include<iostream>
#include<cmath>
using namespace std;
class point
{
public:
int x,y;
point()
{
cout<<"请输入两点的坐标"<<endl;
cin>>x>>y;
}
};
class Line:private point
{
public:
Line():s1(),s2()
{};
show_length()
{
cout<<"此线段的长度是"<<sqrt((s2.y-s1.y)*(s2.y-s1.y)+(s2.x-s1.x)*(s2.x-s1.x))<<endl;
};
show_xl()
{
cout<<"斜率是"<<(s2.y-s1.y)/(s2.x-s1.x)<<endl;
};
private:
point s1,s2;
};
void main()
{
Line L1;
L1.show_xl();
L1.show_length();
}
这个程序怎么改才能在定义L1对象后运行程序后只需要输入两个值就可以了??
求高手解答,可以适当改下程序!
#include<cmath>
using namespace std;
class point
{
public:
int x,y;
point()
{
cout<<"请输入两点的坐标"<<endl;
cin>>x>>y;
}
};
class Line:private point
{
public:
Line():s1(),s2()
{};
show_length()
{
cout<<"此线段的长度是"<<sqrt((s2.y-s1.y)*(s2.y-s1.y)+(s2.x-s1.x)*(s2.x-s1.x))<<endl;
};
show_xl()
{
cout<<"斜率是"<<(s2.y-s1.y)/(s2.x-s1.x)<<endl;
};
private:
point s1,s2;
};
void main()
{
Line L1;
L1.show_xl();
L1.show_length();
}
这个程序怎么改才能在定义L1对象后运行程序后只需要输入两个值就可以了??
求高手解答,可以适当改下程序!
作者: s_april_s 发布时间: 2011-12-05
好多错误啊
C/C++ code
C/C++ code
class point { public: int x,y; point(const int n1 = 0,const int n2 = 0):x(n1),y(n2) { } }; class Line:public point { public: Line(const point p1,const point p2):s1(p1),s2(p2) {}; void show_length() { cout<<"此线段的长度是"<<sqrt((double)(s2.y-s1.y)*(s2.y-s1.y)+(double)(s2.x-s1.x)*(s2.x-s1.x))<<endl; }; void show_xl() { cout<<"斜率是"<<(double)(s2.y-s1.y)/(double)(s2.x-s1.x)<<endl; }; private: point s1,s2; }; int main() { int x1,y1,x2,y2; cout<<"请输入第一点的坐标"<<endl; cin>>x1>>y1; point p1(x1,y1); cout<<"请输入第二点的坐标"<<endl; cin>>x2>>y2; point p2(x2,y2); Line L1(p1,p2); L1.show_length(); L1.show_xl(); system("pause"); return 0; }
作者: riyueming184 发布时间: 2011-12-05
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28