其他分享
首页 > 其他分享> > 小学期

小学期

作者:互联网

完成了小学期的指定内容

#include<iostream>
#include<math.h>
#include <stdlib.h>
using namespace std;
class Dian {
private:
double x, y, z;
public:
void srzb();//输入xyz
void qrzb();//输出刚才输入的坐标并确认
double getx() { return x; }
double gety() { return y; }
double getz() { return z; }
void juli();
~Dian();
};
class Xian :public Dian {
private:
int m, n, p;//点斜式方向向量分量
int x, y, z;//点斜式点的坐标分量
public:
Dian i;
Dian j;
int getm() { return m; }
int getn() { return n; }
int getp() { return p; }
void liangdianshi();
void liangjiaomian();
void dianxieshi();
void dianxianjuli();
void danweixiangliang();
void dainxianweizhi();
void xianxianweizhi();
~Xian();
};
class Mian :public Dian {
private:
double a, b, c, d;
public:
double geta() { return a; }
double getb() { return b; }
double getc() { return c; }
double getd() { return d; }
void setm();
void sandian();
void dianfashi();
void showm();//将方程式表达出来
void dianmianjuli();
void danweifaxiangliang();//单位法向量
void dianmianweizhi();
void xianmianweizhi();
void mianmianweizhi();
~Mian();
};
void Dian::srzb()//输入xyz
{
cin >> x; cin >> y; cin >> z;
}
void Dian::qrzb()//输出刚才输入的坐标并确认
{
cout << "坐标形式为:";
cout << "(" << x << "," << y << "," << z << ")" << endl;
}
void Dian::juli()
{
double d;
Dian A, B;
cout << "A点的坐标为: " << endl;
A.srzb();
A.qrzb();
cout << "B点的坐标为: " << endl;
B.srzb();
B.qrzb();
d = sqrt((B.getx() - A.getx()) * (B.getx() - A.getx()) + (B.gety() - A.gety()) * (B.gety() - A.gety()) + (B.getz() - A.getz()) * (B.getz() - A.getz()));
cout << "两点之间的距离为= " << d;
}
void Xian::liangdianshi()//两点式
{
Dian A, B;
cout << "A";
A.srzb();

cout << "B" << endl;
B.srzb();

double s1;
s1 = sqrt((A.getx() - B.getx()) * (A.getx() - B.getx()) + (A.gety() - B.gety()) * (A.gety() - B.gety()) + (A.getz() - B.getz()) * (A.getz() - B.getz()));
cout << "两点间的直线方程为:" << endl;
cout << "x-" << A.getx() << "/" << (B.getx() - A.getx()) << "=" << "y-" << A.gety() << "/" << (B.gety() - A.gety()) << "=" << "z-" << A.getz() << "/" << (B.getz() - A.getz()) << endl;
}
void Xian::liangjiaomian() //两个相交平面
{
cout << "两个平面分别为:" << endl;
Mian m1;
Mian m2;
m1.setm(); m1.showm();
m2.setm(); m2.showm();
cout << "该直线方程为:" << endl;
cout << "两平面确定的方程(一般式)为:\n{" << m1.geta() << "x+" << m1.getb() << "y+" << m1.getc() << "z+" << m1.getd() << "=0\n{" << m2.geta() << "x+" << m2.getb() << "y+" << m2.getc() << "z+" << m2.getd() << "=0\n";
}

