Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
418 changes: 418 additions & 0 deletions module-1/homework/BigInteger/biginteger.cpp

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions module-1/homework/BigInteger/biginteger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <vector>
#include <string>
#include <iostream>

class BigInteger {

private:
std::vector<int> numb ;
int zn = 1;

public:

BigInteger();
BigInteger(int);
BigInteger(std::string);

BigInteger& plus(BigInteger& x, const BigInteger& y);
BigInteger& minus(BigInteger& x, const BigInteger& y);

BigInteger operator+(const BigInteger& other);
BigInteger operator%(BigInteger other);
BigInteger operator-(BigInteger other);
BigInteger operator*(const BigInteger& other);
BigInteger operator/(const BigInteger& other);

BigInteger& operator=(BigInteger other);
BigInteger& operator=(int other);

BigInteger& operator++();
BigInteger operator++(int);
BigInteger& operator--();
BigInteger operator--(int);
BigInteger& operator-();

BigInteger& operator+=(const BigInteger& other);
BigInteger& operator%=(const BigInteger& other);
BigInteger& operator-=(const BigInteger& other);
BigInteger& operator*=(const BigInteger& other);
BigInteger& operator/=(const BigInteger& other);

bool operator<(const BigInteger& other);
bool operator>(const BigInteger& other);
bool operator==(const BigInteger& other);
bool operator<=(const BigInteger& other);
bool operator>=(const BigInteger& other);
bool operator!=(const BigInteger& other);

BigInteger& operator=(std::string other);

operator bool();

BigInteger operator*(int other);
BigInteger operator/(int other);
BigInteger& operator/=(int other);
BigInteger operator%=(int other);
BigInteger operator==(int other);


friend std::ostream& operator<<(std::ostream&, const BigInteger&);
friend std::istream& operator>>(std::istream&, BigInteger&);

std::string toString() const;

};
9 changes: 9 additions & 0 deletions module-1/homework/Geometry/hierarchy/circle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "circle.h"

Circle::Circle(const Point& center, const double& r)
: Ellipse(center, center, r * 2.0) {}

double Circle::radius() const {
return (rade/2);
}

12 changes: 12 additions & 0 deletions module-1/homework/Geometry/hierarchy/circle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include "ellipse.h"

class Circle : public Ellipse{
public:


Circle(const Point& center, const double& rad);

double radius() const;

};
110 changes: 110 additions & 0 deletions module-1/homework/Geometry/hierarchy/ellipse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include "ellipse.h"

Ellipse::Ellipse(const Point& a1, const Point& a2, const double& rad)
: f1(a1), f2(a2), rade(rad) {}

std::pair<Point,Point> Ellipse::focuses() const{
return (std::pair<Point, Point>(f1,f2));
}

std::pair<Line, Line> Ellipse::directrices() const{
return(std::pair<Line, Line>(Line(Point(1, aa()/e), Point(2, aa()/e)), Line(Point(1, -aa()/e), Point(2, -aa()/e))));
}

double Ellipse::eccentricity() const{
return e;
}

Point Ellipse::center() const{
return((f1+f2)/2);
}

bool Ellipse::operator==(const Shape& another) const{
const auto* another2 = dynamic_cast<const Ellipse*>(&another);
bool ans = 0;
if ((this->f1 == another2->f1) && (this->f2 == another2->f2) && (this->rade == another2->rade)){
ans = 1;
}
return ans;
}

bool Ellipse::isCongruentTo(const Shape& another) const{
const auto* another2 = dynamic_cast<const Ellipse*>(&another);
bool ans = 0;
if ((this->f1-this->f2 == another2->f1-another2->f2) && (this->rade == another2->rade)){
ans = 1;
}
return ans;
}

bool Ellipse::isSimilarTo(const Shape& another) const{
const auto* another2 = dynamic_cast<const Ellipse*>(&another);
bool ans = 0;
if (Vector(this->f1,this->f2).lengh() / Vector(another2->f1,another2->f2).lengh()
== this->rade / another2->rade){
ans = 1;
}
return ans;
}

bool Ellipse::containsPoint(const Point& another) const{
bool convex = false;
if (Vector(another, f1).lengh() + Vector(another, f2).lengh() <= rade) {
convex = true;
}
return convex;
}

Shape& Ellipse::rotate(const Point& center, const double& angle){
const auto* another2 = dynamic_cast<const Ellipse*>(this);
double rad = angle * pi / 180.0;
Vector g2;
Vector g = Vector(f11(), center);
g2.x = g.x*cos(rad) - g.y*sin(rad);
g2.y = g.x*sin(rad) + g.y*cos(rad);
f1.x+=g2.x;
f1.y+=g2.y;
g = Vector(f2, center);
g2.x = g.x*cos(rad) - g.y*sin(rad);
g2.y = g.x*sin(rad) + g.y*cos(rad);
f2.x+=g2.x;
f2.y+=g2.y;
return *this;
}

Shape& Ellipse::reflex(const Point& center) {
this->rotate(center, 180);
return *this;
}

Shape& Ellipse::reflex(const Line& axis){
Point proj = axis.getProjection(f1);
f1 += (proj - f1) * 2;
proj = axis.getProjection(f2);
f2 += (proj - f2) * 2;
return *this;
}

Shape& Ellipse::scale(const Point& center, const double& coefficient){
f1 += (center - f1) * coefficient;
f2 += (center - f2) * coefficient;
return *this;
}

double Ellipse::perimeter() const {
return 4 * (pi * aa() * bb() + (aa() - bb())) / (aa() + bb());
}

double Ellipse::cc() const {
return Vector(f1,f2).lengh()/2;
}
double Ellipse::bb() const {
return sqrt(aa()*aa() - cc()*cc());
}
double Ellipse::aa() const {
return rade/2;
}

double Ellipse::area() const {
return pi * aa() * bb();
}
38 changes: 38 additions & 0 deletions module-1/homework/Geometry/hierarchy/ellipse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
#include "shape.h"

class Ellipse : public Shape {
public:

Ellipse(const Point& f1, const Point& f2, const double& rad);



std::pair<Point,Point> focuses() const;// - фокусы эллипса
std::pair<Line, Line> directrices() const;// - пара директрис эллипса
double eccentricity() const;// - эксцентриситет
Point center() const;

double perimeter() const override;
double area() const override;
bool operator==(const Shape& another) const override;
bool isCongruentTo(const Shape& another) const override;
bool isSimilarTo(const Shape& another) const override;
bool containsPoint(const Point& point) const override;
Shape& rotate(const Point& center, const double& angle) override;
Shape& reflex(const Point& center) override;
Shape& reflex(const Line& axis) override;
Shape& scale(const Point& center, const double& coefficient) override;

Point f11() {return f1;};
Point f22() {return f2;};
double ra_de() {return rade;};

protected:
Point f1, f2;
double rade;
double cc() const;
double bb() const;
double aa() const;
double e = cc()/aa();
};
22 changes: 22 additions & 0 deletions module-1/homework/Geometry/hierarchy/line.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "line.h"

Line::Line(const Point& x, const Point& y){
a1 = x;
a2 = y;
}

bool Line::operator==(const Line& p) const{
return ((this->a1-this->a2).abc() == (p.a1 - p.a2).abc());
}

bool Line::operator!=(const Line& p) const{
return (!((this->a1-this->a2).abc() == (p.a1 - p.a2).abc()));
}

Point Line::getProjection(const Point& point) const {
double m = a1.x - a2.x, p = a1.y - a2.y;
double x = a1.x, y = a1.y;
double t = (m * point.x + p * point.y - m * x - p * y) / (m*m + p*p);

return Point(m * t + x, p * t + y);
}
18 changes: 18 additions & 0 deletions module-1/homework/Geometry/hierarchy/line.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "point.h"

class Line{
public:

Line(const Point& a1, const Point& a2);

bool operator==(const Line& p) const;
bool operator!=(const Line& p) const;

Point getProjection(const Point& point) const;

protected:
Point a1;
Point a2;

};
86 changes: 86 additions & 0 deletions module-1/homework/Geometry/hierarchy/point.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "point.h"

Point::Point(){}

Point::Point(double a, double b){
this->x = a;
this->y = b;
}

Point& Point::operator=(const Point& a) {
this->y = a.y;
this->x = a.x;
return *this;
}

bool Point::operator==(const Point& a) const{
return ((this->x - a.x < 0.00001) && (this->x - a.x > -0.00001) &&
(this->y - a.y < 0.00001) && (this->y - a.y > -0.00001));
}

bool Point::operator!=(const Point& a) const{
return (!((this->x - a.x < 0.00001) && (this->x - a.x > -0.00001) &&
(this->y - a.y < 0.00001) && (this->y - a.y > -0.00001)));
}

Point Point::operator-(const Point& a) const{
Point b;
b.x = this->x - a.x;
b.y = this->y - a.y;
return b;
}

Point Point::operator+(const Point& a) const{
Point b;
b.x = this->x + a.x;
b.y = this->y + a.y;
return b;
}

Point& Point::operator+=(const Point& a){
this->x = this->x + a.x;
this->y = this->y + a.y;
return *this;
}

Point Point::operator*(const double& a) const{
Point b;
b.x = this->x * a;
b.y = this->y * a;
return b;
}

Point Point::operator/(const double& a) const{
Point b;
b.x = this->x / a;
b.y = this->y / a;
return b;
}

Point& Point::rotate_1(const Point& g2){
x+=g2.x;
y+=g2.y;
return *this;
}

Point Point::abc() const{
Point b = *this;
if (b.x<0) b.x*=-1;
if (b.y<0) b.y*=-1;
return b;
}

Vector::Vector(){}

Vector::Vector(const Point& a, const Point& b){
x = a.x - b.x;
y = a.y - b.y;
}

bool isConvexv(const Vector& a, const Vector& b){
return (a.x*b.y-a.y*b.x > 0);
}

double Vector::lengh(){
return(sqrt(x*x + y*y));
}
Loading