Initial Course
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace oop {
|
||||
|
||||
class BankAccount {
|
||||
public:
|
||||
explicit BankAccount(std::string owner, double balance = 0.0);
|
||||
|
||||
[[nodiscard]] auto owner() const -> const std::string&;
|
||||
[[nodiscard]] auto balance() const -> double;
|
||||
|
||||
void deposit(double amount);
|
||||
auto withdraw(double amount) -> bool;
|
||||
|
||||
private:
|
||||
std::string owner_;
|
||||
double balance_;
|
||||
};
|
||||
|
||||
} // namespace oop
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace oop {
|
||||
|
||||
class StringBuilder {
|
||||
public:
|
||||
StringBuilder() = default;
|
||||
explicit StringBuilder(std::string initial);
|
||||
StringBuilder(const StringBuilder& other);
|
||||
auto operator=(const StringBuilder& other) -> StringBuilder&;
|
||||
~StringBuilder() = default;
|
||||
|
||||
void append(const std::string& text);
|
||||
[[nodiscard]] auto str() const -> std::string;
|
||||
[[nodiscard]] auto size() const -> std::size_t;
|
||||
|
||||
private:
|
||||
std::vector<char> buffer_;
|
||||
};
|
||||
|
||||
} // namespace oop
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace oop {
|
||||
|
||||
class Shape {
|
||||
public:
|
||||
virtual ~Shape() = default;
|
||||
[[nodiscard]] virtual auto name() const -> std::string = 0;
|
||||
[[nodiscard]] virtual auto area() const -> double = 0;
|
||||
};
|
||||
|
||||
class Circle : public Shape {
|
||||
public:
|
||||
explicit Circle(double radius);
|
||||
[[nodiscard]] auto name() const -> std::string override;
|
||||
[[nodiscard]] auto area() const -> double override;
|
||||
|
||||
private:
|
||||
double radius_;
|
||||
};
|
||||
|
||||
class Rectangle : public Shape {
|
||||
public:
|
||||
Rectangle(double width, double height);
|
||||
[[nodiscard]] auto name() const -> std::string override;
|
||||
[[nodiscard]] auto area() const -> double override;
|
||||
|
||||
private:
|
||||
double width_;
|
||||
double height_;
|
||||
};
|
||||
|
||||
} // namespace oop
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "inheritance.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace oop {
|
||||
|
||||
[[nodiscard]] auto total_area(const std::vector<std::unique_ptr<Shape>>& shapes) -> double;
|
||||
[[nodiscard]] auto shape_names(const std::vector<std::unique_ptr<Shape>>& shapes)
|
||||
-> std::vector<std::string>;
|
||||
|
||||
class Counter {
|
||||
public:
|
||||
Counter() = default;
|
||||
Counter(const Counter&) { ++copies_; }
|
||||
auto operator=(const Counter&) -> Counter& {
|
||||
++copies_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] static auto copies() -> int;
|
||||
|
||||
private:
|
||||
inline static int copies_ = 0;
|
||||
};
|
||||
|
||||
} // namespace oop
|
||||
Reference in New Issue
Block a user