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
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
NAME = contacts
|
||||
NAME = ex02
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
@ -10,6 +10,7 @@ OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
all: $(NAME)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
mkdir -p obj
|
||||
$(CXX) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
|
@ -45,20 +45,14 @@ std::string Contact::to_string_partial() const
|
||||
std::string short_first_name;
|
||||
std::string short_last_name;
|
||||
std::string short_nickname;
|
||||
std::string short_phone_number;
|
||||
std::string short_darkest_secret;
|
||||
|
||||
short_first_name = truncated(this->first_name);
|
||||
short_last_name = truncated(this->last_name);
|
||||
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 << "|"
|
||||
<< std::setw(10) << short_last_name << "|"
|
||||
<< std::setw(10) << short_nickname << "|"
|
||||
<< std::setw(10) << short_phone_number << "|"
|
||||
<< std::setw(10) << short_darkest_secret;
|
||||
<< std::setw(10) << short_nickname;
|
||||
|
||||
return(ss.str());
|
||||
}
|
||||
@ -67,11 +61,11 @@ std::string Contact::to_string_complete() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << std::setw(10) << this->first_name << "|"
|
||||
<< std::setw(10) << this->last_name << "|"
|
||||
<< std::setw(10) << this->nickname << "|"
|
||||
<< std::setw(10) << this->phone_number << "|"
|
||||
<< std::setw(10) << this->darkest_secret << "|";
|
||||
ss << "first name: " << this->first_name << std::endl
|
||||
<< "last name: " << this->last_name << std::endl
|
||||
<< "nickname: " << this->nickname << std::endl
|
||||
<< "phone number: " << this->phone_number << std::endl
|
||||
<< "darkest secret: " << this->darkest_secret;
|
||||
|
||||
return(ss.str());
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -28,14 +28,13 @@ void PhoneBook::display_contacts()
|
||||
{
|
||||
size_t i;
|
||||
|
||||
std::cout
|
||||
<< " index|"
|
||||
<< "first name|"
|
||||
<< "last name |"
|
||||
<< "nickname |"
|
||||
<< "phone num.|"
|
||||
<< "darkest s."
|
||||
<< std::endl;
|
||||
if (this->len)
|
||||
std::cout
|
||||
<< " index|"
|
||||
<< "first name|"
|
||||
<< "last name |"
|
||||
<< "nickname "
|
||||
<< std::endl;
|
||||
|
||||
for (i = 0; i < this->len; i++)
|
||||
{
|
||||
@ -49,7 +48,6 @@ void PhoneBook::display_contacts()
|
||||
|
||||
Contact* PhoneBook::search(int index)
|
||||
{
|
||||
std::cout << this->len << " " << index << std::endl;
|
||||
if ((size_t) index >= this->len || index < 0)
|
||||
return (NULL);
|
||||
return (&this->contacts[index]);
|
||||
|
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include "Contact.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
@ -8,7 +9,6 @@ class PhoneBook {
|
||||
|
||||
public:
|
||||
size_t len;
|
||||
|
||||
PhoneBook();
|
||||
|
||||
void add_contact(Contact &new_contact);
|
||||
|
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
std::string truncated(const std::string str);
|
||||
|
BIN
subject.pdf
BIN
subject.pdf
Binary file not shown.
Reference in New Issue
Block a user