Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
Kolan Sh | 85d4a64c9c | |
Kolan Sh | e48b696ebd |
|
@ -8,7 +8,7 @@ void CBookItems::CreateNewItem(string sFirstName, string sLastName, string sPhon
|
|||
|
||||
void CBookItems::CreateNewItem(string sFirstName, string sLastName, string sPhoneNumber1, string sPhoneNumber2)
|
||||
{
|
||||
BookItem<string>* spaceItem = new BookItem<string>;
|
||||
BookItem* spaceItem = new BookItem;
|
||||
spaceItem->_sFirstName = sFirstName;
|
||||
spaceItem->_sLastName = sLastName;
|
||||
spaceItem->_sPhoneNumber1 = sPhoneNumber1;
|
||||
|
@ -33,7 +33,7 @@ int CBookItems::SetNewValueToItem(string sFirstName, string sLastName, string sP
|
|||
{
|
||||
if (nNumOfItem == i)
|
||||
{
|
||||
BookItem<string> spaceItem;
|
||||
BookItem spaceItem;
|
||||
spaceItem._sFirstName = sFirstName;
|
||||
spaceItem._sLastName = sLastName;
|
||||
spaceItem._sPhoneNumber1 = sPhoneNumber1;
|
||||
|
@ -72,9 +72,9 @@ int CBookItems::GetItem(int nNumOfItem, string& sFirstName, string& sLastName, s
|
|||
}
|
||||
}
|
||||
|
||||
const CBookItems::BookItem<string>& CBookItems::GetItem(int nNumOfItem)
|
||||
const CBookItems::BookItem& CBookItems::GetItem(int nNumOfItem)
|
||||
{
|
||||
if (nNumOfItem < 0 || nNumOfItem > _aItems.size()) return CBookItems::BookItem<string>();
|
||||
if (nNumOfItem < 0 || nNumOfItem > _aItems.size()) return CBookItems::BookItem();
|
||||
return _aItems[nNumOfItem];
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ int CBookItems::LoadItems(string sNameOfFile)
|
|||
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& s, const CBookItems::BookItem<string>& item)
|
||||
std::ostream& operator<<(std::ostream& s, const CBookItems::BookItem& item)
|
||||
{
|
||||
s << item._sFirstName << " " << item._sLastName << ": " << item._sPhoneNumber1;
|
||||
if (item._sPhoneNumber2 != "")
|
||||
|
@ -318,8 +318,17 @@ std::ostream& operator<<(std::ostream& s, const CBookItems::BookItem<string>& it
|
|||
return s;
|
||||
}
|
||||
|
||||
std::istream& operator>>(std::istream& s, CBookItems::BookItem<string>& item)
|
||||
std::istream& operator>>(std::istream& s, CBookItems::BookItem& item)
|
||||
{
|
||||
s >> item._sFirstName >> item._sLastName >> item._sPhoneNumber1 >> item._sPhoneNumber2;
|
||||
return s;
|
||||
}
|
||||
|
||||
const string CBookItems::BookItem::to_string() const
|
||||
{
|
||||
string str = _sFirstName + " " + _sLastName + ": " + _sPhoneNumber1;
|
||||
|
||||
if (_sPhoneNumber2 != "")
|
||||
str += ", " + _sPhoneNumber2;
|
||||
return str;
|
||||
}
|
|
@ -21,13 +21,25 @@ class CBookItems
|
|||
{
|
||||
public:
|
||||
template<class T>
|
||||
class BookItem
|
||||
class BaseBookItem
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
T _sFirstName;
|
||||
T _sLastName;
|
||||
T _sPhoneNumber1;
|
||||
T _sPhoneNumber2;
|
||||
public:
|
||||
BaseBookItem()
|
||||
{
|
||||
}
|
||||
virtual ~BaseBookItem()
|
||||
{
|
||||
}
|
||||
virtual const string to_string() const = 0;
|
||||
};
|
||||
|
||||
class BookItem : BaseBookItem<string>
|
||||
{
|
||||
public:
|
||||
BookItem()
|
||||
{
|
||||
|
@ -35,18 +47,18 @@ public:
|
|||
virtual ~BookItem()
|
||||
{
|
||||
}
|
||||
|
||||
//===============================================================================
|
||||
/**
|
||||
*Переопределяет операторы вывода/вывода
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& s, const BookItem<string>& item);
|
||||
friend std::istream& operator>>(std::istream& s, BookItem<string>& item);
|
||||
friend std::ostream& operator<<(std::ostream& s, const BookItem& item);
|
||||
friend std::istream& operator>>(std::istream& s, BookItem& item);
|
||||
|
||||
friend CBookItems;
|
||||
const string to_string() const;
|
||||
};
|
||||
|
||||
vector<BookItem<string> > _aItems;
|
||||
vector<BookItem> _aItems;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -90,7 +102,7 @@ public:
|
|||
/**
|
||||
*Возвращает элемент телефонного справочника
|
||||
*/
|
||||
const BookItem<string>& GetItem(int nNumOfItem);
|
||||
const BookItem& GetItem(int nNumOfItem);
|
||||
|
||||
//===============================================================================
|
||||
/**
|
||||
|
|
|
@ -86,13 +86,7 @@ void CConsoleUI::FindItem(CBookItems& CPhoneBook)
|
|||
|
||||
for (int i = 0; i < nNumOfDesirvedItems.size(); i++)
|
||||
{
|
||||
string sFName = " ";
|
||||
string sLName = " ";
|
||||
string sNum1 = " ";
|
||||
string sNum2 = " ";
|
||||
|
||||
CPhoneBook.GetItem(nNumOfDesirvedItems.at(i), sFName, sLName, sNum1, sNum2);
|
||||
cout << 1 + i << ". " << sFName << " " << sLName << ": " << sNum1 << ", " << sNum2 << endl;
|
||||
cout << 1 + i << ". " << CPhoneBook.GetItem(nNumOfDesirvedItems.at(i)).to_string() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue