Untitled
unknown
plain_text
a year ago
4.0 kB
6
Indexable
#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();
};
void DMY::getData() {
cout << "---Data of returning---\n";
cout << " - day: "; cin >> d;
cout << " - month: "; cin >> m;
cout << " - year: "; cin >> y;
}
void DMY::display() {
cout << d << "." << m << "." << y;
}
class Register : public CBook, public CReader, public DMY {
private:
string rNumber;
DMY DateOfReturning;
public:
void getData();
void display();
void returnBook(Register givenBook[], int gbNum, string rNumber);
};
void Register::getData() {
cin.ignore();
cout << "Registration number: "; getline(cin, rNumber); cout << endl;
DateOfReturning.getData();
}
void Register::display() {
cout << "Registration number: " << rNumber;
DateOfReturning.display();
}
void 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;
}
}
}
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);
givenBook[gbNum].returnBook(givenBook, gbNum, rNumber);
}
break;
case 4:
break;
case 5:
break;
default: cout << "Invalid operation code.\n";
}
} while (codeOp != 0);
}
Editor is loading...
Leave a Comment