From 9f61b59ca6ceb76cd634240d118f5771c0534f3d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 20 Apr 2022 18:43:21 +0300 Subject: Added my work from todays exam --- .../Exam 1/ex1/NaturalNumbers.h | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Year 1/Object-oriented Programming/Exam 1/ex1/NaturalNumbers.h (limited to 'Year 1/Object-oriented Programming/Exam 1/ex1/NaturalNumbers.h') diff --git a/Year 1/Object-oriented Programming/Exam 1/ex1/NaturalNumbers.h b/Year 1/Object-oriented Programming/Exam 1/ex1/NaturalNumbers.h new file mode 100644 index 0000000..6282c1d --- /dev/null +++ b/Year 1/Object-oriented Programming/Exam 1/ex1/NaturalNumbers.h @@ -0,0 +1,41 @@ +#include +#include + +class NaturalNumbers { + char* name; + unsigned nameLength; + + int* elements; + unsigned elementsCount; + unsigned elementsLength; + + void copyFrom(const NaturalNumbers& other); + void free(); + void move(NaturalNumbers&& other); + + void resize(); + int indexOfNum(int number) const; + +public: + NaturalNumbers(); + NaturalNumbers(const int* elements, unsigned elementsCount, const char* name); + + ~NaturalNumbers(); + NaturalNumbers(const NaturalNumbers& other); + NaturalNumbers& operator=(const NaturalNumbers& other); + + bool operator[](int number) const; + NaturalNumbers& operator+=(const NaturalNumbers& other); + + const int* get_elements() const; + bool addElement(int number); + unsigned get_elementsCount() const; + + const char* get_name() const; + void set_name(const char* newName); +}; + +NaturalNumbers operator+(const NaturalNumbers& lhs, const NaturalNumbers& rhs); + +std::ostream& operator<<(std::ostream& ostr, const NaturalNumbers& numbers); +std::istream& operator>>(std::istream& istr, NaturalNumbers& numbers); -- cgit v1.3.1-26-gb76a