geekbrains_cpp_difficult_mo.../lesson_8/lesson_1.hpp

58 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* lesson_1.hpp
*
* Created on: 16 окт. 2021 г.
* Author: alexander
*/
#pragma once
/*
* main.cpp
*
* Created on: 22 сент. 2021 г.
* Author: alexander
*/
#include <iostream>
#include <string>
#include <optional>
#include <vector>
#include <fstream>
struct Person
{
std::string firstname;
std::string lastname;
std::optional<std::string> patronymic;
};
struct PhoneNumber
{
int country_code;
int city_code;
std::string number;
std::optional<int> additional_number;
};
class PhoneBook
{
private:
std::vector<std::pair<Person, PhoneNumber>> m_data;
public:
PhoneBook(std::istream &file);
friend std::ostream& operator<<(std::ostream &out, const PhoneBook &pb);
void SortByName();
void SortByPhone();
std::pair<std::string, std::vector<PhoneNumber>> GetPhoneNumber(const std::string &firstname);
void ChangePhoneNumber(const Person &p, const PhoneNumber &pn);
};
std::optional<std::string> getOptStr(std::string &s);
std::ostream& operator<<(std::ostream &out, const Person &p);
bool operator<(const Person &p1, const Person &p2);
bool operator==(const Person &p1, const Person &p2);
bool operator<(const PhoneNumber &p1, const PhoneNumber &p2);
std::optional<int> getOptInt(std::string &s);
std::ostream& operator<<(std::ostream &out, const PhoneNumber &p);