Skip to content

Commit 9993a89

Browse files
committed
Lab 5
1 parent 7ce89be commit 9993a89

17 files changed

+584
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ add_subdirectory(InClassBasicEmployee)
3434
add_subdirectory(Utility)
3535
add_subdirectory(Shapes)
3636
add_subdirectory(DateTime)
37+
add_subdirectory(Shapes2)

Shapes2/Box.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "Box.hpp"
2+
#include <assert.h>
3+
#include <string>
4+
5+
6+
7+
Box::Box()
8+
{
9+
}
10+
Box::Box(float length,float width, float height, std::string name) : ThreeDShape(name,1)
11+
{
12+
this->setLength(length);
13+
this->setWidth(width);
14+
this->setHeight(height);
15+
}
16+
void Box::calculateVolume()
17+
{
18+
this->volume = this->getLength() * this->getWidth()*this->getHeight();
19+
}
20+
void Box::calculateSurfaceArea()
21+
{
22+
this->surfaceArea = this->getLength()*this->getWidth()*2
23+
+this->getLength()*this->getHeight()*2
24+
+this->getHeight()*this->getWidth()*2;
25+
}
26+
std::string Box::to_string()
27+
{
28+
std::string ret;
29+
ret += "Box:\n";
30+
ret += "Length:" + std::to_string(this->getLength()) + "\n";
31+
ret += "Width:" + std::to_string(this->getWidth()) + "\n";
32+
ret += "Height:" + std::to_string(this->getHeight()) + "\n";
33+
ret += ThreeDShape::to_string();
34+
return ret;
35+
}
36+
float Box::getLength()
37+
{
38+
return this->length;
39+
}
40+
void Box::setLength(float length)
41+
{
42+
this->length = length;
43+
}
44+
float Box::getWidth()
45+
{
46+
return this->width;
47+
}
48+
void Box::setWidth(float width)
49+
{
50+
this->width = width;
51+
}
52+
float Box::getHeight()
53+
{
54+
return this->height;
55+
}
56+
void Box::setHeight(float height)
57+
{
58+
this->height = height;
59+
}

Shapes2/Box.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef BOX_HPP
2+
#define BOX_HPP
3+
#include <string>
4+
#include "ThreeDShape.hpp"
5+
6+
7+
class Box : public ThreeDShape
8+
{
9+
float length;
10+
float width;
11+
float height;
12+
public:
13+
Box();
14+
Box(float length,float width, float height, std::string name);
15+
void calculateVolume();
16+
void calculateSurfaceArea();
17+
virtual std::string to_string();
18+
19+
float getLength();
20+
void setLength(float r);
21+
float getWidth();
22+
void setWidth(float r);
23+
float getHeight();
24+
void setHeight(float r);
25+
};
26+
27+
28+
29+
30+
#endif

Shapes2/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
add_library(Shape Shape.cpp)
2+
add_library(TwoDShape TwoDShape.cpp)
3+
add_library(ThreeDShape ThreeDShape.cpp)
4+
add_library(Circle Circle.cpp)
5+
add_library(Sphere Sphere.cpp)
6+
add_library(Rectangle2 Rectangle.cpp)
7+
add_library(Box2 Box.cpp)
8+
9+
10+
add_executable(Shapes2Main Shapes2Main.cpp)
11+
target_link_libraries(Shapes2Main Sphere Circle Box2 Rectangle2 Shape ThreeDShape TwoDShape)
12+
13+

Shapes2/Circle.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "Circle.hpp"
2+
#include <assert.h>
3+
#include <string>
4+
5+
6+
7+
Circle::Circle()
8+
{
9+
}
10+
Circle::Circle(float radius, std::string name) : TwoDShape(name,1)
11+
{
12+
this->setRadius(radius);
13+
}
14+
void Circle::calculateArea()
15+
{
16+
this->area = 3.14159*this->getRadius()*this->getRadius();//Pi r^2
17+
}
18+
void Circle::calculatePerimeter()
19+
{
20+
this->perimeter = 3.14159*2*this->getRadius(); //2 Pi r
21+
}
22+
std::string Circle::to_string()
23+
{
24+
std::string ret;
25+
ret += "Circle:\n";
26+
ret += "Radius:" + std::to_string(this->getRadius()) + "\n";
27+
ret += TwoDShape::to_string();
28+
return ret;
29+
}
30+
float Circle::getRadius()
31+
{
32+
return this->radius;
33+
}
34+
void Circle::setRadius(float r)
35+
{
36+
assert(r > 0);
37+
this->radius = r;
38+
}

