Compare commits

..

6 Commits

Author SHA1 Message Date
bd77483ed4 makefile create obj folder 2023-07-12 02:08:59 +02:00
16ab359cf2 fix : put len in public 2023-07-10 18:28:46 +02:00
120dfcfd83 zied soit firer 2023-06-22 20:41:12 +02:00
585571872e clean: remove debug print 2023-06-22 13:29:18 +02:00
bfda0a7548 add: makefile 2023-06-22 13:20:47 +02:00
03fe0a8720 clean: remove trash file 2023-06-22 13:17:37 +02:00
9 changed files with 43 additions and 23 deletions

25
ex00/Makefile Normal file
View File

@ -0,0 +1,25 @@
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
SRCDIR = src
OBJDIR = obj
NAME = ex02
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(NAME)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p obj
$(CXX) $(CPPFLAGS) -c $< -o $@
$(NAME): $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(NAME)
re: fclean all

View File

@ -2,7 +2,7 @@ CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
SRCDIR = src SRCDIR = src
OBJDIR = obj OBJDIR = obj
NAME = contacts NAME = ex02
SRCS = $(wildcard $(SRCDIR)/*.cpp) SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS)) OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
@ -10,6 +10,7 @@ OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(NAME) all: $(NAME)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p obj
$(CXX) $(CPPFLAGS) -c $< -o $@ $(CXX) $(CPPFLAGS) -c $< -o $@
$(NAME): $(OBJS) $(NAME): $(OBJS)

View File

@ -45,20 +45,14 @@ std::string Contact::to_string_partial() const
std::string short_first_name; std::string short_first_name;
std::string short_last_name; std::string short_last_name;
std::string short_nickname; std::string short_nickname;
std::string short_phone_number;
std::string short_darkest_secret;
short_first_name = truncated(this->first_name); short_first_name = truncated(this->first_name);
short_last_name = truncated(this->last_name); short_last_name = truncated(this->last_name);
short_nickname = truncated(this->nickname); short_nickname = truncated(this->nickname);
short_phone_number = truncated(this->phone_number);
short_darkest_secret = truncated(this->darkest_secret);
ss << std::setw(10) << short_first_name << "|" ss << std::setw(10) << short_first_name << "|"
<< std::setw(10) << short_last_name << "|" << std::setw(10) << short_last_name << "|"
<< std::setw(10) << short_nickname << "|" << std::setw(10) << short_nickname;
<< std::setw(10) << short_phone_number << "|"
<< std::setw(10) << short_darkest_secret;
return(ss.str()); return(ss.str());
} }
@ -67,11 +61,11 @@ std::string Contact::to_string_complete() const
{ {
std::stringstream ss; std::stringstream ss;
ss << std::setw(10) << this->first_name << "|" ss << "first name: " << this->first_name << std::endl
<< std::setw(10) << this->last_name << "|" << "last name: " << this->last_name << std::endl
<< std::setw(10) << this->nickname << "|" << "nickname: " << this->nickname << std::endl
<< std::setw(10) << this->phone_number << "|" << "phone number: " << this->phone_number << std::endl
<< std::setw(10) << this->darkest_secret << "|"; << "darkest secret: " << this->darkest_secret;
return(ss.str()); return(ss.str());
} }

View File

@ -1,3 +1,4 @@
#pragma once
#include <string> #include <string>
#include <iostream> #include <iostream>

View File

@ -28,14 +28,13 @@ void PhoneBook::display_contacts()
{ {
size_t i; size_t i;
std::cout if (this->len)
<< " index|" std::cout
<< "first name|" << " index|"
<< "last name |" << "first name|"
<< "nickname |" << "last name |"
<< "phone num.|" << "nickname "
<< "darkest s." << std::endl;
<< std::endl;
for (i = 0; i < this->len; i++) for (i = 0; i < this->len; i++)
{ {
@ -49,7 +48,6 @@ void PhoneBook::display_contacts()
Contact* PhoneBook::search(int index) Contact* PhoneBook::search(int index)
{ {
std::cout << this->len << " " << index << std::endl;
if ((size_t) index >= this->len || index < 0) if ((size_t) index >= this->len || index < 0)
return (NULL); return (NULL);
return (&this->contacts[index]); return (&this->contacts[index]);

View File

@ -1,3 +1,4 @@
#pragma once
#include "Contact.hpp" #include "Contact.hpp"
#include <cstddef> #include <cstddef>
@ -8,7 +9,6 @@ class PhoneBook {
public: public:
size_t len; size_t len;
PhoneBook(); PhoneBook();
void add_contact(Contact &new_contact); void add_contact(Contact &new_contact);

View File

@ -1,3 +1,4 @@
#pragma once
#include <string> #include <string>
std::string truncated(const std::string str); std::string truncated(const std::string str);

Binary file not shown.