From 571dc57f812a685bda7bd3baf8aaf2ef56feae65 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 28 Mar 2026 16:19:58 +0200 Subject: feat(Week05): Add solutions --- Week05/Exercise03/TaxDatabase.h | 80 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Week05/Exercise03/TaxDatabase.h (limited to 'Week05/Exercise03/TaxDatabase.h') diff --git a/Week05/Exercise03/TaxDatabase.h b/Week05/Exercise03/TaxDatabase.h new file mode 100644 index 0000000..89dd1ed --- /dev/null +++ b/Week05/Exercise03/TaxDatabase.h @@ -0,0 +1,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 */ -- cgit v1.3.1-23-gd82d