Shapes2/Circle.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef CIRCLE_HPP
2+
#define CIRCLE_HPP
3+
#include <string>
4+
#include "TwoDShape.hpp"
5+
6+
7+
class Circle : public TwoDShape
8+
{
9+
float radius;
10+
public:
11+
Circle();
12+
Circle(float radius, std::string name);
13+
virtual void calculateArea();
14+
virtual void calculatePerimeter();
15+
virtual std::string to_string();
16+
17+
float getRadius();
18+
void setRadius(float r);
19+
};
20+
21+
22+
23+
24+
#endif

Shapes2/Rectangle.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "Rectangle.hpp"
2+
#include <assert.h>
3+
#include <string>
4+
5+
6+
7+
Rectangle::Rectangle() : TwoDShape()
8+
{
9+
this->setWidth(0);
10+
this->setLength(0);
11+
}
12+
Rectangle::Rectangle(float length,float width, std::string name) : TwoDShape(name,4)
13+
{
14+
this->setLength(length);
15+
this->setWidth(width);
16+
}
17+
void Rectangle::calculateArea()
18+
{
19+
this->area = this->getWidth() * this->getLength();
20+
}
21+
void Rectangle::calculatePerimeter()
22+
{
23+
this->perimeter = this->getWidth() * 2 + this->getLength()*2;
24+
}
25+
std::string Rectangle::to_string()
26+
{
27+
std::string ret;
28+
ret += "Rectangle:\n";
29+
ret += "Length:" + std::to_string(this->getLength()) + "\n";
30+
ret += "Width:" + std::to_string(this->getWidth()) + "\n";
31+
ret += TwoDShape::to_string();
32+
return ret;
33+
}
34+
35+
float Rectangle::getLength()
36+
{
37+
return this->length;
38+
}
39+
void Rectangle::setLength(float length)
40+
{
41+
this->length = length;
42+
}
43+
float Rectangle::getWidth()
44+
{
45+
return this->width;
46+
}
47+
void Rectangle::setWidth(float width)
48+
{
49+
this->width = width;
50+
}

Shapes2/Rectangle.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef RECTANGLE_HPP
2+
#define RECTANGLE_HPP
3+
#include <string>
4+
#include "TwoDShape.hpp"
5+
6+
7+
class Rectangle : public TwoDShape
8+
{
9+
float length;
10+
float width;
11+
public:
12+
Rectangle();
13+
Rectangle(float length,float width, std::string name);
14+
virtual void calculateArea();
15+
virtual void calculatePerimeter();
16+
virtual std::string to_string();
17+
18+
float getLength();
19+
void setLength(float length);
20+
float getWidth();
21+
void setWidth(float width);
22+
};
23+
24+
25+
26+
27+
#endif

Shapes2/Shape.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "Shape.hpp"
2+
#include <assert.h>
3+
4+
5+
Shape::Shape()
6+
{
7+
this->setName("");
8+
this->setNumberOfEdges(0);
9+
}
10+
11+
Shape::Shape(std::string name, int edges)
12+
{
13+
this->setName(name);
14+
this->setNumberOfEdges(edges);
15+
}
16+
17+
Shape::~Shape()
18+
{
19+
}
20+
std::string Shape::to_string()
21+
{
22+
std::string ret = "Shape:\n";
23+
ret += "Name:" + this->getName() + "\n";
24+
ret += "Number Of Edges:" + std::to_string(this->getNumberOfEdges()) + "\n";
25+
ret += "Dimensionality:" + std::to_string(this->getDimensionality()) + "\n";
26+
return ret;
27+
}
28+
29+
std::string Shape::getName()
30+
{
31+
return this->name;
32+
}
33+
int Shape::getNumberOfEdges()
34+
{
35+
return this->numberOfEdges;
36+
}
37+
void Shape::setName(std::string name)
38+
{
39+
this->name = name;
40+
}
41+
void Shape::setNumberOfEdges(int edges)
42+
{
43+
this->numberOfEdges = edges;
44+
assert(edges > 0);
45+
}

Shapes2/Shape.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef SHAPE_HPP
2+
#define SHAPE_HPP
3+
#include <string>
4+
5+
6+
class Shape
7+
{
8+
std::string name;
9+
int numberOfEdges;
10+
public:
11+
Shape();
12+
Shape(std::string name, int edges);
13+
virtual ~Shape();
14+
virtual std::string to_string();
15+
virtual int getDimensionality() = 0;
16+
17+
18+
std::string getName();
19+
int getNumberOfEdges();
20+
void setName(std::string name);
21+
void setNumberOfEdges(int edges);
22+
};
23+
24+
25+
26+
27+
#endif

0 commit comments

Comments
 (0)