-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (49 loc) · 1.5 KB
/
main.cpp
File metadata and controls
57 lines (49 loc) · 1.5 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
#include "Board.h"
#include <iostream>
using namespace std;
int main() {
Board board1(4); // Initializes a 4x4 board
cout << board1 << endl; /* Shows an empty board:
....
....
....
....
*/
cout << board1[{1,2}] << endl; // .
board1[{1,1}]='X';
board1[{1,2}]='O';
char c = board1[{1,2}]; cout << c << endl; // O
cout << board1 << endl; /* Shows the following board:
....
.XO.
....
....
*/
try {
board1[{3,4}]='O'; // This should raise an exception
} catch (const IllegalCoordinateException& ex) {
cout << "Illegal coordinate: " << ex.theCoordinate() << endl; // prints "Illegal coordinate: 3,4"
}
board1 = '.'; // Fill the entire board with "."
cout << board1 << endl; /* Shows an empty board, as above */
try {
board1 = 'a'; // This should raise an exception
} catch (const IllegalCharException& ex) {
cout << "Illegal char: " << ex.theChar() << endl; // "Illegal char: a"
}
try {
board1[{0,1}] = 'x'; // This should raise an exception
} catch (const IllegalCharException& ex) {
cout << "Illegal char: " << ex.theChar() << endl; // "Illegal char: x"
}
Board board2 = board1;
board2[{0,0}] = 'X';
cout << board1 << endl; /* Shows an empty board, as above */
cout << board2 << endl; /* Shows a board with an X at top-left */
board1 = board2;
board1[{3,3}] = 'O';
cout << board2 << endl; /* Shows a board with an X at top-left */
cout << board1 << endl; /* Shows a board with an X at top-left and O at bottom-right */
cout << "Good bye!" << endl;
return 0;
}