67 lines
1.0 KiB
C++
67 lines
1.0 KiB
C++
#include "../include/PhoneBook.hpp"
|
|
#include <cstddef>
|
|
#include <iomanip>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
PhoneBook::PhoneBook()
|
|
{
|
|
this->len = 0;
|
|
}
|
|
|
|
PhoneBook::~PhoneBook()
|
|
{
|
|
for (size_t i = 0; i < this->len; i++)
|
|
delete this->contacts[i];
|
|
}
|
|
|
|
void PhoneBook::add_contact(Contact *new_contact)
|
|
{
|
|
size_t i;
|
|
|
|
if (this->len < 8)
|
|
{
|
|
this->contacts[this->len] = new_contact;
|
|
this->len++;
|
|
}
|
|
else
|
|
{
|
|
for (i = this->len; i != 0; i--) {
|
|
this->contacts[i] = this->contacts[i - 1];
|
|
}
|
|
this->contacts[0] = new_contact;
|
|
}
|
|
}
|
|
|
|
|
|
void PhoneBook::display_contacts()
|
|
{
|
|
size_t i;
|
|
|
|
std::cout
|
|
<< " index|"
|
|
<< "first name|"
|
|
<< "last name |"
|
|
<< "nickname |"
|
|
<< "phone num.|"
|
|
<< "darkest s."
|
|
<< std::endl;
|
|
|
|
for (i = 0; i < this->len; i++)
|
|
{
|
|
std::cout
|
|
<< std::setw(10) << i
|
|
<< "|"
|
|
<< this->contacts[i]->to_string_partial()
|
|
<< std::endl;
|
|
}
|
|
}
|
|
|
|
Contact* PhoneBook::search(int index)
|
|
{
|
|
if ((size_t) index > this->len || index < 0)
|
|
return (NULL);
|
|
return (this->contacts[index]);
|
|
}
|