ex02 finished

This commit is contained in:
2025-11-10 20:50:53 +01:00
parent 2438853723
commit fa95f2b5b6
14 changed files with 567 additions and 0 deletions

62
ex02/Brain/Brain.cpp Normal file
View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Brain.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/10 11:22:21 by aortigos #+# #+# */
/* Updated: 2025/11/10 20:43:06 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Brain.hpp"
Brain::Brain()
{
std::cout << "Brain has been created" << std::endl;
int i = 0;
while (i < 100)
{
ideas[i++] = "Empty idea";
}
}
Brain::~Brain()
{
std::cout << "Brain has been destroyed" << std::endl;
}
Brain::Brain(const Brain &other)
{
std::cout << "Brain copied" << std::endl;
*this = other;
}
Brain& Brain::operator=(const Brain &other)
{
std::cout << "Brain copy assignment called" << std::endl;
if (this != &other)
{
int i = 0;
while (i < 100)
{
this->ideas[i] = other.ideas[i];
i++;
}
}
return (*this);
}
void Brain::setIdea(int i, const std::string &idea)
{
if (i >= 0 && i < 100)
ideas[i] = idea;
}
std::string Brain::getIdea(int i) const
{
if (i >= 0 && i < 100)
return (this->ideas[i]);
return ("Invalid idea");
}

34
ex02/Brain/Brain.hpp Normal file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Brain.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/10 11:22:17 by aortigos #+# #+# */
/* Updated: 2025/11/10 20:42:43 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BRAIN_HPP
# define BRAIN_HPP
#include <iostream>
class Brain
{
private:
std::string ideas[100];
public:
Brain();
~Brain();
Brain(const Brain &other);
Brain& operator=(const Brain &other);
void setIdea(int i, const std::string &idea);
std::string getIdea(int i) const;
};
#endif