LW6: Abstract Class BaseBookItem with virtual to_string() method.
This commit is contained in:
parent
e48b696ebd
commit
85d4a64c9c
|
@ -323,3 +323,12 @@ 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;
|
||||
}
|
|
@ -35,6 +35,7 @@ public:
|
|||
virtual ~BaseBookItem()
|
||||
{
|
||||
}
|
||||
virtual const string to_string() const = 0;
|
||||
};
|
||||
|
||||
class BookItem : BaseBookItem<string>
|
||||
|
@ -54,6 +55,7 @@ public:
|
|||
friend std::istream& operator>>(std::istream& s, BookItem& item);
|
||||
|
||||
friend CBookItems;
|
||||
const string to_string() const;
|
||||
};
|
||||
|
||||
vector<BookItem> _aItems;
|
||||
|
|
|
@ -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