-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
170 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
// Copyright 2022 UNN-CS | ||
// Copyright 2024 Kachalov Mikhail | ||
#ifndef INCLUDE_CIRCLE_H_ | ||
#define INCLUDE_CIRCLE_H_ | ||
#include <cstdint> | ||
|
||
class Circle { | ||
private: | ||
double radius; | ||
double ference; | ||
double area; | ||
|
||
public: | ||
Circle(double r); | ||
|
||
void setRadius(double r); | ||
void setFerence(double f); | ||
void setArea(double a); | ||
|
||
double getRadius() const; | ||
double getFerence() const; | ||
double getArea() const; | ||
}; | ||
|
||
|
||
#endif // INCLUDE_CIRCLE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright 2024 Kachalov Mikhail | ||
#ifndef TASKS_H | ||
#define TASKS_H | ||
|
||
double solveEarthAndRope(double earthRadius); | ||
double solveSwimmingPool(double poolRadius, double walkwayWidth); | ||
|
||
#endif // INCLUDE_TASKS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,40 @@ | ||
// Copyright 2022 UNN-CS | ||
// Copyright 2024 Kachalov Mikhail | ||
#include <cstdint> | ||
#include "circle.h" | ||
#include <cmath> | ||
|
||
const double PI = 3.14159265358979323846; | ||
|
||
Circle::Circle(double r) { | ||
setRadius(r); | ||
} | ||
|
||
void Circle::setRadius(double r) { | ||
radius = r; | ||
ference = 2 * PI * radius; | ||
area = PI * radius * radius; | ||
} | ||
|
||
void Circle::setFerence(double f) { | ||
ference = f; | ||
radius = ference / (2 * PI); | ||
area = PI * radius * radius; | ||
} | ||
|
||
void Circle::setArea(double a) { | ||
area = a; | ||
radius = std::sqrt(area / PI); | ||
ference = 2 * PI * radius; | ||
} | ||
|
||
double Circle::getRadius() const { | ||
return radius; | ||
} | ||
|
||
double Circle::getFerence() const { | ||
return ference; | ||
} | ||
|
||
double Circle::getArea() const { | ||
return area; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 Kachalov Mikhail | ||
#include "circle.h" | ||
#include "tasks.h" | ||
#include <iostream> | ||
|
||
double solveEarthAndRope(double earthRadius) { | ||
Circle earth(earthRadius); | ||
|
||
double newFerence = earth.getFerence() + 1; | ||
|
||
Circle ropeCircle(earthRadius); | ||
ropeCircle.setFerence(newFerence); | ||
|
||
double gap = ropeCircle.getRadius() - earth.getRadius(); | ||
|
||
return gap; | ||
} | ||
|
||
double solveSwimmingPool(double poolRadius, double walkwayWidth) { | ||
|
||
Circle pool(poolRadius); | ||
|
||
Circle poolWithWalkway(poolRadius + walkwayWidth); | ||
|
||
double walkwayArea = poolWithWalkway.getArea() - pool.getArea(); | ||
|
||
double concreteCost = walkwayArea * 1000; | ||
|
||
double fenceCost = poolWithWalkway.getFerence() * 2000; | ||
|
||
return fenceCost + concreteCost; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,75 @@ | ||
|
||
// Copyright 2024 Kachalov Mikhail | ||
#include <gtest/gtest.h> | ||
#include <cstdint> | ||
#include "circle.h" | ||
#include "tasks.h" | ||
|
||
TEST(CircleTest, SetRadius) { | ||
Circle circle(10); | ||
EXPECT_DOUBLE_EQ(circle.getRadius(), 10); | ||
EXPECT_DOUBLE_EQ(circle.getFerence(), 2 * PI * 10); | ||
EXPECT_DOUBLE_EQ(circle.getArea(), PI * 10 * 10); | ||
} | ||
|
||
TEST(CircleTest, SetFerence) { | ||
Circle circle(10); | ||
circle.setFerence(2 * PI * 15); | ||
EXPECT_DOUBLE_EQ(circle.getRadius(), 15); | ||
EXPECT_DOUBLE_EQ(circle.getFerence(), 2 * PI * 15); | ||
EXPECT_DOUBLE_EQ(circle.getArea(), PI * 15 * 15); | ||
} | ||
|
||
TEST(CircleTest, SetArea) { | ||
Circle circle(10); | ||
circle.setArea(PI * 20 * 20); | ||
EXPECT_DOUBLE_EQ(circle.getRadius(), 20); | ||
EXPECT_DOUBLE_EQ(circle.getFerence(), 2 * PI * 20); | ||
EXPECT_DOUBLE_EQ(circle.getArea(), PI * 20 * 20); | ||
} | ||
|
||
TEST(TasksTest, SolveEarthAndRope) { | ||
double earthRadius = 6378100; | ||
double gap = solveEarthAndRope(earthRadius); | ||
EXPECT_NEAR(gap, 0.159154943, 1e-9); | ||
} | ||
|
||
TEST(TasksTest, SolveEarthAndRopeSmallRadius) { | ||
double smallRadius = 1; | ||
double gap = solveEarthAndRope(smallRadius); | ||
EXPECT_NEAR(gap, 0.159154943, 1e-9); | ||
} | ||
|
||
TEST(TasksTest, SolveSwimmingPool) { | ||
double poolRadius = 3; | ||
double walkwayWidth = 1; | ||
double totalCost = solveSwimmingPool(poolRadius, walkwayWidth); | ||
EXPECT_NEAR(totalCost, 75424.77796, 1e-2); | ||
} | ||
|
||
TEST(TasksTest, SolveSwimmingPoolDifferentSizes) { | ||
double poolRadius = 5; | ||
double walkwayWidth = 2; | ||
double totalCost = solveSwimmingPool(poolRadius, walkwayWidth); | ||
EXPECT_NEAR(totalCost, 207345.1151, 1e-2); | ||
} | ||
|
||
TEST(CircleTest, ZeroRadius) { | ||
Circle circle(0); | ||
EXPECT_DOUBLE_EQ(circle.getRadius(), 0); | ||
EXPECT_DOUBLE_EQ(circle.getFerence(), 0); | ||
EXPECT_DOUBLE_EQ(circle.getArea(), 0); | ||
} | ||
|
||
TEST(CircleTest, FractionalRadius) { | ||
Circle circle(2.5); | ||
EXPECT_DOUBLE_EQ(circle.getRadius(), 2.5); | ||
EXPECT_DOUBLE_EQ(circle.getFerence(), 2 * PI * 2.5); | ||
EXPECT_DOUBLE_EQ(circle.getArea(), PI * 2.5 * 2.5); | ||
} | ||
|
||
TEST(CircleTest, SmallFerence) { | ||
Circle circle(1); | ||
circle.setFerence(1); | ||
EXPECT_NEAR(circle.getRadius(), 1 / (2 * PI), 1e-9); | ||
EXPECT_NEAR(circle.getArea(), PI * std::pow(1 / (2 * PI), 2), 1e-9); | ||
} |