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
6 changes: 5 additions & 1 deletion src/author.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

// 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));
}
Expand All @@ -13,6 +14,9 @@ Author::Author(const std::string &full_name, int age, Sex sex) {
throw std::invalid_argument("Author::full_name must not be empty");
}
// Tip 1: инициализируйте поля
full_name_ = full_name;
age_ = age;
sex_ = sex;
}

void Author::SetAge(int age) {
Expand Down
13 changes: 11 additions & 2 deletions src/book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <stdexcept> // invalid_argument

// 1. реализуйте конструктор ...

Book::Book(const std::string &title,
const std::string &content,
Genre genre,
Expand All @@ -24,13 +24,22 @@ Book::Book(const std::string &title,
}

// Tip 1: остались слезы на щеках, осталось лишь инициализировать поля ...
title_ = title;
content_ = content;
genre_ = genre;
publisher_ = publisher;
authors_ = authors;
}

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

// РЕАЛИЗОВАНО
Expand Down
26 changes: 26 additions & 0 deletions src/book_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ ResizeStorageStatus resize_storage(Book *&storage, int size, int new_capacity) {
// здесь мог бы быть ваш разносторонний и многогранный код ...
// Tip 1: проведите валидацию аргументов функции
// Tip 2: не забудьте высвободить ранее выделенную память под хранилище
if(storage == nullptr){
return ResizeStorageStatus::NULL_STORAGE;
}
if(new_capacity <= size){
return ResizeStorageStatus::INSUFFICIENT_CAPACITY;
}
if(size < 0){
return ResizeStorageStatus::NEGATIVE_SIZE;
}

auto *new_storage = new Book[new_capacity];
std::copy(storage[0], storage[size - 1], new_storage);
delete [] storage;
storage = new_storage;
storage_capacity_ = new_capacity;
return ResizeStorageStatus::SUCCESS;
}

Expand All @@ -19,12 +34,17 @@ BookStore::BookStore(const std::string &name) : name_{name} {
}

// здесь мог бы быть ваш сотрясающий землю и выделяющий память код ...
name_ = name;
resize_storage(&storage_, storage_size_, kInitStorageCapacity);
}

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

// 4. реализуйте метод ...
Expand All @@ -33,8 +53,14 @@ void BookStore::AddBook(const Book &book) {
// здесь мог бы быть ваш умопомрачительный код ...
// Tip 1: используйте функцию resize_storage_internal, задав новый размер хранилища
// Tip 2: не забудьте обработать статус вызова функции
status = resize_storage(&storage_, storage_size_, storage_capacity_ + kInitStorageCapacity);
if(status != ResizeStorageStatus::SUCCESS){
return;
}
}
// Tip 3: не забудьте добавить книгу в наше бездонное хранилище ...
storage_[storage_size_] = book;
storage_size_++;
}

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