#include<iostream>
#include <math.h>
#include<fstream>
using namespace std;
//==============================================================================
class line
{
private:
double x,y,z,x2,y2,z2;
public:
line();
line(double X,double X2,double Y, double Y2,double Z,double Z2);
~line(){cout<<"\n[Line] Destructed! \n";}
double getx() {return x;}
double gety() {return y;}
double getx2() {return x2;}
double gety2() {return y2;}
double getz() {return z;}
double getz2() {return z2;}
virtual void out();
virtual double calculate() {return sqrt(((x2-x)*(x2-x))+((y2-y)*(y2-y))+((z2-z)*(z2-z)));}
};
//==============================================================================
line::line(double X,double X2,double Y, double Y2,double Z,double Z2):x(X),y(Y),z(Z),x2(X2),y2(Y2),z2(Z2)
{
cout<<"\n[Line initialization completed!]\n";
}
//==============================================================================
line::line()
{
cout<<"===constructing line===\n\n";
cout<<"coordinat x1: ";cin>>x;cout<<"\n";
cout<<"coordinat y1: ";cin>>y;cout<<"\n";
cout<<"coordinat x2: ";cin>>x2;cout<<"\n";
cout<<"coordinat y2: ";cin>>y2;cout<<"\n";
cout<<"coordinat z1: ";cin>>z;cout<<"\n";
cout<<"coordinat z2: ";cin>>z2;cout<<"\n";
}
//==============================================================================
void line::out()
{ cout<<"--------------------------------\n"<<"=====line coordinats=====\n";
cout<<"("<<x<<","<<y<<","<<z<<") U ("<<x2<<","<<y2<<","<<z2<<")\n";
cout<<"--------------------------------\n";}
//==============================================================================
//==============================================================================
class triangle : public line
{
protected:
double tx,ty,tz;
public:
triangle();
triangle(double X,double Y, double Z,double X2,double Y2,double Z2,double TX,double TY,double TZ);
~triangle(){cout<<"\n[Triangle] Destructed! \n";};
double getTx() const {return tx;}
double getTy() const {return ty;}
double getTz() const {return tz;}
void settx(double TX) {tx = TX;}
void setty(double TY) {ty = TY;}
virtual double calculate();
virtual void out();
};
//==============================================================================
triangle::triangle()
{
cout<<"===constructing triangle===\n\n";
cout<<"coordinat tx: ";cin>>tx;cout<<"\n";
cout<<"coordinat ty: ";cin>>ty;cout<<"\n";
cout<<"coordinat tz: ";cin>>tz;cout<<"\n";
}
//==============================================================================
triangle::triangle(double X,double Y, double Z,double X2,double Y2,double Z2,double TX,double TY,double TZ):line(X,Y,Z,X2,Y2,Z2),tx(TX),ty(TY),tz(TZ)
{
cout<<"[Triangle initialization complited!]\n";
}
//==============================================================================
void triangle::out()
{
cout<<"--------------------------------\n";
line::out();
cout<<"aditional point for triangle: \n";
cout<<"tx = "<<tx<<"\n";
cout<<"ty = "<<ty<<"\n";
cout<<"tz = "<<tz<<"\n";
cout<<"--------------------------------\n";
}
//==============================================================================
double triangle::calculate()
{
double lenght1,lenght2,lenght3,rezult,halfperim, nx,ny,nz,nx2,ny2,nz2;
nx = getx();ny = gety();nz= getz();nx2 = getx2();ny2 = gety2();
nz2 = getz2();
//-------------------------------------------------------------------------------
lenght1 = sqrt(((nx2-nx)*(nx2-nx))+((ny2-ny)*(ny2-ny))+((nz2-nz)*(nz2-nz)));
lenght2 = sqrt(((nx2-tx)*(nx2-tx))+((ny2-ty)*(ny2-ty))+((nz2-tz)*(nz2-tz)));
lenght3 = sqrt(((nx-tx)*(nx-tx))+((ny-ty)*(ny-ty))+((nz-tz)*(nz-tz)));
//-------------------------------------------------------------------------------
halfperim = (lenght1 + lenght2 + lenght3)/2;
//-----------------------------------------------------------------------------------------
rezult = sqrt(halfperim*(halfperim-lenght1)*(halfperim-lenght2)*(halfperim-lenght3));
//-----------------------------------------------------------------------------------------
return rezult;
}
////==============================================================================
class prism: public triangle
{
protected:
double h;
public:
prism();
prism(double H,double X,double Y, double Z,double X2,double Y2,double Z2,double TX,double TY,double TZ);
~prism(){cout<<"\n[Prism] Destructed! \n";};
virtual void out();
double getH(){return h;}
virtual double calculate();
friend double operator +(prism &prism1;,prism&prism2;);
friend ostream &operator;<<(fstream&f,const prism &prism1;);
};
ostream& operator<<(ostream &f, const prism &prism1;)
{
f << prism1.h << endl;
f << prism1.tz << endl;
return f;
}
//==============================================================================
prism::prism()
{
cout<<"height lenght: ";cin>>h;
}
//==============================================================================
prism::prism(double H,double X,double Y, double Z,double X2,double Y2,double Z2,double TX,double TY,double TZ):triangle(X,Y,Z,X2,Y2,Z2,TX,TY,TZ),h(H)
{
cout<<"[Prism initialization complited!]\n";
}
//==============================================================================
double operator +(prism &prism1;,prism&prism2;)
{
double temp;
temp = prism1.calculate() + prism2.calculate();
return temp;
}
//==============================================================================
double prism::calculate()
{
double lenght1,lenght2,lenght3,rezult,halfperim, nx,ny,nz,nx2,ny2,nz2,ntx,nty,ntz;
nx = getx();ny = gety();nz= getz();nx2 = getx2();ny2 = gety2();ntx = getTx();nty = getTy();ntz = getTz();nz2 = getz2();
//--------------------------------------------------------------------------------------
lenght1 = sqrt(((nx2-nx)*(nx2-nx))+((ny2-ny)*(ny2-ny))+((nz2-nz)*(nz2-nz)));
lenght2 = sqrt(((nx2-ntx)*(nx2-ntx))+((ny2-nty)*(ny2-nty))+((nz2-ntz)*(nz2-ntz)));
lenght3 = sqrt(((nx-ntx)*(nx-ntx))+((ny-nty)*(ny-nty))+((nz-ntz)*(nz-ntz)));
//--------------------------------------------------------------------------------------
halfperim = (lenght1 + lenght2 + lenght3)/2;
//--------------------------------------------------------------------------------------------
rezult = (sqrt(halfperim*(halfperim-lenght1)*(halfperim-lenght2)*(halfperim-lenght3)))*h;
//--------------------------------------------------------------------------------------------
return rezult;
}
//==============================================================================
void prism::out()
{
cout<<"--------------------------------\n"<<"=====Prism coordinats=====\n";
triangle::out();
cout<<"H = "<<h<<"\n";
cout<<"--------------------------------\n";
}
//==============================================================================
void main()
{
ofstream fout;
double rez;
fout.open("rezultfile.txt");
//------------------------------------------------------------------------
//cout<<"--------------------------------\n"<<"push any button...";cin.get();
// line Line1(1,2,3,5,4,3),Line2(1,3,2,4,5,3),total(0,0,0,0,0,0);
// total = Line1 + Line2;
// Line1.out();cout<<"+\n";
// Line2.out();
// cout<<"rezult: \n";
// total.out();
// fout<<total;
// fout.close();
////==============================================================================
//cout<<"--------------------------------\n"<<"push any button...";cin.get();
////--------------------------------------------------------------
// triangle triangle1;
// triangle1.out();
// rez = triangle1.calculate();
// cout<<"triangle area: "<<rez<<"\n\n";
////--------------------------------------------------------------
//cout<<"--------------------------------\n"<<"push any button...";cin.get();
// prism prism1;
// prism1.out();
// rez = prism1.calculate(rez);
// cout<<"prism area: "<<rez<<"\n\n";
////=================================================================================================
//cout<<"--------------------------------\n"<<"push any button...";cin.get();
// line line2(1,2,3,5,8,4);
// line2.out();
// rez = line2.calculate();
// cout<<"line 2 lenght: "<<rez<<"\n\n";
// cout<<"--------------------------------\n"<<"push any button...";cin.get();
////--------------------------------------------------------
// triangle triangle2(1,2,3,5,8,4,3,5,3);
// triangle2.out();
// rez = triangle2.calculate();
// cout<<"triangle 2 area: "<<rez<<"\n\n";
////--------------------------------------------------------
cout<<"--------------------------------\n"<<"push any button...";cin.get();
prism prism1(1,2,1,2,3,4,3,2,1,2),prism2(1,2,3,5,8,4,4,6,3,7);
rez = prism1 + prism2;
cout<<"rez"<<rez;
//--------------------------------------------------------
}
//==============================================================================Add a code snippet to your website: www.paste.org