phonebook operationnel et coloree
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#include "Contact.class.hpp"
|
||||
|
||||
Contact::Contact( void ) {
|
||||
this->add_first("NOT DEFINED");
|
||||
this->add_last("NOT DEFINED");
|
||||
this->add_nick("NOT DEFINED");
|
||||
this->add_num("NOT DEFINED");
|
||||
this->add_secret("NOT DEFINED");
|
||||
this->add_first("");
|
||||
this->add_last("");
|
||||
this->add_nick("");
|
||||
this->add_num("");
|
||||
this->add_secret("");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "Contact.class.hpp"
|
||||
|
||||
PhoneBook::PhoneBook( void ) {
|
||||
|
||||
this->contact_count = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -9,18 +11,124 @@ PhoneBook::~PhoneBook( void ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
Contact new_contact;
|
||||
void PhoneBook::add_contact() {
|
||||
|
||||
new_contact.add_first(name);
|
||||
new_contact.add_last("lamy");
|
||||
new_contact.add_nick("hugonosaure");
|
||||
new_contact.add_num("0123456789");
|
||||
new_contact.add_secret("je suis un dino");
|
||||
std::string str;
|
||||
int it;
|
||||
|
||||
std::cout << "FIRST NAME : " << new_contact.get_first() << std::endl;
|
||||
std::cout << "LAST NAME : " << new_contact.get_last() << std::endl;
|
||||
std::cout << "NICKNAME : " << new_contact.get_nick() << std::endl;
|
||||
std::cout << "NUMBER : " << new_contact.get_num() << std::endl;
|
||||
std::cout << "SECRET : " << new_contact.get_secret() << std::endl;
|
||||
*/
|
||||
this->contact_count++;
|
||||
it = this->contact_count;
|
||||
if (it > 8)
|
||||
it = 1;
|
||||
it--;
|
||||
|
||||
std::cout << B_CYAN "enter a first name pliz :" << std::endl;
|
||||
while (contact[it].get_first().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
this->contact[it].add_first(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a last name pliz :" << std::endl;
|
||||
while (contact[it].get_last().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
this->contact[it].add_last(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a nickname pliz :" << std::endl;
|
||||
while (contact[it].get_nick().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
this->contact[it].add_nick(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a number pliz :" << std::endl;
|
||||
while (contact[it].get_num().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
this->contact[it].add_num(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a secret of this contact pliz :" << std::endl;
|
||||
while (contact[it].get_secret().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
this->contact[it].add_secret(str);
|
||||
}
|
||||
}
|
||||
|
||||
std::string truncate(std::string str, size_t len) {
|
||||
|
||||
if (str.length() > len)
|
||||
return str.substr(0, len - 1) + ".";
|
||||
return str;
|
||||
|
||||
}
|
||||
|
||||
void PhoneBook::print_phonebook() {
|
||||
|
||||
std::cout << std::endl;
|
||||
int it;
|
||||
|
||||
it = this->contact_count;
|
||||
if (it > 8)
|
||||
it = 8;
|
||||
it--;
|
||||
|
||||
std::cout << " ------------------------------------------- " << std::endl;
|
||||
std::cout << "|" << std::setw(10) << "index";
|
||||
std::cout << "|" << std::setw(10) << "first name";
|
||||
std::cout << "|" << std::setw(10) << "last name";
|
||||
std::cout << "|" << std::setw(10) << "nickname";
|
||||
std::cout << "|" << std::endl;
|
||||
std::cout << " ---------- ---------- ---------- ---------- " << std::endl;
|
||||
for (int i = 0; i <= it; i++)
|
||||
{
|
||||
std::cout << "|" << std::setw(10) << i;
|
||||
std::cout << "|" << std::setw(10) << truncate(contact[i].get_first(), 10);
|
||||
std::cout << "|" << std::setw(10) << truncate(contact[i].get_last(), 10);
|
||||
std::cout << "|" << std::setw(10) << truncate(contact[i].get_nick(), 10);
|
||||
std::cout << "|" << std::endl;
|
||||
}
|
||||
std::cout << " ------------------------------------------- " << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void PhoneBook::print_contact( int id ) {
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << B_CYAN "FIRST NAME : " << RESET << this->contact[id].get_first() << std::endl;
|
||||
std::cout << B_CYAN " LAST NAME : " << RESET << this->contact[id].get_last() << std::endl;
|
||||
std::cout << B_CYAN " NICKNAME : " << RESET << this->contact[id].get_nick() << std::endl;
|
||||
std::cout << B_CYAN " NUMBER : " << RESET << this->contact[id].get_num() << std::endl;
|
||||
std::cout << B_CYAN " SECRET : " << RESET << this->contact[id].get_secret() << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void PhoneBook::search_contact() {
|
||||
|
||||
std::string str;
|
||||
std::stringstream convert;
|
||||
int id;
|
||||
|
||||
this->print_phonebook();
|
||||
id = -1;
|
||||
std::cout << std::endl << B_CYAN "choose an index :" << std::endl;
|
||||
while (id < 0 || id > this->contact_count - 1 || id > 7)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
convert << str;
|
||||
convert >> id;
|
||||
if (id < 0 || id > this->contact_count - 1 || id > 7)
|
||||
std::cout << B_RED "sorry, not a valid index" RESET << std::endl;
|
||||
}
|
||||
this->print_contact(id);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,13 +2,37 @@
|
||||
# define PHONEBOOK_CLASS_HPP
|
||||
|
||||
#include "Contact.class.hpp"
|
||||
#include "color.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
class PhoneBook {
|
||||
|
||||
public:
|
||||
|
||||
PhoneBook();
|
||||
~PhoneBook();
|
||||
Contact contact;
|
||||
|
||||
void add_contact();
|
||||
void search_contact();
|
||||
void print_phonebook();
|
||||
void print_contact( int id);
|
||||
|
||||
private:
|
||||
|
||||
Contact contact[8];
|
||||
int contact_count;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* class PhoneBook :
|
||||
* add_contact
|
||||
* print_phonebook
|
||||
* search_by_index
|
||||
* exit
|
||||
*/
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
25
d00/ex01/color.h
Normal file
25
d00/ex01/color.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef COLOR_H
|
||||
# define COLOR_H
|
||||
|
||||
# define GRAY "\e[0;30m"
|
||||
# define RED "\e[0;31m"
|
||||
# define GREEN "\e[0;32m"
|
||||
# define YELLOW "\e[0;33m"
|
||||
# define BLUE "\e[0;34m"
|
||||
# define PURPLE "\e[0;35m"
|
||||
# define CYAN "\e[0;36m"
|
||||
# define WHITE "\e[0;37m"
|
||||
|
||||
# define B_GRAY "\e[1;30m"
|
||||
# define B_RED "\e[1;31m"
|
||||
# define B_GREEN "\e[1;32m"
|
||||
# define B_YELLOW "\e[1;33m"
|
||||
# define B_BLUE "\e[1;34m"
|
||||
# define B_PURPLE "\e[1;35m"
|
||||
# define B_CYAN "\e[1;36m"
|
||||
# define B_WHITE "\e[1;37m"
|
||||
|
||||
# define RESET "\e[0m"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "PhoneBook.class.hpp"
|
||||
#include "color.h"
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
@@ -6,22 +7,31 @@
|
||||
int main() {
|
||||
|
||||
std::string cmd;
|
||||
PhoneBook YellowPage;
|
||||
|
||||
while (1)
|
||||
{
|
||||
std::cout << std::endl;
|
||||
std::cout << B_YELLOW "enter a command: ADD / SEARCH / EXIT" << std::endl;
|
||||
std::cout << std::endl << B_GREEN;
|
||||
std::getline(std::cin, cmd);
|
||||
std::cout << RESET << std::endl;
|
||||
if (cmd.compare("ADD") == 0)
|
||||
std::cout << "it works !" << std::endl;
|
||||
YellowPage.add_contact();
|
||||
else if (cmd.compare("SEARCH") == 0)
|
||||
YellowPage.search_contact();
|
||||
else if (cmd.compare("EXIT") == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* class PhoneBook :
|
||||
* add_contact
|
||||
* print_phonebook
|
||||
* search_by_index
|
||||
* exit
|
||||
*/
|
||||
// B_GRAY "\e[1;30m"
|
||||
// B_RED "\e[1;31m"
|
||||
// B_GREEN "\e[1;32m"
|
||||
// B_YELLOW "\e[1;33m"
|
||||
// B_BLUE "\e[1;34m"
|
||||
// B_PURPLE "\e[1;35m"
|
||||
// B_CYAN "\e[1;36m"
|
||||
// B_WHITE "\e[1;37m"
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user