diff --git a/Figures/Makefile b/Figures/Makefile new file mode 100644 index 0000000..0b5e439 --- /dev/null +++ b/Figures/Makefile @@ -0,0 +1,27 @@ +TARGET := figures + +BUILD_DIR := bin +SRC_DIR := source +INC_DIR := include + +SRCS := $(shell find $(SRC_DIR) -name *.cpp) +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) + +INC_FLAGS := $(addprefix -I,$(INC_DIR)) + +CPPFLAGS := $(INC_FLAGS) --std=c++14 + + +$(BUILD_DIR)/$(TARGET): $(OBJS) + echo $(LDFLAGS) + $(CXX) $(OBJS) -o $@ $(LDFLAGS) + +$(BUILD_DIR)/%.cpp.o: %.cpp + mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ + + +.PHONY: clean + +clean: + rm -rf $(BUILD_DIR)/* diff --git a/Figures/bin/a.exe b/Figures/bin/a.exe new file mode 100644 index 0000000..e16f5f0 Binary files /dev/null and b/Figures/bin/a.exe differ diff --git a/Figures/include/Circle.h b/Figures/include/Circle.h new file mode 100644 index 0000000..dfe6819 --- /dev/null +++ b/Figures/include/Circle.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Figure.h" +#include + +class Circle : public Figure { + public: + float r; + Circle(); + Circle(float _r); + virtual std::string type() const; + virtual float area() const; +}; diff --git a/Figures/include/Figure.h b/Figures/include/Figure.h new file mode 100644 index 0000000..609fc8f --- /dev/null +++ b/Figures/include/Figure.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +class Figure { + public: + virtual std::string type() const = 0; + virtual float area() const = 0; +}; \ No newline at end of file diff --git a/Figures/include/Rectangle.h b/Figures/include/Rectangle.h new file mode 100644 index 0000000..2731c13 --- /dev/null +++ b/Figures/include/Rectangle.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Figure.h" +#include + +class Rectangle : public Figure { + public: + float w,h; + Rectangle(); + Rectangle(float _w, float _h); + virtual std::string type() const; + virtual float area() const; +}; \ No newline at end of file diff --git a/Figures/source/Circle.cpp b/Figures/source/Circle.cpp new file mode 100644 index 0000000..8c806b2 --- /dev/null +++ b/Figures/source/Circle.cpp @@ -0,0 +1,19 @@ +#include "../include/Circle.h" +#include + +#define PI 3.141592653589793238463 + +using namespace std; + + +Circle::Circle(){r=0;} + +Circle::Circle(float _r){r=_r;} + +string Circle::type() const { + return "Circle"; +} + +float Circle::area() const { + return PI * r * r; +} \ No newline at end of file diff --git a/Figures/source/Rectangle.cpp b/Figures/source/Rectangle.cpp new file mode 100644 index 0000000..81d1f0d --- /dev/null +++ b/Figures/source/Rectangle.cpp @@ -0,0 +1,16 @@ +#include "../include/Rectangle.h" +#include +using namespace std; + + +Rectangle::Rectangle() : w(0), h(0) {} + +Rectangle::Rectangle(float _w, float _h) : w(_w), h(_h) {} + +string Rectangle::type() const { + return "Rectangle"; +} + +float Rectangle::area() const { + return w * h; +} \ No newline at end of file diff --git a/Figures/source/main.cpp b/Figures/source/main.cpp new file mode 100644 index 0000000..1e3832a --- /dev/null +++ b/Figures/source/main.cpp @@ -0,0 +1,18 @@ +#include "../include/Circle.h" +#include "../include/Rectangle.h" +#include +#include +using namespace std; + +int main(){ + vector figures = { + (Figure*)new Rectangle(10, 2), + (Figure*)new Rectangle(3, 3), + (Figure*)new Circle(5), + (Figure*)new Circle(1) + }; + for (Figure *f : figures) { + cout << f->type() << ": area = " << f->area() << "\n"; + } + return 0; +} diff --git a/logs/log1.txt b/logs/log1.txt deleted file mode 100644 index 877d834..0000000 --- a/logs/log1.txt +++ /dev/null @@ -1,9 +0,0 @@ -cpp1 -cpp2 -ilovecpp -linuxoverwindows -123 -456 -789 -abc -qwe diff --git a/logs/log2.txt b/logs/log2.txt deleted file mode 100644 index 877d834..0000000 --- a/logs/log2.txt +++ /dev/null @@ -1,9 +0,0 @@ -cpp1 -cpp2 -ilovecpp -linuxoverwindows -123 -456 -789 -abc -qwe diff --git a/zad7_3.cpp b/zad7_3.cpp index 02741e2..5471646 100644 --- a/zad7_3.cpp +++ b/zad7_3.cpp @@ -5,16 +5,22 @@ using namespace std; template class Array { private: - type* ptrs; - Array(){} - ~Array(){} + type* basePtr; + Array(unsigned int n){ + basePtr=(type*)malloc(sizeof(type)*n); //allocate the memory + } + ~Array(){ + free(basePtr); + } public: - Array& operator new [](){ - Array(); + Array& operator new [](unsigned int n){ + Array(n); return *this; } - void operator delete [](){ + void* operator delete [](unsigned int n){ ~Array(); } - -} \ No newline at end of file + type operator[](){ + return + } +};