class Catalog {
bool BookCopy;
public:
string BookTitle;
Catalog()
{
BookCopy = false;
}
Catalog(string Title, bool Copy)
{
BookTitle = Title;
BookCopy = Copy;
}
void SetTitle(string Title) {BookTitle = Title; }
void SetBookCopy(bool Copy) {BookCopy = Copy; }
string GetTitle() { return BookTitle; }
bool GetCopy() { return BookCopy; }
};
class BookList {
vector<Catalog> List;
vector<Catalog>::iterator Transit;
public:
void Fill();
void Show();
};
void BookList::Fill() //Create book record
{
string Title;
bool Copy;
Catalog Buffer;
cout << "Enter book information, Stop To quit" << endl;
cout << "-------------------------- " << endl;
while(true)
{
cout << "Title: ";
getline(cin, Title);
if(Title == "Stop")
break;
for(Transit = List.begin() ; Transit != List.end() ; Transit++) {
if(Transit->GetTitle() == Title) {
Copy = true;
}
else
Copy = false;
}
我想檢查是否存在一個相同的標題時,創造一個新的記錄。如果存在,則將1分配給複製,否則將其保留爲0.當我製作具有相同標題的記錄時1不會分配給複製。檢查現有記錄
似乎代碼不完整。 – 2010-11-05 18:25:55
請顯示列表來自哪裏。它是否已經有數據或者你應該在輸入時添加每個標題到列表。 – 2010-11-05 18:26:53
你也可以粘貼'GetTitle'函數嗎? – Leonid 2010-11-05 18:28:11