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
Empty file added .vs/CMake Overview
Empty file.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": "x64-Debug (по умолчанию)"
}
10 changes: 10 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ExpandedNodes": [
"",
"\\include",
"\\src",
"\\tests"
],
"SelectedNode": "\\tests\\runner_tests.cpp",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/h01_cpp_basics-UnluckyDen/v16/.suo
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## ФИО студента

**Пожалуйста, добавьте сюда свое ФИО**
Гладких Даниил Сергеевич

## Описание задания

Expand Down
25 changes: 18 additions & 7 deletions src/author.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
// 1. реализуйте конструктор ...
Author::Author(const std::string &full_name, int age, Sex sex) {
// валидация аргументов (здесь был Рамиль)
if (age < kMinAuthorAge) {
throw std::invalid_argument("Author::age must be greater than " + std::to_string(kMinAuthorAge));
}

if (full_name.empty()) {
throw std::invalid_argument("Author::full_name must not be empty");
}
if (age < kMinAuthorAge)
{
throw std::invalid_argument("Author::age must be greater than " + std::to_string(kMinAuthorAge));
}
else
{
age_ = age;
}

if (full_name.empty())
{
throw std::invalid_argument("Author::full_name must not be empty");
}
else
{
full_name_ = full_name;
}
sex_ = sex;
// Tip 1: инициализируйте поля
}

Expand Down
46 changes: 28 additions & 18 deletions src/book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,37 @@ Book::Book(const std::string &title,
const std::vector<Author> &authors) {

// валидация аргументов
if (title.empty()) {
throw std::invalid_argument("Book::title cannot be empty");
}

if (content.empty()) {
throw std::invalid_argument(
"Book::content cannot be empty");
}

if (authors.empty()) {
throw std::invalid_argument("Book::authors cannot be empty");
}

// Tip 1: остались слезы на щеках, осталось лишь инициализировать поля ...
if (title.empty()) {
throw std::invalid_argument("Book::title cannot be empty");
}

if (content.empty()) {
throw std::invalid_argument(
"Book::content cannot be empty");
}

if (authors.empty()) {
throw std::invalid_argument("Book::authors cannot be empty");
}
title_ = title;
content_ = content;
genre_ = genre;
publisher_ = publisher;
authors_ = authors;
}


// 2. реализуйте метод ...
bool Book::AddAuthor(const Author &author) {
// здесь мог бы быть ваш сногсшибающий код ...
// Tip 1: для поиска дубликатов можно использовать цикл for-each
return false;
bool Book::AddAuthor(const Author& author) {
bool flag = true;
for (const Author& elem : authors_) {
if (elem.GetFullName() == author.GetFullName()) {
flag = false;
break;
}
}
if (flag) authors_.push_back(author);
return flag;
}

// РЕАЛИЗОВАНО
Expand Down
66 changes: 46 additions & 20 deletions src/book_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,63 @@
#include <stdexcept> // invalid_argument

// 1. реализуйте функцию ...
ResizeStorageStatus resize_storage(Book *&storage, int size, int new_capacity) {
// здесь мог бы быть ваш разносторонний и многогранный код ...
// Tip 1: проведите валидацию аргументов функции
// Tip 2: не забудьте высвободить ранее выделенную память под хранилище
return ResizeStorageStatus::SUCCESS;
ResizeStorageStatus resize_storage(Book*& storage, int size, int new_capacity) {
// здесь мог бы быть ваш разносторонний и многогранный код ...
// Tip 1: проведите валидацию аргументов функции
if (storage == nullptr)
return ResizeStorageStatus::NULL_STORAGE;
if (new_capacity <= size)
return ResizeStorageStatus::INSUFFICIENT_CAPACITY;
if (size < 0)
return ResizeStorageStatus::NEGATIVE_SIZE;
// Tip 2: не забудьте высвободить ранее выделенную память под хранилище

Book* newStorage = storage;
storage = new Book[new_capacity];

std::copy(newStorage, newStorage + size, storage);
delete[] newStorage;


return ResizeStorageStatus::SUCCESS;
}

// 2. реализуйте конструктор ...
BookStore::BookStore(const std::string &name) : name_{name} {
// валидация аргумента
if (name.empty()) {
throw std::invalid_argument("BookStore::name must not be empty");
}
BookStore::BookStore(const std::string& name) : name_{ name } {
// валидация аргумента
if (name.empty()) {
throw std::invalid_argument("BookStore::name must not be empty");
}

// здесь мог бы быть ваш сотрясающий землю и выделяющий память код ...
// здесь мог бы быть ваш сотрясающий землю и выделяющий память код ...
this->name_ = name;
this->storage_ = new Book[kInitStorageCapacity];
this->storage_size_ = 0;//
this->storage_capacity_ = kInitStorageCapacity;
}

// 3. реализуйте деструктор ...
BookStore::~BookStore() {
// здесь мог бы быть ваш высвобождающий разум от негатива код ...
// Tip 1: я свободен ..., словно память в куче: не забудьте обнулить указатель
delete[] storage_;
storage_ = nullptr;
storage_capacity_ = 0;
storage_size_ = 0;
// здесь мог бы быть ваш высвобождающий разум от негатива код ...
// Tip 1: я свободен ..., словно память в куче: не забудьте обнулить указатель
}

// 4. реализуйте метод ...
void BookStore::AddBook(const Book &book) {
if (storage_size_ == storage_capacity_) {
// здесь мог бы быть ваш умопомрачительный код ...
// Tip 1: используйте функцию resize_storage_internal, задав новый размер хранилища
// Tip 2: не забудьте обработать статус вызова функции
}
// Tip 3: не забудьте добавить книгу в наше бездонное хранилище ...
void BookStore::AddBook(const Book& book) {
if (storage_size_ == storage_capacity_) {
// здесь мог бы быть ваш умопомрачительный код ...
// Tip 1: используйте функцию resize_storage_internal, задав новый размер хранилища
// Tip 2: не забудьте обработать статус вызова функции
ResizeStorageStatus status = resize_storage_internal(storage_capacity_ + kCapacityCoefficient);
if (status != ResizeStorageStatus::SUCCESS)
throw std::invalid_argument("");
}
storage_[storage_size_] = book;
storage_size_++;
}

// РЕАЛИЗОВАНО
Expand Down