mirror of
https://github.com/Ladebeze66/cpp-partie-1.git
synced 2026-11-09 13:17:15 +01:00
ccp
This commit is contained in:
18
cpp00/ex01/.vscode/c_cpp_properties.json
vendored
Normal file
18
cpp00/ex01/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
24
cpp00/ex01/.vscode/launch.json
vendored
Normal file
24
cpp00/ex01/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": false,
|
||||
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp00/ex01",
|
||||
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp00/ex01/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
108
cpp00/ex01/.vscode/settings.json
vendored
Normal file
108
cpp00/ex01/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"random": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
}
|
||||
}
|
||||
97
cpp00/ex01/Contact.cpp
Normal file
97
cpp00/ex01/Contact.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Contact.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 17:17:14 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 20:52:55 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Contact.hpp"
|
||||
|
||||
Contact::Contact() {}
|
||||
|
||||
void Contact::SetDetails()
|
||||
{
|
||||
std::cout << "First Name: ";
|
||||
std::cin >> _first_name;
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
std::cout << "Last Name: ";
|
||||
std::cin >> _last_name;
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
std::cout << "Nickname: ";
|
||||
std::cin >> _nickname;
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
while (true)
|
||||
{
|
||||
std::cout << "Phone Number: ";
|
||||
std::cin >> _phone_number;
|
||||
|
||||
bool isValid = true;
|
||||
for (char c : _phone_number)
|
||||
{
|
||||
if (!std::isdigit(c))
|
||||
{
|
||||
isValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isValid)
|
||||
{
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Invalid input. A phone number should contain only digits (0-9)." << std::endl;
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
}
|
||||
}
|
||||
std::cout << "Darkest Secret: ";
|
||||
std::getline(std::cin, _darkest_secret);
|
||||
}
|
||||
|
||||
Contact::~Contact() {}
|
||||
|
||||
void Contact::DisplaySummary(int index) const
|
||||
{
|
||||
std::string redBar = "\033[31m|\033[0m";
|
||||
std::cout << std::setw(8) << index << redBar;
|
||||
if (_first_name.length() > 10)
|
||||
{
|
||||
std::cout << std::setw(10) << _first_name.substr(0,9) + "." << redBar;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << std::setw(10) << _first_name << redBar;
|
||||
}
|
||||
if (_last_name.length() > 10)
|
||||
{
|
||||
std::cout << std::setw(10) << _last_name.substr(0,9) + "." << redBar;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << std::setw(10) << _last_name << redBar;
|
||||
}
|
||||
if (_nickname.length() > 10)
|
||||
{
|
||||
std::cout << std::setw(10) << _nickname.substr(0,9) + "." << redBar;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << std::setw(10) << _nickname << redBar;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void Contact::DisplayDetails() const
|
||||
{
|
||||
std::cout << "First Name: " << _first_name << std::endl;
|
||||
std::cout << "Last Name: " << _last_name << std::endl;
|
||||
std::cout << "Nickname: " << _nickname << std::endl;
|
||||
std::cout << "Phone Number: " << _phone_number << std::endl;
|
||||
std::cout << "Darkest Secret: " << _darkest_secret << std::endl;
|
||||
}
|
||||
38
cpp00/ex01/Contact.hpp
Normal file
38
cpp00/ex01/Contact.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Contact.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 16:56:55 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 19:49:10 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CONTACT_HPP
|
||||
# define CONTACT_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
|
||||
class Contact
|
||||
{
|
||||
public:
|
||||
Contact();
|
||||
~Contact();
|
||||
void SetDetails();
|
||||
void DisplaySummary(int index) const;
|
||||
void DisplayDetails() const;
|
||||
|
||||
private:
|
||||
std::string _first_name;
|
||||
std::string _last_name;
|
||||
std::string _nickname;
|
||||
std::string _phone_number;
|
||||
std::string _darkest_secret;
|
||||
};
|
||||
|
||||
#endif
|
||||
BIN
cpp00/ex01/Contact.o
Normal file
BIN
cpp00/ex01/Contact.o
Normal file
Binary file not shown.
63
cpp00/ex01/Makefile
Normal file
63
cpp00/ex01/Makefile
Normal file
@@ -0,0 +1,63 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/12/23 18:31:36 by fgras-ca #+# #+# #
|
||||
# Updated: 2023/12/23 19:06:37 by fgras-ca ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
|
||||
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
|
||||
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
|
||||
echo "( ( ( ( ( ( ( ("
|
||||
|
||||
DEF_COLOR = \033[0m
|
||||
GRAY = \033[0;90m
|
||||
RED = \033[0;91m
|
||||
GREEN = \033[0;92m
|
||||
YELLOW = \033[0;93m
|
||||
BLUE = \033[0;94m
|
||||
MAGENTA = \033[0;95m
|
||||
CYAN = \033[0;96m
|
||||
WHITE = \033[0;97m
|
||||
ORANGE = \033[38;5;214m
|
||||
|
||||
NAME = phonebook
|
||||
|
||||
SRC = PhoneBook.cpp \
|
||||
Contact.cpp \
|
||||
main.cpp \
|
||||
|
||||
OBJS = ${SRC:.cpp=.o}
|
||||
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Werror -Wextra -std=c++98
|
||||
RM = rm -f
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
$(NAME) : $(OBJS)
|
||||
@echo "$(RED)Compilation bookphone... $(DEF_COLOR)"
|
||||
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
|
||||
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./phonebook"!!$(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
clean :
|
||||
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
|
||||
$(RM) $(OBJS)
|
||||
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
fclean : clean
|
||||
@echo "$(RED)Delete program name... $(DEF_COLOR)"
|
||||
$(RM) $(NAME)
|
||||
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
re : fclean all
|
||||
|
||||
.PHONY : all clean fclean re
|
||||
69
cpp00/ex01/PhoneBook.cpp
Normal file
69
cpp00/ex01/PhoneBook.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* PhoneBook.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 18:01:39 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 20:52:57 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "PhoneBook.hpp"
|
||||
|
||||
PhoneBook::PhoneBook() : next_index(0), total_contacts(0) {}
|
||||
|
||||
PhoneBook::~PhoneBook() {}
|
||||
|
||||
void PhoneBook::AddContact()
|
||||
{
|
||||
contacts[next_index].SetDetails();
|
||||
next_index = (next_index + 1) % 8;
|
||||
if (total_contacts < 8)
|
||||
{
|
||||
total_contacts++;
|
||||
}
|
||||
std::cout << "Contact added successfully!" << std::endl;
|
||||
}
|
||||
|
||||
void PhoneBook::SearchContact() const
|
||||
{
|
||||
std::cout << "\033[31m";
|
||||
std::cout << "------------------------------------------" << std::endl;
|
||||
std::cout << std::setw(8) << "Index" << "|"
|
||||
<< std::setw(10) << "First" << "|"
|
||||
<< std::setw(10) << "Last" << "|"
|
||||
<< std::setw(10) << "Nickname" << "|" << std::endl;
|
||||
std::cout << "------------------------------------------" << std::endl;
|
||||
std::cout << "\033[0m";
|
||||
for (int i = 0; i < total_contacts; ++i)
|
||||
{
|
||||
contacts[i].DisplaySummary(i + 1);
|
||||
}
|
||||
std::cout << "\033[31m";
|
||||
std::cout << "------------------------------------------" << std::endl;
|
||||
std::cout << "\033[0m";
|
||||
while (true)
|
||||
{
|
||||
std::cout << "Enter the index of the contact to display: ";
|
||||
int index;
|
||||
std::cin >> index;
|
||||
|
||||
if (std::cin.fail())
|
||||
{
|
||||
std::cin.clear();
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
std::cout << "Invalid input. Please enter a number." << std::endl;
|
||||
}
|
||||
else if (index < 1 || index > total_contacts)
|
||||
{
|
||||
std::cout << "Invalid index. Please enter a number between 1 and " << total_contacts << "." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
contacts[index - 1].DisplayDetails();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
cpp00/ex01/PhoneBook.hpp
Normal file
37
cpp00/ex01/PhoneBook.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* PhoneBook.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 17:55:10 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 19:52:34 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PHONEBOOK_HPP
|
||||
# define PHONEBOOK_HPP
|
||||
|
||||
#include "Contact.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
|
||||
class PhoneBook
|
||||
{
|
||||
public:
|
||||
PhoneBook();
|
||||
~PhoneBook();
|
||||
|
||||
void AddContact();
|
||||
void SearchContact() const;
|
||||
|
||||
private:
|
||||
Contact contacts[8];
|
||||
int next_index;
|
||||
int total_contacts;
|
||||
};
|
||||
|
||||
#endif
|
||||
BIN
cpp00/ex01/PhoneBook.o
Normal file
BIN
cpp00/ex01/PhoneBook.o
Normal file
Binary file not shown.
44
cpp00/ex01/main.cpp
Normal file
44
cpp00/ex01/main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/23 18:16:58 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/23 18:31:05 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Contact.hpp"
|
||||
#include "PhoneBook.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
PhoneBook phonebook;
|
||||
std::string command;
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::cout << "Enter command (ADD, SEARCH, or EXIT): ";
|
||||
std::cin >> command;
|
||||
|
||||
if (command == "ADD")
|
||||
{
|
||||
phonebook.AddContact();
|
||||
}
|
||||
else if (command == "SEARCH")
|
||||
{
|
||||
phonebook.SearchContact();
|
||||
}
|
||||
else if (command == "EXIT")
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Command not recognized." << std::endl;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
BIN
cpp00/ex01/main.o
Normal file
BIN
cpp00/ex01/main.o
Normal file
Binary file not shown.
BIN
cpp00/ex01/phonebook
Executable file
BIN
cpp00/ex01/phonebook
Executable file
Binary file not shown.
Reference in New Issue
Block a user