void Xian::dianxieshi() //点斜式
{
int x, y, z;
cout << "输入点的坐标值:";
Dian A;
A.srzb();
cout << "该点的坐标形式为:";
A.qrzb();
cout << "\n";
cout << "请输入方向向量:";
cin >> x >> y >> z;
m = x; n = y; p = z;
cout << "该方向向量为:";
cout << "(" << x << "," << y << "," << z << ")";
cout << "点斜式所确定的直线方程为:" << endl;
cout << "x-" << A.getx() << "/" << x << "=" << "y-" << A.gety() << "/" << y << "=" << "z-" << A.getz() << "/" << z << endl;
}
void Xian::dianxianjuli() //点到线的距离面积法
{
Dian y, m, n;
y.srzb(); y.qrzb();
m.srzb(); m.qrzb();
n.srzb(); n.qrzb();
double k, l, h;
double p;
double s;
double d;
k = sqrt((m.getx() - n.getx()) * (m.getx() - n.getx()) + (m.gety() - n.gety()) * (m.gety() - n.gety()) + (m.getz() - n.getz()) * (m.getz() - n.getz()));
l = sqrt((m.getx() - y.getx()) * (m.getx() - y.getx()) + (m.getx() - y.getx()) * (m.gety() - y.gety()) + (m.getz() - y.getz()) * (m.getz() - y.getz()));
h = sqrt((n.getx() - y.getx()) * (n.getx() - y.getx()) + (n.gety() - y.gety()) * (n.gety() - y.gety()) + (n.getz() - y.getz()) * (n.getz() - y.getz()));
p = (k + l + h) / 2;
s = sqrt(p * (p - k) * (p - l) * (p - h));
d = 2 * s / k;
cout << d << endl;
}
void Xian::danweixiangliang() //单位方向向量
{
Dian d;
cout << "请输入直线的方向向量:" << endl;
d.srzb(); d.qrzb();
double w;
w = sqrt(d.getx() * d.getx() + d.gety() * d.gety() + d.getz() * d.getz());
cout << "其单位方向向量为:" << endl;
cout << "(" << d.getx() / w << "," << d.gety() / w << "," << d.getz() / w << ")" << endl;
}
void Xian::dainxianweizhi() //点线的位置关系
{
Dian y;
Dian m;
Dian n;
y.srzb(); y.qrzb();
m.srzb(); m.qrzb();
n.srzb(); n.qrzb();
double k, l, h;
double p;
double s;
double d;
k = sqrt((m.getx() - n.getx()) * (m.getx() - n.getx()) + (m.gety() - n.gety()) * (m.gety() - n.gety()) + (m.getz() - n.getz()) * (m.getz() - n.getz()));
l = sqrt((m.getx() - y.getx()) * (m.getx() - y.getx()) + (m.getx() - y.getx()) * (m.gety() - y.gety()) + (m.getz() - y.getz()) * (m.getz() - y.getz()));
h = sqrt((n.getx() - y.getx()) * (n.getx() - y.getx()) + (n.gety() - y.gety()) * (n.gety() - y.gety()) + (n.getz() - y.getz()) * (n.getz() - y.getz()));
p = (k + l + h) / 2;
s = sqrt(p * (p - k) * (p - l) * (p - h));
d = 2 * s / k;
if (d == 0)
cout << "点在直线上" << endl;
else
cout << "点在直线外" << endl;
}
void Xian::xianxianweizhi() //线线的位置关系
{
Xian l1, l2;
l1.dianxieshi(); l2.dianxieshi();
if (l1.getm() == l2.getm() && l1.getn() == l2.getn() && l1.getp() == l2.getp())
cout << "两直线重合!\n";
if (l1.getm() / l2.getm() == l1.getn() / l2.getn() == l1.getp() / l2.getp() != 0)
cout << "两直线平行!\n";
else cout << "两直线相交或异面!\n";
}
void Mian::setm()
{
cout << "请输入平面一般方程的a,b,c,d的值:";
cin >> a >> b >> c >> d;
}
void Mian::showm()
{
cout << "平面的一般方程为:";
cout << a << "x";
if (b >= 0)
cout << "+";

cout << b << "y";

if (c >= 0)
cout << "+";

cout << c << "z";

if (d >= 0)
cout << "+";
cout << d << "=0\n";

}
void Mian::sandian()//三个不共线的点
{
cout << "请输入三个不共线的点:";
Dian A, B, C;
A.srzb(); A.qrzb();
B.srzb(); B.qrzb();
C.srzb(); C.qrzb();
a = (C.gety() - A.gety()) * (C.getz() - A.getz()) - (C.gety() - A.gety()) * (B.getz() - A.getz());
b = (C.getx() - A.getx()) * (B.getz() - A.getz()) - (B.getx() - B.getx()) * (B.getz() - A.getz());
c = (B.getx() - A.getx()) * (C.gety() - A.gety()) - (C.getx() - A.getx()) * (B.gety() - A.gety());
d = -(a * (A.getx()) + b * (A.gety()) + c * (A.getz()));
showm();
}
void Mian::dianfashi()//一个点和一个法向量
{
Mian A;
A.srzb(); A.qrzb();
int x, y, z;
cout << "请输入平面的法向量n=(x,y,z):";
cin >> x >> y >> z;
a = x; b = y; c = z;
d = -(a * (A.getx()) + b * (A.gety()) + c * (A.getz()));
showm();
}

