diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/cpp/address_book/contact_details.cc | |
add: graphs et rushs
Diffstat (limited to 'graphs/cpp/address_book/contact_details.cc')
| -rw-r--r-- | graphs/cpp/address_book/contact_details.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/graphs/cpp/address_book/contact_details.cc b/graphs/cpp/address_book/contact_details.cc new file mode 100644 index 0000000..3880d14 --- /dev/null +++ b/graphs/cpp/address_book/contact_details.cc @@ -0,0 +1,38 @@ +// +// Created by martial.simon on 2/26/25. +// + +#include "contact_details.hh" + +#include <iostream> +#include <stdexcept> +ContactDetails ContactDetails::makeDetails(const std::string& telephone_number, + const std::string& personal_email) +{ + for (auto digit : telephone_number) + { + if (!isdigit(digit)) + throw std::invalid_argument{ + "Phone number must only contain digits." + }; + } + size_t i; + for (i = 0; i < personal_email.length(); ++i) + { + if (personal_email[i] == '@') + break; + } + if (i == personal_email.length()) + throw std::invalid_argument{ "Email must contain at least one '@'." }; + return ContactDetails{ telephone_number, personal_email }; +} +std::ostream& operator<<(std::ostream& os, const ContactDetails& dt) +{ + os << dt.phone_ << ", " << dt.email_ << "\n"; + return os; +} +ContactDetails::ContactDetails(const std::string& telephone_number, + const std::string& personal_email) + : phone_{ telephone_number } + , email_{ personal_email } +{}
\ No newline at end of file |
