-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task 1,2,3. Шумов #13
Open
krozzzis
wants to merge
29
commits into
LifeStyle28:main
Choose a base branch
from
krozzzis:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
83ee753
Some work
krozzzis 2d67764
Update matrix.hpp
krozzzis d2c2801
Some work
krozzzis 2118de7
Update circular_queue.hpp
krozzzis 81211c3
Update circular_queue.cpp
krozzzis d302f1c
Update circular_queue.cpp
krozzzis d12ebae
Update circular_queue.hpp
krozzzis 481a4eb
Update circular_queue.hpp
krozzzis 3c253f1
Update circular_queue.cpp
krozzzis 7fa1635
Update circular_queue.cpp
krozzzis 5ba759c
Update circular_queue.cpp
krozzzis 58a9af0
Update circular_queue.hpp
krozzzis 0e10861
Update circular_queue.cpp
krozzzis fce891d
Update circular_queue.hpp
krozzzis 5024b9a
Update circular_queue.cpp
krozzzis 14edbc6
Update circular_queue.hpp
krozzzis 644faa7
Update circular_queue.hpp
krozzzis e760e90
Update circular_queue.cpp
krozzzis 4ed07fd
Update circular_queue.cpp
krozzzis c31ef71
Update circular_queue.hpp
krozzzis b6e6b78
Update circular_queue.cpp
krozzzis 7573515
Update circular_queue.cpp
krozzzis 42065b0
Update circular_queue.hpp
krozzzis 92a8a4d
Update circular_queue.hpp
krozzzis 1fc3f72
Update circular_queue.cpp
krozzzis fa709e7
Update circular_queue.hpp
krozzzis 6edb722
Update circular_queue.hpp
krozzzis 3eef040
Update README.md
krozzzis 46548c5
Update matrix.hpp
krozzzis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,77 @@ | ||
#include "matrix.hpp" | ||
|
||
#include <stdexcept> | ||
|
||
Matrix::Matrix(int numRows, int numCols) | ||
{ | ||
// your implementation here | ||
using namespace std; | ||
|
||
Matrix::Matrix(int rows, int cols) { | ||
if (rows < 0 || cols < 0) { | ||
throw out_of_range(""); | ||
} | ||
if (rows == 0 || cols == 0) { | ||
num_rows = 0; | ||
num_cols = 0; | ||
data.clear(); | ||
} else { | ||
num_rows = rows; | ||
num_cols = cols; | ||
data.assign(rows, vector<int>(cols, 0)); | ||
} | ||
} | ||
|
||
void Matrix::Reset(int numRows, int numCols) | ||
{ | ||
// your implementation here | ||
void Matrix::Reset(int rows, int cols) { | ||
if (rows < 0 || cols < 0) { | ||
throw out_of_range(""); | ||
} | ||
if (rows == 0 || cols == 0) { | ||
num_rows = 0; | ||
num_cols = 0; | ||
data.clear(); | ||
} else { | ||
num_rows = rows; | ||
num_cols = cols; | ||
data.assign(rows, vector<int>(cols, 0)); | ||
} | ||
} | ||
|
||
int& Matrix::At(int row, int col) | ||
{ | ||
// your implementation here | ||
int Matrix::At(int row, int col) const { | ||
if (row < 0 || row >= num_rows || col < 0 || col >= num_cols) { | ||
throw out_of_range(""); | ||
} | ||
return data[row][col]; | ||
} | ||
|
||
const int& Matrix::At(int row, int col) const | ||
{ | ||
// your implementation here | ||
int& Matrix::At(int row, int col) { | ||
if (row < 0 || row >= num_rows || col < 0 || col >= num_cols) { | ||
throw out_of_range(""); | ||
} | ||
return data[row][col]; | ||
} | ||
|
||
int Matrix::GetRows() const | ||
{ | ||
// your implementation here | ||
int Matrix::GetRows() const { | ||
return num_rows; | ||
} | ||
|
||
int Matrix::GetCols() const | ||
{ | ||
// your implementation here | ||
int Matrix::GetCols() const { | ||
return num_cols; | ||
} | ||
|
||
bool Matrix::operator==(const Matrix& m2) | ||
{ | ||
// your implementation here | ||
bool operator==(const Matrix& lhs, const Matrix& rhs) { | ||
return lhs.num_rows == rhs.num_rows && lhs.num_cols == rhs.num_cols && lhs.data == rhs.data; | ||
} | ||
|
||
bool Matrix::operator!=(const Matrix& m2) | ||
{ | ||
// your implementation here | ||
bool operator!=(const Matrix& lhs, const Matrix& rhs) { | ||
return !(lhs == rhs); | ||
} | ||
|
||
Matrix Matrix::operator+(const Matrix& m2) | ||
{ | ||
// your implementation here | ||
Matrix operator+(const Matrix& lhs, const Matrix& rhs) { | ||
if (lhs.GetRows() != rhs.GetRows() || lhs.GetCols() != rhs.GetCols()) { | ||
throw invalid_argument(""); | ||
} | ||
Matrix result(lhs.GetRows(), lhs.GetCols()); | ||
for (int i = 0; i < lhs.GetRows(); ++i) { | ||
for (int j = 0; j < lhs.GetCols(); ++j) { | ||
result.At(i, j) = lhs.At(i, j) + rhs.At(i, j); | ||
} | ||
} | ||
return result; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
#pragma once | ||
#include <iostream> | ||
#include <vector> | ||
#include <stdexcept> | ||
|
||
class Matrix | ||
{ | ||
class Matrix { | ||
public: | ||
Matrix() = default; | ||
Matrix(int numRows, int numCols); | ||
Matrix() : num_rows(0), num_cols(0) {} | ||
explicit Matrix(int rows, int cols); | ||
|
||
Matrix(const Matrix& other) = default; | ||
Matrix& operator=(const Matrix& other) = default; | ||
|
||
Matrix(Matrix&& other) noexcept : num_rows(other.num_rows), num_cols(other.num_cols), data(std::move(other.data)) { | ||
other.num_rows = 0; | ||
other.num_cols = 0; | ||
} | ||
Matrix& operator=(Matrix&& other) noexcept { | ||
if (this != &other) { | ||
num_rows = other.num_rows; | ||
num_cols = other.num_cols; | ||
data = std::move(other.data); | ||
other.num_rows = 0; | ||
other.num_cols = 0; | ||
} | ||
return *this; | ||
} | ||
|
||
void Reset(int numRows, int numCols); | ||
void Reset(int rows, int cols); | ||
int At(int row, int col) const; | ||
int& At(int row, int col); | ||
const int& At(int row, int col) const; | ||
int GetRows() const; | ||
int GetCols() const; | ||
|
||
bool operator==(const Matrix& m2); | ||
bool operator!=(const Matrix& m2); | ||
Matrix operator+(const Matrix& m2); | ||
friend bool operator==(const Matrix& lhs, const Matrix& rhs); | ||
friend bool operator!=(const Matrix& lhs, const Matrix& rhs); | ||
friend Matrix operator+(const Matrix& lhs, const Matrix& rhs); | ||
|
||
private: | ||
int num_rows; | ||
int num_cols; | ||
std::vector<std::vector<int>> data; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,70 @@ | ||
#include "figures.hpp" | ||
#include <cmath> | ||
|
||
static constexpr double PI = 3.14; | ||
Rect::Rect(double a, double b) : width(a), height(b) {} | ||
|
||
FigureType Rect::Type() const { | ||
return FigureType::RECTANGLE; | ||
} | ||
|
||
double Rect::Perimeter() const { | ||
return 2 * (width + height); | ||
} | ||
|
||
double Rect::Area() const { | ||
return width * height; | ||
} | ||
|
||
Triangle::Triangle(double side_a, double side_b, double side_c) | ||
: a(side_a), b(side_b), c(side_c) {} | ||
|
||
FigureType Triangle::Type() const { | ||
return FigureType::TRIANGLE; | ||
} | ||
|
||
double Triangle::Perimeter() const { | ||
return a + b + c; | ||
} | ||
|
||
double Triangle::Area() const { | ||
double s = Perimeter() / 2; | ||
return std::sqrt(s * (s - a) * (s - b) * (s - c)); | ||
} | ||
|
||
Circle::Circle(double r) : radius(r) {} | ||
|
||
FigureType Circle::Type() const { | ||
return FigureType::CIRCLE; | ||
} | ||
|
||
double Circle::Perimeter() const { | ||
return 2 * PI * radius; | ||
} | ||
|
||
double Circle::Area() const { | ||
return PI * radius * radius; | ||
} | ||
|
||
|
||
std::unique_ptr<Figure> make_figure(FigureType type, double a, double b, double c) { | ||
if (a < 0 || b < 0 || c < 0) { | ||
throw LessThanZeroParam(""); | ||
} | ||
|
||
switch (type) { | ||
case FigureType::RECTANGLE: | ||
return std::make_unique<Rect>(a, b); | ||
|
||
case FigureType::TRIANGLE: | ||
if (a + b <= c || b + c <= a || a + c <= b) { | ||
throw WrongTriangle(""); | ||
} | ||
return std::make_unique<Triangle>(a, b, c); | ||
|
||
case FigureType::CIRCLE: | ||
return std::make_unique<Circle>(a); | ||
|
||
default: | ||
return nullptr; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,47 @@ | ||
#include "circular_queue.hpp" | ||
#include <stdexcept> | ||
|
||
CircularQueue::CircularQueue(size_t size) | ||
{ | ||
// your implementation here | ||
CircularQueue::CircularQueue(size_t size) : capacity(size), size(0), front(0), rear(0) { | ||
buffer = new int[size]; | ||
} | ||
|
||
bool CircularQueue::Push(int value) | ||
{ | ||
// your implementation here | ||
bool CircularQueue::Push(int value) { | ||
if (Full()) { | ||
return false; | ||
} | ||
buffer[rear] = value; | ||
rear = (rear + 1) % capacity; | ||
size++; | ||
return true; | ||
} | ||
|
||
bool CircularQueue::Pop() | ||
{ | ||
// your implementation here | ||
bool CircularQueue::Pop() { | ||
if (Empty()) { | ||
return false; | ||
} | ||
front = (front + 1) % capacity; | ||
size--; | ||
return true; | ||
} | ||
|
||
int CircularQueue::Front() const | ||
{ | ||
// your implementation here | ||
int CircularQueue::Front() const { | ||
if (Empty()) { | ||
return -1; | ||
} | ||
return buffer[front]; | ||
} | ||
|
||
int CircularQueue::Back() const | ||
{ | ||
// your implementation here | ||
int CircularQueue::Back() const { | ||
if (Empty()) { | ||
return -1; | ||
} | ||
return buffer[(rear - 1 + capacity) % capacity]; | ||
} | ||
|
||
bool CircularQueue::Empty() const | ||
{ | ||
// your implementation here | ||
bool CircularQueue::Empty() const { | ||
return size == 0; | ||
} | ||
|
||
bool CircularQueue::Full() const | ||
{ | ||
// your implementation here | ||
bool CircularQueue::Full() const { | ||
return size == capacity; | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нужно позаботиться о деаллокации памяти, тут утечка
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
исправляй, отправляй снова