Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- // Клас Читател
- class Reader {
- protected:
- string name; // Име на читателя
- string number; // Номер на читателя
- public:
- // Конструктор с параметри
- Reader(string readerName, string readerNumber)
- : name(readerName), number(readerNumber) {}
- // Метод за извеждане на информация за читателя
- void printReaderInfo() const {
- cout << "Reader Name: " << name << ", Reader Number: " << number << endl;
- }
- };
- // Клас Библиотека (наследява Reader)
- class Library : public Reader {
- private:
- string bookName; // Име на книгата
- bool isBorrowed; // Статус на книгата: заета или свободна
- public:
- // Конструктор с параметри
- Library(string readerName, string readerNumber, string book, bool status)
- : Reader(readerName, readerNumber), bookName(book), isBorrowed(status) {}
- // Функция за заемане на книга
- void borrowBook() {
- if (!isBorrowed) {
- isBorrowed = true;
- cout << "The book \"" << bookName << "\" has been borrowed by " << name << "." << endl;
- } else {
- cout << "The book \"" << bookName << "\" is already borrowed." << endl;
- }
- }
- // Функция за проверка дали дадена книга е заета
- bool checkBookStatus() const {
- return isBorrowed;
- }
- // Функция за извеждане на информация за книгата
- void printBookInfo() const {
- cout << "Book Name: " << bookName
- << ", Status: " << (isBorrowed ? "Borrowed" : "Available") << endl;
- }
- };
- // Главна функция
- int main() {
- // Масив от обекти Library
- Library books[] = {
- Library("Ivan Ivanov", "001", "C++ Programming", false),
- Library("Maria Petrova", "002", "Data Structures", false),
- Library("Georgi Georgiev", "003", "Algorithms", true),
- Library("Anna Dimitrova", "004", "Operating Systems", false),
- Library("Petar Petrov", "005", "Computer Networks", false),
- };
- // Извеждане на информация за книгите преди заемането
- cout << "Books before borrowing:" << endl;
- for (const Library& book : books) {
- book.printBookInfo();
- }
- cout << endl;
- // Заемане на първите две книги със статус "свободна"
- cout << "Borrowing available books:" << endl;
- int borrowedCount = 0;
- for (Library& book : books) {
- if (!book.checkBookStatus() && borrowedCount < 2) {
- book.borrowBook();
- borrowedCount++;
- }
- }
- cout << endl;
- // Извеждане на информация за книгите след заемането
- cout << "Books after borrowing:" << endl;
- for (const Library& book : books) {
- book.printBookInfo();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement