narnaud 3 years ago
parent
commit
274acb8d47
  1. 16
      CPP00/ex00/Makefile
  2. 34
      CPP00/ex00/main.cpp
  3. BIN
      CPP00/ex00/megaphone
  4. 55
      CPP00/ex01/Contact.cpp
  5. 39
      CPP00/ex01/Contact.hpp
  6. 72
      CPP00/ex01/PhoneBook.cpp
  7. 29
      CPP00/ex01/PhoneBook.hpp
  8. BIN
      CPP00/ex01/a.out
  9. 22
      CPP00/ex01/main.cpp
  10. 10
      README.md

16
CPP00/ex00/Makefile

@ -0,0 +1,16 @@
NAME = megaphone
SRC = main.cpp
CC = c++
CFLAGS = -std=c++98 -Wall -Werror -Wextra
RM = rm -rf
$(NAME): $(SRC)
$(CC) $(CFLAGS) $(SRC) -o $(NAME)
all: $(NAME)
clean:
$(RM) $(NAME)
.PHONY: all re

34
CPP00/ex00/main.cpp

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/13 08:20:39 by narnaud #+# #+# */
/* Updated: 2022/06/13 08:44:34 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
# include <iostream>
# include <locale.h>
int main(int argc, char **argv)
{
if (argc < 2)
std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *";
else
{
int i = 1;
char *ret;
while (i < argc)
{
ret = argv[i];
while (*ret)
std::cout << (char)toupper(*(ret++));
i++;
}
}
std::cout << std::endl;
return (EXIT_SUCCESS);
}

BIN
CPP00/ex00/megaphone

Binary file not shown.

55
CPP00/ex01/Contact.cpp

@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Contact.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/13 13:29:20 by narnaud #+# #+# */
/* Updated: 2022/06/13 16:48:13 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "Contact.hpp"
Contact::Contact(){}
void Contact::set(int id)
{
this->id = id;
std::cout << "Enter new contact first name:\n";
std::cin >> this->datas[FIRST];
std::cout << "Enter new contact last name:\n";
std::cin >> this->datas[LAST];
std::cout << "Enter new contact nickname:\n";
std::cin >> this->datas[NICK];
std::cout << "Enter new contact number:\n";
std::cin >> this->datas[NUMBER];
std::cout << "Enter new contact secret:\n";
std::cin >> this->datas[SECRET];
std::cout << std::endl;
}
void Contact::summary()
{
std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n";
std::cout << "|";
std::cout << std::setw(2) << this->id;
std::cout << "|";
for (int i = 0; i <= SECRET; i++)
{
if (this->datas[i].length() < 10)
std::cout << std::setw(10) << this->datas[i] << "|";
else
std::cout << this->datas[i].substr(0, 9) << "." << "|";
}
std::cout << "\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n";
}
void Contact::get()
{
std::cout <<"First name : " << this->datas[FIRST] << std::endl;
std::cout <<"Last name : " << this->datas[LAST] << std::endl;
std::cout <<"Nick name : " << this->datas[NICK] << std::endl;
std::cout <<"Phone nb : " << this->datas[NUMBER] << std::endl;
std::cout <<"Dark secret : " << this->datas[SECRET] << std::endl;
}

39
CPP00/ex01/Contact.hpp

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Contact.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/13 13:02:55 by narnaud #+# #+# */
/* Updated: 2022/06/13 16:35:43 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CONTACT_HPP
# define CONTACT_HPP
# include <iostream>
# include <string>
# include <iomanip>
enum e_datas
{
FIRST,
LAST,
NICK,
NUMBER,
SECRET,
};
class Contact
{
public:
Contact();
void set(int id);
void summary();
void get();
private:
int id;
std::string datas[5];
};
#endif

72
CPP00/ex01/PhoneBook.cpp

@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* PhoneBook.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/13 10:14:16 by narnaud #+# #+# */
/* Updated: 2022/06/13 16:00:30 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "PhoneBook.hpp"
PhoneBook::PhoneBook()
{
this->id = 0;
}
void PhoneBook::add()
{
int id = this->id % CONTACTS_AMOUNT;
if (this->id > 7)
{
std::cout << "You gonna remove the contact n." << id;
std::cout << "\nTo continue, type 'y': ";
std::string confirm = 0;
std::cin >> confirm;
if (confirm != "y")
{
std::cout << "\nAbort.\n";
return ;
}
std::cout << std::endl;
}
this->contacts[id].set(id);
this->id++;
}
void PhoneBook::search()
{
int id = 0;
Contact ctct;
ctct = this->contacts[0];
while (id++ < this->id % CONTACTS_AMOUNT)
{
ctct.summary();
ctct = this->contacts[id];
}
std::string sid;
std::cout << "Which contact do you wanna see [id?]:";
std::cin >> sid;
id = std::stoi(sid);
ctct = this->contacts[id];
ctct.get();
}
int PhoneBook::run()
{
std::cout << "PhoneBook.\n" << "Commands available : ADD, SEARCH, EXIT.\n";
std::cout << "What do you want?\n";
std::cin >> this->cmd;
if (cmd == "EXIT")
return (EXIT_FAILURE);
if (cmd == "SEARCH")
this->search();
else if (cmd == "ADD")
this->add();
else
std::cout << "Unknown command.\n";
return (EXIT_SUCCESS);
}

29
CPP00/ex01/PhoneBook.hpp

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* PhoneBook.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/13 09:31:44 by narnaud #+# #+# */
/* Updated: 2022/06/13 15:35:30 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PHONEBOOK_HPP
# define PHONEBOOK_HPP
# include "Contact.hpp"
# define CONTACTS_AMOUNT 8
class PhoneBook
{
public:
PhoneBook();
int run();
private:
Contact contacts[CONTACTS_AMOUNT];
std::string cmd;
int id;
void add();
void search();
};
#endif

BIN
CPP00/ex01/a.out

Binary file not shown.

22
CPP00/ex01/main.cpp

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/13 09:31:46 by narnaud #+# #+# */
/* Updated: 2022/06/13 15:16:37 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "PhoneBook.hpp"
int main(void)
{
PhoneBook pb;
while (pb.run() == EXIT_SUCCESS)
;
return (EXIT_SUCCESS);
}

10
README.md

@ -1,2 +1,12 @@
# CPP
## Subjects :
- [CPP00](https://cdn.intra.42.fr/pdf/pdf/48426/fr.subject.pdf) + ress.
- [CPP01](https://cdn.intra.42.fr/pdf/pdf/50707/en.subject.pdf)
- [CPP02](https://cdn.intra.42.fr/pdf/pdf/48502/fr.subject.pdf)
- [CPP03](https://cdn.intra.42.fr/pdf/pdf/48500/fr.subject.pdf)
- [CPP04](https://cdn.intra.42.fr/pdf/pdf/48498/fr.subject.pdf)
- [CPP05](https://cdn.intra.42.fr/pdf/pdf/51045/fr.subject.pdf)
- [CPP06](https://cdn.intra.42.fr/pdf/pdf/48493/fr.subject.pdf)
- [CPP07](https://cdn.intra.42.fr/pdf/pdf/48487/fr.subject.pdf) + .cpp
- [CPP08](https://cdn.intra.42.fr/pdf/pdf/48485/fr.subject.pdf)

Loading…
Cancel
Save