-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDemo.cpp
39 lines (34 loc) · 1.21 KB
/
Demo.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
/**
* Demo program for notebook exercise.
*
* Author: Erel Segal-Halevi
* Edited by: Tal Zichlinsky
* Since : 2022-01
*/
#include "Notebook.hpp"
#include "Direction.hpp"
using ariel::Direction;
#include <iostream>
#include <stdexcept>
using namespace std;
int main() {
ariel::Notebook notebook;
try{
notebook.write(/*page=*/100, /*row=*/100, /*column=*/50, Direction::Horizontal, "abcd");
cout << notebook.read(/*page=*/100, /*row=*/99, /*column=*/51, Direction::Vertical, /*length=*/3) << endl;
// prints "_b_" (starts at row 99 which is empty; then at row 100 there is "b"; then row 101 is empty again).
notebook.write(/*page=*/100, /*row=*/99, /*column=*/52, Direction::Vertical, "xyz");
// throws error because writing the letter y will intersect with the letter c
notebook.erase(/*page=*/100, /*row=*/99, /*column=*/51, Direction::Vertical, /*length=*/3);
// writes ~ instead of _ in line 99, b in line 100 and _ again in line 99
notebook.show(100); // shows the notebook's page in a reasonable way. For example:
// 98: _________
// 99: ___~_____
// 100: __a~cd___
// 101: ___~_____
// 102: _________
}catch (const std::exception& e)
{
cout << e.what() << endl;
}
}