Skip to content

Commit ce1fcf1

Browse files
committed
module 07 submited with grade 100
1 parent 32c0669 commit ce1fcf1

File tree

10 files changed

+739
-0
lines changed

10 files changed

+739
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
| [Module 04](https://github.com/waltergcc/42-cpp_modules/tree/main/module_04) | 100 |
1010
| [Module 05](https://github.com/waltergcc/42-cpp_modules/tree/main/module_05) | 100 |
1111
| [Module 06](https://github.com/waltergcc/42-cpp_modules/tree/main/module_06) | 100 |
12+
| [Module 07](https://github.com/waltergcc/42-cpp_modules/tree/main/module_07) | 100 |
13+

module_07/ex00/Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# **************************************************************************** #
2+
# #
3+
# ::: :::::::: #
4+
# Makefile :+: :+: :+: #
5+
# +:+ +:+ +:+ #
6+
# By: wcorrea- <[email protected]> +#+ +:+ +#+ #
7+
# +#+#+#+#+#+ +#+ #
8+
# Created: 2023/07/07 17:07:34 by wcorrea- #+# #+# #
9+
# Updated: 2023/09/09 00:50:41 by wcorrea- ### ########.fr #
10+
# #
11+
# **************************************************************************** #
12+
13+
NAME = whatever
14+
15+
SRC = main.cpp
16+
17+
OBJS = ${SRC:.cpp=.o}
18+
19+
INCLUDE = -I .
20+
21+
CC = c++
22+
RM = rm -f
23+
CPPFLAGS = -Wall -Wextra -Werror -pedantic -std=c++98
24+
25+
.cpp.o:
26+
${CC} ${CPPFLAGS} ${INCLUDE} -c $< -o ${<:.cpp=.o}
27+
28+
$(NAME): ${OBJS}
29+
${CC} ${CPPFLAGS} ${INCLUDE} ${OBJS} -o ${NAME}
30+
31+
all: ${NAME}
32+
33+
clean:
34+
${RM} ${OBJS}
35+
36+
fclean: clean
37+
${RM} ${NAME}
38+
39+
re: clean all
40+
41+
.PHONY: all clean re

module_07/ex00/main.cpp

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* main.cpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: wcorrea- <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/09/04 19:26:23 by wcorrea- #+# #+# */
9+
/* Updated: 2023/09/09 00:44:02 by wcorrea- ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "whatever.hpp"
14+
15+
#define RESET "\033[0m"
16+
#define RED "\033[31m"
17+
#define GREEN "\033[32m"
18+
19+
void pressEnter(void)
20+
{
21+
std::cout << std::endl << "press ENTER to continue" << std::endl;
22+
std::cin.ignore();
23+
std::cout << "\033c";
24+
}
25+
26+
void titleHeader(const std::string& message)
27+
{
28+
std::cout << "\033c";
29+
int standartSize = 34;
30+
int messageSize = message.length();
31+
int spaces = (standartSize - messageSize) / 2;
32+
33+
std::cout << "************************************" << std::endl << "*";
34+
for (int i = 0; i < spaces; i++)
35+
std::cout << " ";
36+
std::cout << message;
37+
for (int i = 0; i < spaces; i++)
38+
std::cout << " ";
39+
std::cout << "*" << std::endl << "************************************" << std::endl << std::endl;
40+
}
41+
42+
int main(void)
43+
{
44+
{
45+
titleHeader("SUBJECT TEST");
46+
47+
int a = 2;
48+
int b = 3;
49+
50+
::swap( a, b );
51+
std::cout << "a = " << a << ", b = " << b << std::endl;
52+
std::cout << "min( a, b ) = " << ::min( a, b ) << std::endl;
53+
std::cout << "max( a, b ) = " << ::max( a, b ) << std::endl;
54+
55+
std::string c = "chaine1";
56+
std::string d = "chaine2";
57+
58+
::swap(c, d);
59+
std::cout << "c = " << c << ", d = " << d << std::endl;
60+
std::cout << "min( c, d ) = " << ::min( c, d ) << std::endl;
61+
std::cout << "max( c, d ) = " << ::max( c, d ) << std::endl;
62+
}
63+
pressEnter();
64+
{
65+
titleHeader("SAME TYPE TEST");
66+
67+
std::string first = "first";
68+
std::string second = "second";
69+
70+
std::cout << "===== before swap =====" << std::endl;
71+
std::cout << "first = " << first << std::endl;
72+
std::cout << "second = " << second << std::endl;
73+
std::cout << std::endl;
74+
75+
::swap(first, second);
76+
77+
std::cout << "===== after swap =====" << std::endl;
78+
std::cout << "first = " << first << std::endl;
79+
std::cout << "second = " << second << std::endl;
80+
std::cout << std::endl;
81+
82+
float a = -987.6895659f;
83+
float b = -987.6545654f;
84+
85+
std::cout << "float a = " << a << std::endl;
86+
std::cout << "float b = " << b << std::endl;
87+
std::cout << std::endl;
88+
89+
std::cout << "who is min between a and b? ";
90+
std::cout << ::min(a, b) << std::endl;
91+
92+
std::cout << "who is max between a and b? ";
93+
std::cout << ::max(a, b) << std::endl;
94+
}
95+
pressEnter();
96+
// {
97+
// titleHeader("DIFFERENT TYPE TEST");
98+
99+
// std::string first = "first";
100+
// char second = 's';
101+
102+
// std::cout << "===== before swap =====" << std::endl;
103+
// std::cout << "first = " << first << std::endl;
104+
// std::cout << "second = " << second << std::endl;
105+
// std::cout << std::endl;
106+
107+
// ::swap(first, second);
108+
// std::cout << "===== after swap =====" << std::endl;
109+
// std::cout << "first = " << first << std::endl;
110+
// std::cout << "second = " << second << std::endl;
111+
// std::cout << std::endl;
112+
113+
// int a = 123;
114+
// float b = 123.456f;
115+
116+
// std::cout << "int a = " << a << std::endl;
117+
// std::cout << "float b = " << b << std::endl;
118+
// std::cout << std::endl;
119+
120+
// std::cout << "who is min between a and b? ";
121+
// std::cout << ::min(a, b) << std::endl;
122+
123+
// std::cout << "who is max between a and b? ";
124+
// std::cout << ::max(a, b) << std::endl;
125+
// }
126+
}

module_07/ex00/whatever.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* whatever.hpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: wcorrea- <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/09/04 19:26:35 by wcorrea- #+# #+# */
9+
/* Updated: 2023/09/09 00:21:27 by wcorrea- ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#pragma once
14+
15+
#include <iostream>
16+
#include <string>
17+
18+
template <typename T>
19+
void swap(T &a, T &b)
20+
{
21+
T tmp = a;
22+
a = b;
23+
b = tmp;
24+
}
25+
26+
template <typename T>
27+
T const &min(T const &a, T const &b)
28+
{
29+
return (a < b ? a : b);
30+
}
31+
32+
template <typename T>
33+
T const &max(T const &a, T const &b)
34+
{
35+
return (a > b ? a : b);
36+
}

module_07/ex01/Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# **************************************************************************** #
2+
# #
3+
# ::: :::::::: #
4+
# Makefile :+: :+: :+: #
5+
# +:+ +:+ +:+ #
6+
# By: wcorrea- <[email protected]> +#+ +:+ +#+ #
7+
# +#+#+#+#+#+ +#+ #
8+
# Created: 2023/07/07 17:07:34 by wcorrea- #+# #+# #
9+
# Updated: 2023/09/09 00:50:31 by wcorrea- ### ########.fr #
10+
# #
11+
# **************************************************************************** #
12+
13+
NAME = iter
14+
15+
SRC = main.cpp
16+
17+
OBJS = ${SRC:.cpp=.o}
18+
19+
INCLUDE = -I .
20+
21+
CC = c++
22+
RM = rm -f
23+
CPPFLAGS = -Wall -Wextra -Werror -pedantic -std=c++98
24+
25+
.cpp.o:
26+
${CC} ${CPPFLAGS} ${INCLUDE} -c $< -o ${<:.cpp=.o}
27+
28+
$(NAME): ${OBJS}
29+
${CC} ${CPPFLAGS} ${INCLUDE} ${OBJS} -o ${NAME}
30+
31+
all: ${NAME}
32+
33+
clean:
34+
${RM} ${OBJS}
35+
36+
fclean: clean
37+
${RM} ${NAME}
38+
39+
re: clean all
40+
41+
.PHONY: all clean re

module_07/ex01/iter.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* iter.hpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: wcorrea- <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/09/04 19:26:35 by wcorrea- #+# #+# */
9+
/* Updated: 2023/09/11 15:07:05 by wcorrea- ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#pragma once
14+
15+
#include <iostream>
16+
#include <string>
17+
18+
template <typename T>
19+
void printContent(T const &content)
20+
{
21+
std::cout << content << std::endl;
22+
}
23+
24+
template <typename T, typename F>
25+
void iter(T *array, int size, F f)
26+
{
27+
for (int i = 0; i < size; i++)
28+
f(array[i]);
29+
}

module_07/ex01/main.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* main.cpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: wcorrea- <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/09/04 19:26:23 by wcorrea- #+# #+# */
9+
/* Updated: 2023/09/11 14:56:40 by wcorrea- ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "iter.hpp"
14+
15+
#define RESET "\033[0m"
16+
#define RED "\033[31m"
17+
#define GREEN "\033[32m"
18+
19+
void pressEnter(void)
20+
{
21+
std::cout << std::endl << "press ENTER to continue" << std::endl;
22+
std::cin.ignore();
23+
std::cout << "\033c";
24+
}
25+
26+
void titleHeader(const std::string& message)
27+
{
28+
std::cout << "\033c";
29+
int standartSize = 34;
30+
int messageSize = message.length();
31+
int spaces = (standartSize - messageSize) / 2;
32+
33+
std::cout << "************************************" << std::endl << "*";
34+
for (int i = 0; i < spaces; i++)
35+
std::cout << " ";
36+
std::cout << message;
37+
for (int i = 0; i < spaces; i++)
38+
std::cout << " ";
39+
std::cout << "*" << std::endl << "************************************" << std::endl << std::endl;
40+
}
41+
42+
int main(void)
43+
{
44+
{
45+
titleHeader("INT ARRAY TEST");
46+
47+
int array[] = {1, 22, 333, 4444, 55555, 666666, 7777777, 88888888, 999999999, 1010101010};
48+
49+
::iter(array, 10, printContent<int>);
50+
}
51+
pressEnter();
52+
{
53+
titleHeader("STRING ARRAY TEST");
54+
55+
std::string array[] = {
56+
"first", "second", "third", "fourth",
57+
"fifth", "sixth", "seventh", "eighth",
58+
"ninth", "tenth"};
59+
60+
::iter(array, 10, printContent<std::string>);
61+
}
62+
pressEnter();
63+
}

0 commit comments

Comments
 (0)