void Mian::dianmianjuli()//点到面的距离
{
Dian A;
A.srzb(); A.qrzb();
Mian m1;
m1.setm(); m1.showm();
double d, m, n;
m = (m1.geta() * A.getx() + m1.getb() * A.gety() + m1.getc() * A.getz() + m1.getd());
n = sqrt(double(m1.geta() * m1.geta() + m1.getb() * m1.getb() + m1.getc() * m1.getc()));
d = m / n;
cout << "点到平面的距离为:" << d << endl;
}
void Mian::danweifaxiangliang()//平面的单位法向量
{
double n;
n = sqrt(double((a * a + b * b + c * c)));
cout << "平面的法向量为:(" << a / n << "," << b / n << "," << c / n << ")" << endl;
}
void Mian::dianmianweizhi()
{
Dian d1;
d1.srzb(); d1.qrzb();
Mian m1;
m1.setm(); m1.showm();
if (m1.geta() * d1.getx() + m1.getb() * d1.gety() + m1.getc() * d1.getz() + m1.getd() == 0)
cout << "点在平面内!\n";
else cout << "点在平面外!\n";
}
void Mian::xianmianweizhi()
{
Xian x; Mian m;
x.dianxieshi();
m.setm(); m.showm();
if (x.getm() * m.geta() + x.getn() * m.getb() + x.getp() * m.getc() == 0)
cout << "直线和平面平行!" << endl;
else if (x.getm() / m.geta() == x.getn() / m.getb() == x.getp() / m.getc())
cout << "直线和平面垂直!" << endl;
else
cout << "直线和平面相交!" << endl;
}
void Mian::mianmianweizhi()
{
Mian m1, m2;
m1.setm(); m1.showm();
m2.setm(); m2.showm();
if (m1.geta() / m2.geta() == m1.getb() / m2.getb() == m1.getc() / m2.getc() == m1.getc() / m2.getc() != 0)
cout << "两平面平行!\n";
if (m1.geta() == m2.geta() && m1.getb() == m2.getb() && m1.getc() == m2.getc() && m1.getc() == m2.getc())
cout << "两平面重合!\n";
else cout << "两平面相交!\n";
}
Dian::~Dian()
{

}
Xian::~Xian()
{

}
Mian::~Mian()
{

}

int main()
{
int x, a;
for (int n = 0;; n++)
{
cout << " 请选择执行项目:" << endl;
cout << " 1、创建 " << endl;
cout << " 2、距离 " << endl;
cout << " 3、向量 " << endl;
cout << " 4、关系 " << endl;
cout << " 5、退出 " << endl;
cout << endl;
cin >> x;
cout << endl;
switch (x)
{
case 1: {
int y;
cout << "1、创建直线\t2、创建平面" << endl;
cout << endl;
cin >> y;
switch (y) {
case 1: {
int k;
cout << "1、两点确定一条直线\t2、两个相交平面确定一条直线\t3、点斜式求直线" << endl;
cin >> k;
if (k == 1) {
Xian l;
l.liangdianshi();
}
if (k == 2) {
Xian l;
l.liangjiaomian();
}
if (k == 3) {
Xian l;
l.dianxieshi();
}
break;
}
case 2: {
int k;
cout << "1、三个点确定一个平面\t2、一个点与一个法向量确定一个平面" << endl;
cin >> k;
if (k == 1) {
Mian s;
s.sandian();
}
if (k == 2) {
Mian s;
s.dianfashi();
}
break;
}
break;
}
break;
}
case 2: {
int y;
cout << "1、两点之间的距离\t2、点到直线的距离\t3、点到平面的距离" << endl;
cout << endl;
cin >> y;
if (y == 1) {
Dian n;
n.juli();
}
if (y == 2) {
Xian l;
l.dianxianjuli();
}
if (y == 3) {
Mian s;
s.dianmianjuli();
}
break;
}
case 3: {
cout << "1、空间直线的单位方向向量\t2、空间平面的单位法向量" << endl;
cout << endl;
int y;
cin >> y;
if (y == 1) {
Xian l;
l.danweixiangliang();
}
if (y == 2) {
Mian s;
s.setm();//赋值
s.danweifaxiangliang();//单位法向量
}
break;
}

case 4: {
cout << "1、点线关系\t2、线线关系\t3、点面关系\t4、线面关系\t5、面面关系" << endl;
cout << endl;
int y;
cin >> y;
if (y == 1) {
Xian l;
l.dainxianweizhi();
}
if (y == 2) {
Xian l;
l.xianxianweizhi();
}
if (y == 3) {
Mian s;
s.dianmianweizhi();
}
if (y == 4) {
Mian s;
s.xianmianweizhi();
}
if (y == 5) {
Mian s;
s.mianmianweizhi();
}
break; }
case 5:cout << "已退出 "; exit(0);
}
}
return 0;
}

标签:cout,小学,void,getx,gety,getz,m1
来源: https://www.cnblogs.com/zbw-m/p/16460632.html