aboutsummaryrefslogtreecommitdiff
path: root/week04/Exercise3.cpp
blob: c8340972c1561fe328579b37812e1be36ed322dc (plain) (blame)
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
#include <iostream>
#include <cstring>

struct Paper {
private:
	char contents[1024];
	unsigned page;

	void copyFrom(const Paper& other) {
		strncpy(this->contents, other.contents, 1024);
		page = other.page + 1;
	}

public:
	Paper(const char* contents) {
		strncpy(this->contents, contents, 1024);
		page = 1;
	}

	Paper(const Paper& other) {
		copyFrom(other);
	}
};

int main() {
	int N;
	std::cin >> N;

	Paper** papers = new Paper*[N];

	char buffer[1024];
	std::cin.ignore();
	std::cin.getline(buffer, 1024);
	papers[0] = new Paper(buffer);
	for (int i = 1; i < N; i++) {
		papers[i] = new Paper(*papers[0]);
	}

	for (int i = 0; i < N; i++) {
		delete papers[i];
	}
	delete[] papers;
}