ex01 done

This commit is contained in:
2026-03-21 16:58:41 +01:00
parent f05f057399
commit cbcc65b196
3 changed files with 139 additions and 0 deletions

64
ex01/main.cpp Normal file
View File

@@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/21 16:57:02 by aortigos #+# #+# */
/* Updated: 2026/03/21 16:57:36 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "iter.hpp"
template <typename T>
void printElement(const T& elem)
{
std::cout << elem << " ";
}
void toUpper(std::string& str)
{
for (size_t i = 0; i < str.length(); i++)
str[i] = std::toupper(str[i]);
}
void increment(int& x)
{
x++;
}
int main()
{
// -------- STRING ARRAY --------
std::string words[] = {"hola", "mundo", "iter"};
size_t wordsLen = sizeof(words) / sizeof(words[0]);
std::cout << "Original strings: ";
iter(words, wordsLen, printElement<std::string>);
std::cout << std::endl;
iter(words, wordsLen, toUpper);
std::cout << "Uppercase strings: ";
iter(words, wordsLen, printElement<std::string>);
std::cout << std::endl;
// -------- INT ARRAY --------
int numbers[] = {1, 2, 3, 4};
size_t numLen = sizeof(numbers) / sizeof(numbers[0]);
std::cout << "\nOriginal ints: ";
iter(numbers, numLen, printElement<int>);
std::cout << std::endl;
iter(numbers, numLen, increment);
std::cout << "Incremented ints: ";
iter(numbers, numLen, printElement<int>);
std::cout << std::endl;
return 0;
}