Website Summary Files Commits Branches @commit @diff @stats
path: root / Week05 / Exercise03 / TaxDatabase.h
blob: 89dd1edab66ce84655d8c754d765fb12a0481384 (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
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
#ifndef _TAXDATABASE
#define _TAXDATABASE

#include "Person.h"
#include "TaxReport.h"

class TaxDatabase {
	Person* people;
	unsigned peopleCount;
	unsigned peopleAllocated;

	TaxReport* reports;
	unsigned reportsCount;
	unsigned reportsAllocated;

	void free();
	void copyFrom(const TaxDatabase& other);

	void resizePeople();
	void resizeReports();

public:
	TaxDatabase();
	~TaxDatabase();
	TaxDatabase(const TaxDatabase& other);
	TaxDatabase& operator=(const TaxDatabase& other);

	TaxDatabase(TaxDatabase&& other);
	TaxDatabase& operator=(TaxDatabase&& other);

	bool RegisterPerson(const Person& person);
	bool LogTaxReport(const TaxReport& report);

	void PersonalReports(unsigned long long PN) const;
	void YearlyReports(unsigned short year) const;

	double YearlyAvgIncome(unsigned short year) const;
	double YearlyTaxedIncome(unsigned short year) const;

	const TaxReport* GetReport(unsigned long long PN, unsigned short year) const;
	const TaxReport* GetReportByAge(unsigned long long PN, unsigned short age) const;

	// Можем да дефинираме класове в други класове, можем да достъпим
	// вътрешния клас с името "TaxDatabase::Reports".
	// Достъпността на класа следва public/protected/private, в този
	// случай класа е публичен.
	class Reports {
		TaxReport** reports;
		unsigned reportsCount;

		void copyFrom(const Reports& other);
		void free();

	public:
		Reports();
		~Reports();
		Reports(const Reports& other);
		Reports& operator=(const Reports& other);

		Reports(Reports&& other);
		Reports& operator=(Reports&& other);

		unsigned ReportsCount() const;
		const TaxReport* At(unsigned index) const;

		// Тези се използват единствено от GetReports и GetReportsByAge
		// Тоест не позволяваме на върнатата стойност да бъде изменяна
		void Allocate(unsigned size);
		TaxReport** At(unsigned index);
	};

	const Reports GetReports(unsigned long long PN, unsigned short startYear, unsigned short endYear) const;
	const Reports GetReportsByAge(unsigned long long PN, unsigned short startAge, unsigned short endAge) const;

	/* Помощни функции */

	const Person* GetPerson(unsigned long long PN) const;
};

#endif /* _TAXDATABASE */