code

mail@pastecode.io avatar
unknown
plain_text
a month ago
4.6 kB
1
Indexable
Never
#include <iostream>
#include <string>
using namespace std;

class CBook {
private:
    string invNumber, author, title;
    float price;
public:
    void getData();
    void display();
};
void CBook::getData() {
    cin.ignore();
    cout << "iNumber: "; getline(cin, invNumber);
    cout << "Author: "; getline(cin, author);
    cout << "Title: "; getline(cin, title);
    cout << "Price: "; cin >> price;
}
void CBook::display() {
    cout << "iNumber: " << invNumber << endl;
    cout << "Author: " << author << endl;
    cout << "Title: " << title << endl;
    cout << "Price: " << price << endl;
}

class CReader {
private:
    string name, address, EGN;
public:
    void getData();
    void display();
};
void CReader::getData() {
    cin.ignore();
    cout << "Reader's name: "; getline(cin, name);
    cout << "Address: "; getline(cin, address);
    cout << "EGN: "; getline(cin, EGN);
}
void CReader::display() {
    cout << "Name: " << name << endl;
    cout << "Address: " << address << endl;
    cout << "EGN: " << EGN << endl;
}

class DMY {
private:
    int d, m, y;
public:
    void getData();
    void display();
    int datCmp(DMY d1,DMY d2);
};
void DMY::getData() {
    cout << "--- Date ---\n";
    cout << "   - day: "; cin >> d;
    cout << "   - month: "; cin >> m;
    cout << "   - year: "; cin >> y;

}
void DMY::display() {
    cout << d << "." << m << "." << y;
}
int DMY::datCmp(DMY d1, DMY d2) {
    if (d1.y != d2.y) return d1.y - d2.y;
    if (d1.m != d2.m) return d1.m - d2.m;
    return d1.d - d2.d;
}


class Register : public CBook, public CReader, public DMY {
private:
    string rNumber;
    DMY DateOfReturning;
public:
    void getData();
    void display();
    int returnBook(Register givenBook[], int gbNum, string rNumber);
    void notReturned(Register givenBook[], int gbNum);
};

void Register::getData() {
    cin.ignore();
    cout << "Registration number: "; getline(cin, rNumber); cout << endl;
    DateOfReturning.getData();
}
void Register::display() {
    cout << "Registration number: " << rNumber;
    DateOfReturning.display();
}
int Register::returnBook(Register givenBook[], int gbNum, string rNumber) {
    int count = 0;
    for (int i = 0; i < gbNum; i++) {
        if (givenBook[i].rNumber == rNumber) {
            for (int j = i; j <= gbNum - 1; j++)
            {
                givenBook[j] = givenBook[j + 1];
            }
            gbNum--;
            cout << "The book is deleted.";
        }
        else {
            cout << "No matching book..." << endl;
        }
        return gbNum;
    }
}
void Register::notReturned(Register givenBook[], int gbNum) {;
    DMY controlDate;
    cout << "Input today's date."; controlDate.getData();
    for (int i = 0; i < gbNum; i++) {
        if (DMY::datCmp(givenBook[i], controlDate) < 0) {
            givenBook[i].CReader::display();
        }
    };
}

int main()
{
    int codeOp = 0;
    Register givenBook[10]; int gbNum = 0;
    do {
        cout << "\nMENU OF EXECUTABLE OPERATIONS:\n";
        cout << " 1 -  add given book\n";
        cout << " 2 -  all lent books\n";
        cout << " 3 -  delete returned book\n";
        cout << " 4 -  list of readers who have not returned books\n";
        cout << " 5 -  create an array with data of unreturned books\n";
        cout << "Select an operation or 0 to end: "; cin >> codeOp;
        switch (codeOp) {
        case 0: cout << "Exiting..."; break;
        case 1:
            givenBook[gbNum].CBook::getData();
            givenBook[gbNum].CReader::getData();
            givenBook[gbNum++].getData();
            break;
        case 2:
            for (int i = 0; i < gbNum; i++) {
                if (gbNum = 0) {
                    cout << "No lent books";
                }
                givenBook[i].CBook::display();
                givenBook[i].CReader::display();
                givenBook[i].display();
            }
            break;
        case 3:
        {
            string rNumber;
            cin.ignore();
            cout << "Register number of the book you want to return: "; getline(cin, rNumber);
            gbNum = givenBook[gbNum].returnBook(givenBook, gbNum, rNumber);
        }
        break;
        case 4:
        {
            givenBook[0].notReturned( givenBook, gbNum);
        }
            break;
        case 5:
            break;
        default: cout << "Invalid operation code.\n";
        }
    } while (codeOp != 0);
Leave a Comment