zied soit firer

This commit is contained in:
Camille Chauvet 2023-06-22 20:41:12 +02:00
parent 585571872e
commit 120dfcfd83
6 changed files with 17 additions and 22 deletions

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,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++)

View File

@ -1,3 +1,4 @@
#pragma once
#include "Contact.hpp" #include "Contact.hpp"
#include <cstddef> #include <cstddef>
@ -5,10 +6,9 @@ class PhoneBook {
private: private:
Contact contacts[8]; Contact contacts[8];
size_t number; size_t number;
public:
size_t len; size_t len;
public:
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);