fix: all
This commit is contained in:
parent
11eb368caf
commit
29364df310
@ -1,60 +0,0 @@
|
||||
#include <ios>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "Contact.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
Contact::Contact(std::string first_name, std::string last_name, std::string nickname, std::string phone_number)
|
||||
{
|
||||
this->nickname = nickname;
|
||||
this->last_name = last_name;
|
||||
this->first_name = first_name;
|
||||
this->phone_number = phone_number;
|
||||
}
|
||||
|
||||
Contact::Contact()
|
||||
{
|
||||
this->first_name = "";
|
||||
this->last_name = "";
|
||||
this->phone_number = "";
|
||||
this->phone_number = "";
|
||||
}
|
||||
|
||||
Contact::~Contact()
|
||||
{
|
||||
}
|
||||
|
||||
Contact &Contact::operator=(const Contact &contact)
|
||||
{
|
||||
this->first_name = contact.first_name;
|
||||
this->last_name = contact.last_name;
|
||||
this->nickname = contact.nickname;
|
||||
this->phone_number = contact.phone_number;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
bool Contact::isValid() const
|
||||
{
|
||||
return (!(this->first_name == "" || this->last_name == "" || this->nickname == "" || this->phone_number == ""));
|
||||
}
|
||||
|
||||
std::string Contact::to_string() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << std::setw(10) << truncated(this->first_name) << "|"
|
||||
<< std::setw(10) << truncated(this->last_name) << "|"
|
||||
<< std::setw(10) << truncated(this->nickname) << "|"
|
||||
<< std::setw(10) << truncated(this->phone_number);
|
||||
|
||||
return(ss.str());
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Contact& contact)
|
||||
{
|
||||
os << contact.to_string() << std::endl;
|
||||
return (os);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class Contact {
|
||||
private:
|
||||
std::string first_name;
|
||||
std::string last_name;
|
||||
std::string nickname;
|
||||
std::string phone_number;
|
||||
|
||||
public:
|
||||
Contact(std::string first_name, std::string last_name, std::string nickname, std::string phone_number);
|
||||
Contact();
|
||||
~Contact();
|
||||
|
||||
Contact &operator=(const Contact &contact);
|
||||
|
||||
bool isValid() const;
|
||||
std::string to_string() const;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Contact& fixed);
|
@ -1,36 +0,0 @@
|
||||
#include "PhoneBook.hpp"
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
PhoneBook::PhoneBook()
|
||||
{
|
||||
this->len = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
for (i = 0; i < this->len; i++)
|
||||
{
|
||||
std::cout << this->contacts[i];
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#include "Contact.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
class PhoneBook {
|
||||
private:
|
||||
Contact contacts[8];
|
||||
size_t len;
|
||||
|
||||
public:
|
||||
PhoneBook();
|
||||
void add_contact(Contact new_contact);
|
||||
void display_contacts();
|
||||
};
|
BIN
ex01/bin/.nfs000000000c70039200000411
Executable file
BIN
ex01/bin/.nfs000000000c70039200000411
Executable file
Binary file not shown.
@ -1,63 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <bits/stdc++.h>
|
||||
#include <string>
|
||||
#include "PhoneBook.hpp"
|
||||
|
||||
Contact read_contact()
|
||||
{
|
||||
std::string first_name;
|
||||
std::string last_name;
|
||||
std::string nickname;
|
||||
std::string phone_number;
|
||||
|
||||
std::cout << "first_name: ";
|
||||
std::getline(std::cin, first_name);
|
||||
std::cout << "last_name: ";
|
||||
std::getline(std::cin, last_name);
|
||||
std::cout << "nickname: ";
|
||||
std::getline(std::cin, nickname);
|
||||
std::cout << "phone_number: ";
|
||||
std::getline(std::cin, phone_number);
|
||||
|
||||
return Contact(first_name, last_name, nickname, phone_number);
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string command;
|
||||
Contact new_contact;
|
||||
PhoneBook phone_book;
|
||||
|
||||
phone_book = PhoneBook();
|
||||
while (true)
|
||||
{
|
||||
std::cout << "command: ";
|
||||
std::getline(std::cin, command);
|
||||
if (command == "ADD")
|
||||
{
|
||||
new_contact = read_contact();
|
||||
if (new_contact.isValid())
|
||||
phone_book.add_contact(new_contact);
|
||||
else
|
||||
{
|
||||
std::cerr << "Contact Error !" << std::endl;
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
else if (command == "SEARCH")
|
||||
{
|
||||
phone_book.display_contacts();
|
||||
}
|
||||
else if (command == "EXIT")
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Command not found" << std::endl;
|
||||
return (2);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
#include <string>
|
||||
|
||||
std::string truncated(const std::string str)
|
||||
{
|
||||
std::string out;
|
||||
|
||||
out = str.substr(0, 10);
|
||||
if (str.length() > 10)
|
||||
out[9] = '.';
|
||||
return (out);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
#include <string>
|
||||
|
||||
std::string truncated(const std::string str);
|
Loading…
Reference in New Issue
Block a user