Skip to content

Commit d4721c4

Browse files
committed
ex03 almost working
1 parent 0d5c851 commit d4721c4

File tree

8 files changed

+351
-3
lines changed

8 files changed

+351
-3
lines changed

ex03/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
# By: tblaase <[email protected]> +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: 2022/03/16 14:46:31 by tblaase #+# #+# #
9-
# Updated: 2022/03/16 15:10:40 by tblaase ### ########.fr #
9+
# Updated: 2022/03/17 12:13:21 by tblaase ### ########.fr #
1010
# #
1111
# **************************************************************************** #
1212

13-
NAME =
13+
NAME = unnecessary_violence
1414

1515
CC = c++
1616

@@ -31,7 +31,7 @@ UP = \033[A
3131
CUT = \033[K
3232

3333
#source files
34-
SRC_FILES =
34+
SRC_FILES = HumanA.cpp HumanB.cpp main.cpp Weapon.cpp
3535

3636
OBJ_FILES = $(SRC_FILES:.cpp=.o)
3737

ex03/include/HumanA.hpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* HumanA.hpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: tblaase <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/17 10:29:55 by tblaase #+# #+# */
9+
/* Updated: 2022/03/17 11:58:09 by tblaase ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
// Header-protection
14+
#pragma once
15+
16+
// Includes
17+
#include <string>
18+
#include <iostream>
19+
#include "Weapon.hpp"
20+
21+
// classes
22+
23+
class HumanA
24+
{
25+
private:
26+
Weapon _weapon;
27+
std::string _name;
28+
public:
29+
// Constructors
30+
HumanA();
31+
HumanA(std::string name, Weapon weapon);
32+
33+
// Deconstructors
34+
~HumanA();
35+
36+
// Public Methods
37+
void attack(void)const;
38+
// Getter
39+
const std::string getWeapon(void)const;
40+
const std::string getName(void)const;
41+
// Setter
42+
void setWeapon(Weapon weapon);
43+
void setName(std::string name);
44+
};

ex03/include/HumanB.hpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* HumanB.hpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: tblaase <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/17 10:30:07 by tblaase #+# #+# */
9+
/* Updated: 2022/03/17 12:39:33 by tblaase ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
// Header-protection
14+
#pragma once
15+
16+
// Includes
17+
#include <string>
18+
#include <iostream>
19+
#include "Weapon.hpp"
20+
21+
// classes
22+
23+
class HumanB
24+
{
25+
private:
26+
Weapon _weapon;
27+
std::string _name;
28+
public:
29+
// Constructors
30+
HumanB();
31+
HumanB(std::string name);
32+
33+
// Deconstructors
34+
~HumanB();
35+
36+
// Public Methods
37+
void attack(void)const;
38+
// Getter
39+
const std::string getWeapon(void)const;
40+
const std::string getName(void)const;
41+
// Setter
42+
void setWeapon(Weapon weapon);
43+
void setName(std::string name);
44+
};

ex03/include/Weapon.hpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* Weapon.hpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: tblaase <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/17 10:30:24 by tblaase #+# #+# */
9+
/* Updated: 2022/03/17 10:53:11 by tblaase ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
// Header-protection
14+
#pragma once
15+
16+
// Includes
17+
#include <string>
18+
#include <iostream>
19+
20+
// classes
21+
22+
class Weapon
23+
{
24+
private:
25+
std::string _type;
26+
27+
public:
28+
// Constructors
29+
Weapon();
30+
Weapon(std::string new_type);
31+
32+
// Deconstructors
33+
~Weapon();
34+
35+
// Public Methods
36+
37+
// Getter
38+
const std::string &getType(void)const;
39+
40+
// Setter
41+
void setType(std::string new_type);
42+
};

ex03/src/HumanA.cpp

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* HumanA.cpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: tblaase <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/17 10:30:58 by tblaase #+# #+# */
9+
/* Updated: 2022/03/21 14:40:15 by tblaase ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "HumanA.hpp"
14+
15+
16+
// Constructors
17+
HumanA::HumanA()
18+
{
19+
Weapon default_club = Weapon();
20+
this->setName("defaultA");
21+
this->setWeapon(default_club);
22+
}
23+
24+
HumanA::HumanA(std::string name, Weapon weapon)
25+
{
26+
this->setName(name);
27+
this->setWeapon(weapon);
28+
}
29+
30+
// Deconstructor
31+
HumanA::~HumanA()
32+
{
33+
}
34+
35+
// Public Methods
36+
void HumanA::attack(void)const
37+
{
38+
std::cout <<
39+
this->getName() <<
40+
" attacks with their " <<
41+
this->getWeapon() <<
42+
std::endl;
43+
}
44+
45+
// Getters
46+
const std::string HumanA::getName(void)const
47+
{
48+
return (this->_name);
49+
}
50+
51+
const std::string HumanA::getWeapon(void)const
52+
{
53+
return (this->_weapon.getType());
54+
}
55+
56+
// Setters
57+
void HumanA::setName(std::string name)
58+
{
59+
this->_name = name;
60+
}
61+
62+
void HumanA::setWeapon(Weapon weapon)
63+
{
64+
this->_weapon = weapon;
65+
}

ex03/src/HumanB.cpp

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* HumanB.cpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: tblaase <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/17 10:31:05 by tblaase #+# #+# */
9+
/* Updated: 2022/03/21 14:39:38 by tblaase ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "HumanB.hpp"
14+
15+
16+
// Constructor
17+
HumanB::HumanB() : _weapon(NULL)
18+
{
19+
this->setName("defaultA");
20+
}
21+
22+
HumanB::HumanB(std::string name) : _weapon(NULL)
23+
{
24+
this->setName(name);
25+
}
26+
// Deconstructor
27+
HumanB::~HumanB()
28+
{
29+
std::cout << "HumanB Deconstructor called" << std::endl;
30+
/*CODE*/
31+
}
32+
33+
// Public Methods
34+
void HumanB::attack(void)const
35+
{
36+
std::cout <<
37+
this->getName() <<
38+
" attacks with their ";
39+
if (HumanB::_weapon != NULL)
40+
{
41+
std::cout << this->getWeapon() <<
42+
std::endl;
43+
}
44+
else
45+
{
46+
std::cout << "Fists" <<
47+
std::endl;
48+
}
49+
}
50+
51+
// Getters
52+
const std::string HumanB::getName(void)const
53+
{
54+
return (this->_name);
55+
}
56+
57+
const std::string HumanB::getWeapon(void)const
58+
{
59+
return (this->_weapon.getType());
60+
}
61+
62+
// Setters
63+
void HumanB::setName(std::string name)
64+
{
65+
this->_name = name;
66+
}
67+
68+
void HumanB::setWeapon(Weapon weapon)
69+
{
70+
this->_weapon = weapon;
71+
}
72+

ex03/src/Weapon.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* Weapon.cpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: tblaase <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/17 10:30:41 by tblaase #+# #+# */
9+
/* Updated: 2022/03/17 10:53:38 by tblaase ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "Weapon.hpp"
14+
15+
16+
// Constructors
17+
18+
Weapon::Weapon()
19+
{
20+
this->_type = "default club";
21+
}
22+
23+
Weapon::Weapon(std::string new_type)
24+
{
25+
this->_type = new_type;
26+
}
27+
28+
// Deconstructor
29+
Weapon::~Weapon()
30+
{
31+
std::cout << "Weapon Deconstructor called" << std::endl;
32+
}
33+
34+
// Public Methods
35+
36+
// Getter
37+
const std::string &Weapon::getType(void)const
38+
{
39+
const std::string &typeREF = this->_type;
40+
return (typeREF);
41+
}
42+
43+
// Setter
44+
void Weapon::setType(std::string new_type)
45+
{
46+
this->_type = new_type;
47+
}

ex03/src/main.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* main.cpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: tblaase <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/17 10:47:17 by tblaase #+# #+# */
9+
/* Updated: 2022/03/17 11:05:04 by tblaase ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "HumanA.hpp"
14+
#include "HumanB.hpp"
15+
#include "Weapon.hpp"
16+
17+
int main()
18+
{
19+
{
20+
Weapon club = Weapon("crude spiked club");
21+
HumanA bob("Bob", club);
22+
bob.attack();
23+
club.setType("some other type of club");
24+
bob.attack();
25+
}
26+
{
27+
Weapon club = Weapon("crude spiked club");
28+
HumanB jim("Jim");
29+
jim.setWeapon(club);
30+
jim.attack();
31+
club.setType("some other type of club");
32+
jim.attack();
33+
}
34+
return (EXIT_SUCCESS);

0 commit comments

Comments
 (0)