-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcabinet.cpp
98 lines (90 loc) · 2.22 KB
/
cabinet.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include "cabinet.h"
using namespace std;
Cabinet :: Cabinet(const int & NMAX)
{
for(int i = 0; i < CABINETSHELVESNUMBER; i++)
{
shelf[i] = new Shelf(NMAX);
}
cout << "A new Cabinet has been created." << endl;
}
Cabinet :: ~Cabinet()
{
cout << "A Cabinet to be destroyed." << endl;
for(int i = 0; i < CABINETSHELVESNUMBER; i++)
{
delete shelf[i];
}
}
bool Cabinet :: place_book(const int & placeNumber, Book & book)
{
switch (placeNumber)
{
case 1 :
if(this->shelf[0]->place_book(book))
{
return true;
}
cout << '\t' << '\t' << '\t' << "ERROR : Couldn't place book in top cabinet shelf." << endl;
return false;
break;
case 2 :
if(this->shelf[1]->place_book(book))
{
return true;
}
cout << '\t' << '\t' << '\t' << "ERROR : Couldn't place book in bottom cabinet shelf." << endl;
return false;
break;
default:
cout << "ERROR : Give 1 or 2." << endl;
return false;
}
}
bool Cabinet :: take_book(const int & placeNumber)
{
switch (placeNumber)
{
case 1 :
if(this->shelf[0]->take_book())
{
return true;
}
cout << '\t' << '\t' << '\t' << "ERROR : Couldn't take book from top cabinet shelf." << endl;
return false;
break;
case 2 :
if(this->shelf[1]->take_book())
{
return true;
}
cout << '\t' << '\t' << '\t' << "ERROR : Couldn't take book from bottom cabinet shelf." << endl;
return false;
break;
default:
cout << '\t' << '\t' << '\t' << "ERROR : Give 1 or 2." << endl;
return false;
}
}
void Cabinet :: print() const
{
cout << '\t' << '\t' << "Printing the top shelf of cabinet : " << endl;
print(1);
cout << endl << '\t' << '\t' << "Printing the bottom shelf of cabinet : " << endl;
print(2);
}
void Cabinet :: print(const int & placeNumber) const
{
switch (placeNumber)
{
case 1 :
this->shelf[0]->print();
break;
case 2 :
this->shelf[1]->print();
break;
default:
cout << "ERROR : Give 1 or 2." << endl;
}
}