forked from natto1784/ooplab
82
lab6/16.cpp
Normal file
82
lab6/16.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user