forked from natto1784/ooplab
83 lines
1.3 KiB
C++
83 lines
1.3 KiB
C++
#include <iostream>
|
|
using namespace std;
|
|
|
|
class Book {
|
|
private:
|
|
char name[50];
|
|
uint id;
|
|
|
|
public:
|
|
void getData();
|
|
void putData();
|
|
};
|
|
|
|
void Book::getData() {
|
|
cout << "Name of book: ";
|
|
cin >> name;
|
|
cout << "ID of book: ";
|
|
cin >> id;
|
|
}
|
|
|
|
void Book::putData() {
|
|
cout << "Name of book: " << name << endl << "ID of book: " << id << endl;
|
|
}
|
|
|
|
class Authorities : public Book {
|
|
private:
|
|
char author[50];
|
|
char publisher[50];
|
|
|
|
public:
|
|
void getData();
|
|
void putData();
|
|
};
|
|
|
|
void Authorities::getData() {
|
|
cout << "Name of author: ";
|
|
cin >> author;
|
|
cout << "Name of publisher: ";
|
|
cin >> publisher;
|
|
}
|
|
|
|
void Authorities::putData() {
|
|
cout << "Name of author: " << author << endl
|
|
<< "Name of publisher: " << publisher << endl;
|
|
}
|
|
|
|
class Publication : public Authorities {
|
|
private:
|
|
uint pageCount;
|
|
uint year;
|
|
|
|
public:
|
|
void getData();
|
|
void putData();
|
|
};
|
|
|
|
void Publication::getData() {
|
|
cout << "Number of pages: ";
|
|
cin >> pageCount;
|
|
cout << "Year (YYYY): ";
|
|
cin >> year;
|
|
}
|
|
|
|
void Publication::putData() {
|
|
cout << "Number of pages: " << pageCount << endl << "Year: " << year << endl;
|
|
}
|
|
|
|
int main() {
|
|
Publication p[3];
|
|
|
|
for (auto &x: p) {
|
|
x.Book::getData();
|
|
x.Authorities::getData();
|
|
x.getData();
|
|
}
|
|
|
|
for (auto &x: p) {
|
|
x.Book::putData();
|
|
x.Authorities::putData();
|
|
x.putData();
|
|
}
|
|
}
|