Compare commits
6 Commits
44eec651e0
...
master
Author | SHA1 | Date | |
---|---|---|---|
bd77483ed4 | |||
16ab359cf2 | |||
120dfcfd83 | |||
585571872e | |||
bfda0a7548 | |||
03fe0a8720 |
25
ex00/Makefile
Normal file
25
ex00/Makefile
Normal 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
|
@ -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)
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -28,13 +28,12 @@ void PhoneBook::display_contacts()
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
if (this->len)
|
||||||
std::cout
|
std::cout
|
||||||
<< " index|"
|
<< " index|"
|
||||||
<< "first name|"
|
<< "first name|"
|
||||||
<< "last name |"
|
<< "last name |"
|
||||||
<< "nickname |"
|
<< "nickname "
|
||||||
<< "phone num.|"
|
|
||||||
<< "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]);
|
||||||
|
@ -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);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::string truncated(const std::string str);
|
std::string truncated(const std::string str);
|
||||||
|
BIN
subject.pdf
BIN
subject.pdf
Binary file not shown.
Reference in New Issue
Block a user