-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.cpp
74 lines (61 loc) · 1.78 KB
/
Block.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
/*
@author: Sir0ga90
@version: 0.1
*/
#include "Block.h"
//======================================================================//Constructors
Block::Block() :num{0}, area{hig*wid}{}
//======================================================================//
Block::Block(uint32_t n, p_size h, p_size w){
num = n;
hig = h;
check_hig(h);
wid = w;
check_wid(w);
area = hig * wid;
}
//======================================================================//
Block::~Block(){} // destructor
//======================================================================//Member func's
/*
rotate - change sizes of block from vertical to gorizontal
orientation by interchanging it's width & hight
*/
void Block::rotate(){
p_size temp = hig;
hig = wid;
wid = temp;
}
//======================================================================//
/*
decremet number of this type blocks
*/
void Block::dec_num(){
num--;
}
//======================================================================//
istream &operator>>(istream &is, Block &b){
is >> b.wid >> b.hig >> b.num;
check_wid(b.wid);
check_hig(b.hig);
b.area = b.hig*b.wid;
return is;
}
//======================================================================//
void check_wid(p_size w){
if (w < 1){
throw exception("Hight of block less then 1\n");
}
else if (w > MAX_BLOCK_SIZE){
throw exception("Hight of block not fit in block max sizes\n"); //wrong init prtection
}
}
//======================================================================//
void check_hig(p_size h){
if (h < 1){
throw exception("Hight of block less then 1\n");
}
else if (h > MAX_BLOCK_SIZE){
throw exception("Hight of block not fit in block max sizes\n"); //wrong init prtection
}
};