initial commit

This commit is contained in:
2023-07-16 13:23:25 +00:00
commit c3fa5367c3
85 changed files with 4921 additions and 0 deletions

30
C++/lesson7/task1.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <iostream>
#include <string>
struct Good {
std::string name;
unsigned cost;
unsigned amount;
Good(std::string name, unsigned cost, unsigned amount) {
this->name = name;
this->cost = cost;
this->amount = amount;
}
void information() {
std::cout << '(' << name << ',' << cost << ',' << amount
<< ")\n";
}
void changeCost(unsigned cost) {
this->cost = cost;
}
};
int main() {
Good apple("Apple", 10, 20);
apple.information();
apple.changeCost(20);
apple.information();
}

43
C++/lesson7/task8.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <iostream>
#include <string>
enum EventKind {
Lesson,
Meeting,
Celebration
};
struct Event {
std::string name;
std::string time;
std::string date;
EventKind kind;
Event(std::string name, std::string time, std::string date, EventKind kind) {
this->name = name;
this->time = time;
this->date = date;
this->kind = kind;
}
void information() {
std::cout
<< '(' << name << ',' << time << ',' << date << ',' << kind << ')' << '\n';
}
~Event() {
std::cout
<< '(' << name << ',' << time << ',' << date << ',' << kind << ')' << " was deleted\n";
}
};
void display_events(Event events[], size_t length) {
for (size_t i = 0; i < length; i++) {
events[i].information();
}
};
int main() {
Event m[3] = {Event("NewYear", "00:00", "31:12:2023", Celebration), Event("Breefing", "17:00", "15:06:2023", Meeting), Event("AI", "10:00", "03:07:2023", Lesson)};
display_events(m, 3);
}

160
C++/lesson7/task9.cpp Normal file
View File

@ -0,0 +1,160 @@
#include <iostream>
#include <string>
#include <vector>
class Book {
int id;
std::string name;
std::string writer;
std::string year;
public:
Book() {}
Book(unsigned id, std::string name, std::string writer, std::string year) {
this->id = id;
this->name = name;
this->writer = writer;
this->year = year;
}
std::string& get_name() {
return name;
}
std::string& get_writer() {
return writer;
}
std::string& get_year() {
return year;
}
void setname(std::string name) {
this->name = name;
}
void setwriter(std::string writer) {
this->name = name;
}
void setyear(std::string year) {
this->name = name;
}
};
class Reader {
std::string name;
unsigned number;
public:
Reader() {}
Reader(std::string name, unsigned number) {
this->name = name;
this->number = number;
}
std::string& getName() {
return name;
}
unsigned getNumber() {
return number;
}
void setName(std::string name) {
this->name = name;
}
void setNumber(unsigned number) {
this->number = number;
}
};
class Library {
public:
Reader* readers;
size_t amount_readers;
Book* books;
size_t amount_books;
Library() {
readers = new Reader[0];
amount_readers = 0;
books = new Book[0];
amount_books = 0;
}
void addReader(Reader reader) {
Reader* new_readers = new Reader[amount_readers + 1];
for (size_t i = 0; i < amount_readers; i++) {
new_readers[i] = readers[i];
}
new_readers[amount_readers] = reader;
delete[] readers;
readers = new_readers;
amount_readers++;
}
void addBook(Book book) {
Book* new_books = new Book[amount_books + 1];
for (size_t i = 0; i < amount_books; i++) {
new_books[i] = books[i];
}
new_books[amount_books] = book;
delete[] books;
books = new_books;
amount_books++;
}
Book deleteBook(size_t n) {
Book* new_books = new Book[amount_books - 1];
for (size_t i = 0; i < n; i++) {
new_books[i] = books[i];
}
for (size_t j = n + 1; j < amount_books; j++) {
new_books[j - 1] = books[j];
}
Book deleted = books[n];
delete[] books;
books = new_books;
amount_books -= 1;
return deleted;
}
Book takeBook(size_t n) {
Book taken = this->deleteBook(n);
std::cout << "Book" << taken.get_name() << "is taken\n";
return taken;
}
void returnBook(Book book) {
std::cout << "Book" << book.get_name() << "is returned\n";
this->addBook(book);
}
};
int main() {
Book WarAndPeace(0, "WarAndPeace", "Tolstoy", "1867");
Book EugeneOnegin(1, "EugeneOnegin", "Pushkin", "1832");
Book HeroOfOurTime(2, "HeroOfOurTime", "Lemontov", "1840");
Book PortraitOfDorianGray(3, "PortraitOfDorianGray", "Wilde", "1890");
Library library;
library.addBook(WarAndPeace);
library.addBook(EugeneOnegin);
library.addBook(HeroOfOurTime);
library.addBook(PortraitOfDorianGray);
Reader petya("Petya", 0);
Reader vasya("Vasya", 1);
library.addReader(petya);
library.addReader(vasya);
Book book1 = library.takeBook(0);
Book book2 = library.takeBook(0);
library.returnBook(book1);
library.returnBook(book2);
library.takeBook(3);
}