added figures for Windows

This commit is contained in:
Marcin 2019-05-13 20:54:13 +02:00
parent f018058248
commit 78901ce84f
11 changed files with 129 additions and 26 deletions

27
Figures/Makefile Normal file
View File

@ -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)/*

BIN
Figures/bin/a.exe Normal file

Binary file not shown.

13
Figures/include/Circle.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "Figure.h"
#include <string>
class Circle : public Figure {
public:
float r;
Circle();
Circle(float _r);
virtual std::string type() const;
virtual float area() const;
};

9
Figures/include/Figure.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <string>
class Figure {
public:
virtual std::string type() const = 0;
virtual float area() const = 0;
};

View File

@ -0,0 +1,13 @@
#pragma once
#include "Figure.h"
#include <string>
class Rectangle : public Figure {
public:
float w,h;
Rectangle();
Rectangle(float _w, float _h);
virtual std::string type() const;
virtual float area() const;
};

19
Figures/source/Circle.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "../include/Circle.h"
#include <string>
#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;
}

View File

@ -0,0 +1,16 @@
#include "../include/Rectangle.h"
#include <string>
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;
}

18
Figures/source/main.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "../include/Circle.h"
#include "../include/Rectangle.h"
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<Figure*> 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;
}

View File

@ -1,9 +0,0 @@
cpp1
cpp2
ilovecpp
linuxoverwindows
123
456
789
abc
qwe

View File

@ -1,9 +0,0 @@
cpp1
cpp2
ilovecpp
linuxoverwindows
123
456
789
abc
qwe

View File

@ -5,16 +5,22 @@ using namespace std;
template <typename type>
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();
}
}
type operator[](){
return
}
};