From f3406754705e508f57768d3d0d8e457ff5b7620c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 22 Apr 2024 15:43:49 +0300 Subject: [w8] Added exercise descriptions and solutions to ex 1-7 --- week08/Exercise4.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 week08/Exercise4.h (limited to 'week08/Exercise4.h') diff --git a/week08/Exercise4.h b/week08/Exercise4.h new file mode 100644 index 0000000..588589e --- /dev/null +++ b/week08/Exercise4.h @@ -0,0 +1,37 @@ +#include + +class FloatArray { + float *numbers; + int lastUnused; + int allocated; + + void free(); + void copyFrom(const FloatArray& other); + + void resize(); + +public: + FloatArray(); + ~FloatArray(); + FloatArray(const FloatArray& other); + FloatArray& operator=(const FloatArray& other); + FloatArray(FloatArray&& other); + FloatArray& operator=(FloatArray&& other); + + void Add(float number); + + // Тези оператори променят аргумента си, затова е по-добре да са член-функции + FloatArray& operator+=(const FloatArray& other); + FloatArray& operator+=(float number); + // По дефиниция не може operator=, operator(), operator[] и operator-> да бъдат имплементирани + // като приятелски функции + float& operator[](int index); + + // Тези оператори не променят аргументите си, затова е по-добре да са приятелски + friend FloatArray operator+(const FloatArray& left, const FloatArray& right); + friend FloatArray operator+(const FloatArray& left, float right); + friend bool operator==(const FloatArray& left, const FloatArray& right); + friend bool operator!=(const FloatArray& left, const FloatArray& right); + friend std::ostream& operator<<(std::ostream& ostr, const FloatArray& right); + friend std::istream& operator>>(std::istream& ostr, FloatArray& right); +}; -- cgit v1.2.3