Initial Course

This commit is contained in:
David Gil de Gómez Pérez
2026-08-11 17:40:36 +03:00
commit 9aed1d1d86
202 changed files with 3420 additions and 0 deletions
@@ -0,0 +1,22 @@
#include "classes_and_objects.hpp"
namespace oop {
BankAccount::BankAccount(std::string owner, double balance)
: owner_(std::move(owner)), balance_(balance) {}
auto BankAccount::owner() const -> const std::string& { return owner_; }
auto BankAccount::balance() const -> double { return balance_; }
void BankAccount::deposit(double amount) {
// TODO: Add amount when positive
(void)amount;
}
auto BankAccount::withdraw(double amount) -> bool {
// TODO: Return false if insufficient funds, else subtract and return true
(void)amount;
return false;
}
} // namespace oop
@@ -0,0 +1,30 @@
#include "constructors.hpp"
namespace oop {
StringBuilder::StringBuilder(std::string initial) {
// TODO: Initialize buffer_ from initial
(void)initial;
}
StringBuilder::StringBuilder(const StringBuilder& other) : buffer_(other.buffer_) {}
auto StringBuilder::operator=(const StringBuilder& other) -> StringBuilder& {
if (this != &other) {
buffer_ = other.buffer_;
}
return *this;
}
void StringBuilder::append(const std::string& text) {
// TODO: Append all characters from text
(void)text;
}
auto StringBuilder::str() const -> std::string {
return std::string(buffer_.begin(), buffer_.end());
}
auto StringBuilder::size() const -> std::size_t { return buffer_.size(); }
} // namespace oop
+13
View File
@@ -0,0 +1,13 @@
#include "inheritance.hpp"
namespace oop {
Circle::Circle(double radius) : radius_(radius) {}
auto Circle::name() const -> std::string { return "Circle"; }
auto Circle::area() const -> double { return 3.141592653589793 * radius_ * radius_; }
Rectangle::Rectangle(double width, double height) : width_(width), height_(height) {}
auto Rectangle::name() const -> std::string { return "Rectangle"; }
auto Rectangle::area() const -> double { return width_ * height_; }
} // namespace oop
@@ -0,0 +1,26 @@
#include "polymorphism.hpp"
namespace oop {
auto total_area(const std::vector<std::unique_ptr<Shape>>& shapes) -> double {
double total = 0.0;
for (const auto& shape : shapes) {
// TODO: Add each shape's area using polymorphism
(void)shape;
}
return total;
}
auto shape_names(const std::vector<std::unique_ptr<Shape>>& shapes)
-> std::vector<std::string> {
std::vector<std::string> names;
for (const auto& shape : shapes) {
// TODO: Collect shape->name()
(void)shape;
}
return names;
}
auto Counter::copies() -> int { return copies_; }
} // namespace oop