forked from s444409/POB_2019
added figures for Windows
This commit is contained in:
parent
f018058248
commit
78901ce84f
27
Figures/Makefile
Normal file
27
Figures/Makefile
Normal 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
BIN
Figures/bin/a.exe
Normal file
Binary file not shown.
13
Figures/include/Circle.h
Normal file
13
Figures/include/Circle.h
Normal 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
9
Figures/include/Figure.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Figure {
|
||||||
|
public:
|
||||||
|
virtual std::string type() const = 0;
|
||||||
|
virtual float area() const = 0;
|
||||||
|
};
|
13
Figures/include/Rectangle.h
Normal file
13
Figures/include/Rectangle.h
Normal 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
19
Figures/source/Circle.cpp
Normal 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;
|
||||||
|
}
|
16
Figures/source/Rectangle.cpp
Normal file
16
Figures/source/Rectangle.cpp
Normal 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
18
Figures/source/main.cpp
Normal 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;
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
cpp1
|
|
||||||
cpp2
|
|
||||||
ilovecpp
|
|
||||||
linuxoverwindows
|
|
||||||
123
|
|
||||||
456
|
|
||||||
789
|
|
||||||
abc
|
|
||||||
qwe
|
|
@ -1,9 +0,0 @@
|
|||||||
cpp1
|
|
||||||
cpp2
|
|
||||||
ilovecpp
|
|
||||||
linuxoverwindows
|
|
||||||
123
|
|
||||||
456
|
|
||||||
789
|
|
||||||
abc
|
|
||||||
qwe
|
|
22
zad7_3.cpp
22
zad7_3.cpp
@ -5,16 +5,22 @@ using namespace std;
|
|||||||
template <typename type>
|
template <typename type>
|
||||||
class Array {
|
class Array {
|
||||||
private:
|
private:
|
||||||
type* ptrs;
|
type* basePtr;
|
||||||
Array(){}
|
Array(unsigned int n){
|
||||||
~Array(){}
|
basePtr=(type*)malloc(sizeof(type)*n); //allocate the memory
|
||||||
|
}
|
||||||
|
~Array(){
|
||||||
|
free(basePtr);
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
Array& operator new [](){
|
Array& operator new [](unsigned int n){
|
||||||
Array();
|
Array(n);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
void operator delete [](){
|
void* operator delete [](unsigned int n){
|
||||||
~Array();
|
~Array();
|
||||||
}
|
}
|
||||||
|
type operator[](){
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user