Adding the menu and started the new syntaxe with the two classes
This commit is contained in:
parent
e657cd8012
commit
1e42383953
3 changed files with 38 additions and 17 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/17 14:56:49 by rparodi #+# #+# */
|
/* Created: 2024/10/17 14:56:49 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/18 12:18:04 by rparodi ### ########.fr */
|
/* Updated: 2024/10/18 16:02:09 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,8 +21,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "color.hpp"
|
#include "color.hpp"
|
||||||
|
|
||||||
#define ERROR 1
|
#define MENU CLR_BLUE << "ADD" << CLR_RESET << ":\tAdding a new contact" << std::endl << CLR_BLUE << "SEARCH" << CLR_RESET << ":\tSearching a contact in the list" << std::endl << CLR_BLUE << "EXIT" << CLR_RESET << ":\texit the program" << std::endl
|
||||||
#define NO_ERROR 0
|
|
||||||
|
|
||||||
std::string get_input(const char *str);
|
std::string get_input(const char *str);
|
||||||
|
|
||||||
|
|
@ -47,8 +46,8 @@ class PhoneBook
|
||||||
public:
|
public:
|
||||||
void add();
|
void add();
|
||||||
void search();
|
void search();
|
||||||
|
Contact array_contact[8];
|
||||||
private:
|
private:
|
||||||
Contact _array_contact[8];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/17 14:55:18 by rparodi #+# #+# */
|
/* Created: 2024/10/17 14:55:18 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/18 12:19:07 by rparodi ### ########.fr */
|
/* Updated: 2024/10/18 15:58:15 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -38,19 +38,19 @@ std::string get_input(const char *err_msg)
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::string input;
|
std::string input;
|
||||||
Contact array_contact[8];
|
PhoneBook phonebook;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
std::cout << MENU << std::endl;
|
||||||
input = get_input("SELECT MENU [main.cpp:38]");
|
input = get_input("SELECT MENU [main.cpp:38]");
|
||||||
if (strcmp(input.c_str(), "ADD"))
|
if (strcmp(input.c_str(), "ADD") == 0)
|
||||||
{
|
{
|
||||||
std::cout << "adding" << std::endl;
|
phonebook.array_contact[i].init_new(i);
|
||||||
array_contact[i].init_new(i);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (strcmp(input.c_str(), "EXIT"))
|
if (strcmp(input.c_str(), "EXIT") == 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/17 15:09:21 by rparodi #+# #+# */
|
/* Created: 2024/10/17 15:09:21 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/17 16:44:08 by rparodi ### ########.fr */
|
/* Updated: 2024/10/18 15:55:41 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,19 +15,41 @@
|
||||||
void Contact::init_new(int id)
|
void Contact::init_new(int id)
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
|
std::cout << "First Name:\t";
|
||||||
_first_name = get_input("first_name [phonebook.cpp:18]");
|
_first_name = get_input("first_name [phonebook.cpp:18]");
|
||||||
|
std::cout << "Last Name:\t";
|
||||||
_last_name = get_input("last_name [phonebook.cpp:19]");
|
_last_name = get_input("last_name [phonebook.cpp:19]");
|
||||||
|
std::cout << "Nickname:\t";
|
||||||
_nickname = get_input("nickname [phonebook.cpp:20]");
|
_nickname = get_input("nickname [phonebook.cpp:20]");
|
||||||
|
std::cout << "Number:\t";
|
||||||
_number = get_input("number [phonebook.cpp:21]");
|
_number = get_input("number [phonebook.cpp:21]");
|
||||||
|
std::cout << "Secret:\t";
|
||||||
_secret = get_input("secret [phonebook.cpp:22]");
|
_secret = get_input("secret [phonebook.cpp:22]");
|
||||||
|
Contact::print();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Contact::print()
|
void Contact::print()
|
||||||
{
|
{
|
||||||
std::cout << "|" << std::setw(10) << _id << "|";
|
std::cout << "|" << std::setw(10) << _id;
|
||||||
std::cout << "|" << std::setw(10) << _first_name << "|";
|
if (_first_name.length() > 10)
|
||||||
std::cout << "|" << std::setw(10) << _last_name << "|";
|
std::cout << "|" << std::setw(10) << _first_name.substr(0, 9) << ".";
|
||||||
std::cout << "|" << std::setw(10) << _nickname << "|";
|
else
|
||||||
std::cout << "|" << std::setw(10) << _number << "|";
|
std::cout << "|" << std::setw(10) << _first_name;
|
||||||
std::cout << "|" << std::setw(10) << _secret << "|";
|
if (_last_name.length() > 10)
|
||||||
|
std::cout << "|" << std::setw(10) << _last_name.substr(0, 9) << ".";
|
||||||
|
else
|
||||||
|
std::cout << "|" << std::setw(10) << _last_name;
|
||||||
|
if (_nickname.length() > 10)
|
||||||
|
std::cout << "|" << std::setw(10) << _nickname.substr(0, 9) << ".";
|
||||||
|
else
|
||||||
|
std::cout << "|" << std::setw(10) << _nickname;
|
||||||
|
if (_number.length() > 10)
|
||||||
|
std::cout << "|" << std::setw(10) << _number.substr(0, 9) << ".";
|
||||||
|
else
|
||||||
|
std::cout << "|" << std::setw(10) << _number;
|
||||||
|
if (_secret.length() > 10)
|
||||||
|
std::cout << "|" << std::setw(10) << _secret.substr(0, 9) << ".";
|
||||||
|
else
|
||||||
|
std::cout << "|" << std::setw(10) << _secret;
|
||||||
|
std::cout << "|" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue