-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist3802.cpp
More file actions
72 lines (61 loc) · 1.95 KB
/
Copy pathlist3802.cpp
File metadata and controls
72 lines (61 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <string>
using namespace std;
class work
{
public:
work() = default;
work(work const&) = default;
work(string const& id, string const& title): id_{id}, title_{title} {}
virtual ~work() {};
string const& id() const { return id_; }
string const& title() const { return title_; }
virtual void print(ostream&) const {}
private:
string id_;
string title_;
};
class book : public work{
public:
book(): work{}, author_{}, pubyear_{0} {}
book(string const& id, string const& title, string const& author, int pubyear)
: work{id, title}, author_{author}, pubyear_{pubyear} {}
string const& author() const { return author_; }
int const& pubyear() const { return pubyear_; }
void print(ostream& out) const override{
out << author() << ", " << title() << ", " << pubyear() << ".";
}
private:
string author_;
int pubyear_;
};
class periodical: public work{
public:
periodical() : work{}, volume_{0}, number_{0}, date_{} {}
periodical(string const& id, string const& title, int volume, int number, string const& date)
: work{id, title}, volume_{volume}, number_{number}, date_{date} {}
int volume() const { return volume_; }
int number() const { return number_; }
string const& date() const { return date_; }
void print(ostream& out) const override {
out << title() << ", " << volume() << "( " << number() << "), " << date() << ".";
}
private:
int volume_;
int number_;
string date_;
};
void showoff (work const& w) {
w.print(std::cout);
std::cout << '\n';
}
int main () {
book sc{"1", "The Sun Also Crashes", "Ernest Lemmingway", 2000};
book ecpp{"2", "Exploring C++", "Ray Lischner", 2013};
periodical pop{"3", "Popular C++", 13, 42, "January 1, 2000"};
periodical today{"4", "C++ Today", 1, 1, "January 13, 1984"};
showoff(sc);
showoff(ecpp);
showoff(pop);
showoff(today);
}