commit 95c25afc0378131740190c9ca1fe24a37130e16c Author: Angel Ortigosa Perez Date: Sun Sep 7 10:02:26 2025 +0200 cpp00... diff --git a/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..dffa408 --- /dev/null +++ b/ex00/Makefile @@ -0,0 +1,26 @@ +NAME=megaphone + +SRCS=megaphone.cpp + +OBJS=$(SRCS:.cpp=.o) + +CC=g++ +CFLAGS=-Wall -Wextra -Werror -std=c++98 + +all: $(NAME) + +$(NAME): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $(NAME) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ex00/megaphone.cpp b/ex00/megaphone.cpp new file mode 100644 index 0000000..e108f05 --- /dev/null +++ b/ex00/megaphone.cpp @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* megaphone.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +int main(int argc, char **argv) +{ + int i; + int j; + + i = 1; + j = 0; + if (argc >= 2) + { + while (argv[i]) + { + j = 0; + while (argv[i][j] != '\0') + { + std::cout << (char)std::toupper(argv[i][j]); + j++; + } + if (argv[i+1]) + std::cout << " "; + i++; + } + } else + std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *"; + std::cout << std::endl; + return (0); +} \ No newline at end of file diff --git a/ex01/Contact/Contact.cpp b/ex01/Contact/Contact.cpp new file mode 100644 index 0000000..4334c86 --- /dev/null +++ b/ex01/Contact/Contact.cpp @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Contact.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos name = "NULL"; +} + +std::string Contact::getName() +{ + return (this->name); +} + +std::string Contact::getSurname() +{ + return (this->surname); +} + +std::string Contact::getNickname() +{ + return (this->nickname); +} + +std::string Contact::getPhoneNumber() +{ + return (this->phoneNumber); +} + +std::string Contact::getSecret() +{ + return (this->secret); +} + +void Contact::setName(std::string str) +{ + this->name = str; +} + +void Contact::setSurname(std::string str) +{ + this->surname = str; +} + +void Contact::setNickname(std::string str) +{ + this->nickname = str; +} + +void Contact::setPhoneNumber(std::string str) +{ + this->phoneNumber = str; +} + +void Contact::setSecret(std::string str) +{ + this->secret = str; +} diff --git a/ex01/Contact/Contact.hpp b/ex01/Contact/Contact.hpp new file mode 100644 index 0000000..8fdc069 --- /dev/null +++ b/ex01/Contact/Contact.hpp @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Contact.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +class Contact +{ + private: + std::string name; + std::string surname; + std::string nickname; + std::string phoneNumber; + std::string secret; + + public: + Contact(); + void setName(std::string str); + void setSurname(std::string str); + void setNickname(std::string str); + void setPhoneNumber(std::string str); + void setSecret(std::string str); + + std::string getName(); + std::string getSurname(); + std::string getNickname(); + std::string getPhoneNumber(); + std::string getSecret(); +}; + +#endif \ No newline at end of file diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..bffb473 --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,26 @@ +NAME=phonebook + +SRCS=main.cpp Contact/Contact.cpp Phonebook/Phonebook.cpp + +OBJS=$(SRCS:.cpp=.o) + +CC=g++ +CFLAGS=-Wall -Wextra -Werror -std=c++98 + +all: $(NAME) + +$(NAME): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $(NAME) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ex01/Phonebook/Phonebook.cpp b/ex01/Phonebook/Phonebook.cpp new file mode 100644 index 0000000..eb52753 --- /dev/null +++ b/ex01/Phonebook/Phonebook.cpp @@ -0,0 +1,166 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Phonebook.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos index = 0; +} + +void Phonebook::addContacts() +{ + std::string str; + + str = ""; + while (str == "") + { + std::cout << "Introduzca el nombre: "; + std::getline(std::cin, str); + } + this->contacts[this->index % 8].setName(str); + + str = ""; + while (str == "") + { + std::cout << "Introduzca el apellido: "; + std::getline(std::cin, str); + } + this->contacts[this->index % 8].setSurname(str); + + str = ""; + while (str == "") + { + std::cout << "Introduzca el nickname: "; + std::getline(std::cin, str); + } + this->contacts[this->index % 8].setNickname(str); + + str = ""; + while (str == "") + { + std::cout << "Introduzca el telefono: "; + std::getline(std::cin, str); + } + this->contacts[this->index % 8].setPhoneNumber(str); + + str = ""; + while (str == "") + { + std::cout << "Introduzca el secreto: "; + std::getline(std::cin, str); + } + this->contacts[this->index % 8].setSecret(str); + + this->index++; +} + +static void print_name(std::string str) +{ + int i; + int j; + + i = 9; + j = 0; + + while (str[j] != '\0') + j++; + while (i >= j && j <= 10) + { + std::cout << " "; + i--; + } + i = 0; + while (str[i] != '\0' && i <= 9) + { + if (i == 9 && j > 10) + std::cout << "."; + else + std::cout << str[i]; + i++; + } + std::cout << "|"; + +} + +void Phonebook::print_table() +{ + int i; + int j; + std::string c; + + i = 0; + j = 0; + std::cout << "---------------------------------------------" << std::endl; + std::cout << "| Index| Nombre| Apellido| Nickname|" << std::endl; + std::cout << "---------------------------------------------" << std::endl; + + if (this->index >= 9) + j = 8; + else + j = this->index; + while (i < j) + { + c = std::string(1, i + '0'); + std::cout << "|"; + print_name(c); + print_name(this->contacts[i].getName()); + print_name(this->contacts[i].getSurname()); + print_name(this->contacts[i].getNickname()); + std::cout << std::endl; + i++; + } + std::cout << "---------------------------------------------" << std::endl; + +} + +void Phonebook::find_contact(int i) +{ + if(this->contacts[i].getName() != "NULL") + { + std::cout << "----------------------------------" << std::endl; + std::cout << "Nombre: " << this->contacts[i].getName() << std::endl; + std::cout << "Apellido: " << this->contacts[i].getSurname() << std::endl; + std::cout << "Nickname: " << this->contacts[i].getNickname() << std::endl; + std::cout << "Numero: " << this->contacts[i].getPhoneNumber() << std::endl; + std::cout << "Secreto: " << this->contacts[i].getSecret() << std::endl; + std::cout << "----------------------------------" << std::endl; + } else { + std::cout << "Contacto no encontrado" << std::endl; + } +} + +void Phonebook::showContacts() +{ + int i; + std::string str; + + i = 0; + str = ""; + if (this->index == 0) + { + std::cout << "No hay contactos." << std::endl; + return ; + } + + print_table(); + + while (str == "" || str.length() != 1 || (str[0] < '0' || str[0] > '7')) + { + std::cout << "Introduzca el index a buscar: "; + std::getline(std::cin, str); + } + + i = str[0] - '0'; + + find_contact(i); +} diff --git a/ex01/Phonebook/Phonebook.hpp b/ex01/Phonebook/Phonebook.hpp new file mode 100644 index 0000000..a58fa50 --- /dev/null +++ b/ex01/Phonebook/Phonebook.hpp @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Phonebook.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +# include +# include "../Contact/Contact.hpp" + +class Phonebook +{ + private: + int index; + Contact contacts[8]; + + public: + Phonebook(); + void addContacts(); + void showContacts(); + void print_table(); + void find_contact(int i); +}; + +#endif \ No newline at end of file diff --git a/ex01/main.cpp b/ex01/main.cpp new file mode 100644 index 0000000..1f5b4ef --- /dev/null +++ b/ex01/main.cpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos "; + std::getline(std::cin, str); + + if (str == "ADD") + ph.addContacts(); + else if (str == "SHOW") + ph.showContacts(); + std::cout << std::endl; + } + + return (0); +} \ No newline at end of file