用类成员结构修改习题6.4第4小题的程序,使其实现相同的功能。定义Point类和Line类,表示点和线;定义setPoint类,包含两个Line类成员和一个表示直线交点的Point成员,并定义类中求直线交点的成员函数。编写每个类相应的成员函数和测试用的主函数。
这个简单。。。
#include<iostream>
#include<cmath>
using namespace std;
class Point
{
public:
double x;
double y;
void print()
{
cout<<"交点为:("<<x<<" , "<<y<<")"<<endl;
}</cmath></iostream>
};
class Line
{
public:
double a,b;
void print()
{
cout<<"y="<<a<<"x+"<<b<<endl;
}
};
class setPoint
{
public:
Line L1;
Line L2;
Point p;
void pp(double a1,double b1,double a2,double b2)
{
L1.a=a1;
L1.b=b1;
L2.a=a2;
L2.b=b2;
p.x=(b2-b1)1.0/(a1-a2);
p.y=a1p.x+b1;
}
};
int main()
{
setPoint m;
int a1,b1,a2,b2;
cout<<"请输入两个方程的系数:";
cin>>a1>>b1>>a2>>b2;
m.pp(a1,b1,a2,b2);
m.L1.print();
m.L2.print();
m.p.print();
return 0;
}