Created
June 23, 2019 12:39
-
-
Save daniilgri/b2bffefc419364ea808d33c15df856d8 to your computer and use it in GitHub Desktop.
Classy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "Point.h" | |
#include "Parallelogram.h" | |
#include "Parallelepiped.h" | |
using namespace std; | |
int main() | |
{ | |
Point point1(0, 0); | |
Point point2(2, 3); | |
Point point3(6, 0); | |
Parallelogram parallelogram(point1, point2, point3); | |
cout << "Area: " << parallelogram.getArea() << endl; | |
cout << "Angle: " << parallelogram.getAngle() << endl; | |
parallelogram.out(cout); | |
parallelogram.putAngle(20); | |
parallelogram.out(cout); | |
parallelogram.getAngle(); | |
/* | |
Point p1(0, 0, 0); | |
Point p2(2, 3, 0); | |
Point p3(4, 0, 0); | |
Point p4(0, 0, 4); | |
Parallelepiped paralpid(p1, p2, p3, p4); | |
cout << "Area: " << paralpid.getArea() << endl; | |
cout << "Area: " << paralpid.getArea() << endl; | |
cout << "Capacity: " << paralpid.getCapacity() << endl;*/ | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Parallelepiped.h" | |
#include "Parallelogram.h" | |
Parallelepiped::Parallelepiped() | |
{ | |
} | |
Parallelepiped::Parallelepiped(Point p1, Point p2, Point p3, Point p4) : Parallelogram(p1, p2, p3) | |
{ | |
this->p4 = p4; | |
} | |
double Parallelepiped::getArea() | |
{ | |
double s = 0; | |
s += Parallelogram::getArea() * 2; | |
s += (p4.z - p1.z) * (sqrt(pow(p3.x - p1.x, 2) + pow(p3.y - p1.y, 2)) * 2 + sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2)) * 2); | |
return s; | |
} | |
double Parallelepiped::getCapacity() | |
{ | |
return Parallelogram::getArea()*(p4.z - p1.z); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "Point.h" | |
#include "Parallelogram.h" | |
class Parallelepiped : Parallelogram | |
{ | |
public: | |
Parallelepiped(); | |
Parallelepiped(Point p1, Point p2, Point p3, Point p4); | |
double getArea(); | |
double getCapacity(); | |
protected: | |
Point p4; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Parallelogram.h" | |
#include "Point.h" | |
#include <iostream> | |
#include <math.h> | |
constexpr auto PI = 3.14159265; | |
using namespace std; | |
Parallelogram::Parallelogram() | |
{ | |
} | |
Parallelogram::Parallelogram(Point p1, Point p2, Point p3) | |
{ | |
this->p1 = p1; | |
this->p2 = p2; | |
this->p3 = p3; | |
} | |
Parallelogram::Parallelogram(Point p1, Point p2, int side) | |
{ | |
this->p1 = p1; | |
this->p2 = p2; | |
this->p3 = Point(p1.x + side, p1.y); | |
} | |
void Parallelogram::out(ostream& streamOut) | |
{ | |
streamOut << "(" << p2.x << "," << p2.y << ")" << " -------------" << "(" << p3.x + (p2.x - p1.x) << "," << p2.y << ")\n" | |
" / / \n" | |
" / / \n" | |
<< "(" << p1.x << "," << p1.y << ")" << "-------------" << "(" << p3.x << "," << p3.y << ")\n"; | |
} | |
double Parallelogram::getArea() | |
{ | |
return (p2.y - p1.y)*(p3.x - p2.x); | |
} | |
int Parallelogram::getAngle() | |
{ | |
double otherSide = sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2)); | |
return int(asin(getArea() / (otherSide * p3.x - p2.x)) * 180.0 / PI); | |
} | |
void Parallelogram::putAngle(int angle) | |
{ | |
double temp_x = (p2.y - p1.y) / tan(angle * PI / 180.0); | |
double temp2_x = temp_x - (p2.x - p1.x); | |
p2.x = temp_x; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "Point.h" | |
#include <iostream> | |
using namespace std; | |
class Parallelogram | |
{ | |
public: | |
Parallelogram(); | |
Parallelogram(Point p1, Point p2, Point p3); | |
Parallelogram(Point p1, Point p2, int side); | |
void out(ostream& streamOut); | |
double getArea(); | |
int getAngle(); | |
void putAngle(int angle); | |
protected: | |
Point p1, p2, p3; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Point.h" | |
Point::Point() | |
{ | |
} | |
Point::Point(int x, int y, int z) | |
{ | |
this->x = x; | |
this->y = y; | |
this->z = z; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
class Point | |
{ | |
public: | |
int x = 0, y = 0, z = 0; | |
Point(); | |
Point(int x, int y, int z = 0); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment