我正在写一个书店计划。该程序将一些书籍及其相关值(标题,价格,isbn,作者)存储在一个向量中。我试图写的一个功能是通过isbn搜索矢量并更新任何书籍匹配的值。这里是我的代码使用集合函数的C++更新对象属性
void UpdateOnIsbn(vector <CBooks> booklist)
{
string searchisbn;
char response;
string booktitle;
string author;
double price;
string ISBN;
cout << "Please enter an ISBN to be searched: ";
cin >> searchisbn;
for (int i = 0; i < booklist.size(); i++)
{
if (booklist[i].HasISBN(searchisbn))
{
booklist[i].Display();
cout << "Would you like to update the details of this book? (Y/N): ";
cin >> response;
if (response != 'n' && response != 'N')
{
cout << endl << "Please Enter New Title for book: ";
cin >> booktitle;
booklist[i].SetTitle(booktitle);
cout << endl << "Please Enter New Author ";
cin >> author;
booklist[i].SetAuthor(author);
cout << endl << "Please Enter New Price ";
cin >> price;
booklist[i].SetPrice(price);
cout << endl << "Please Enter New ISBN ";
cin >> ISBN;
booklist[i].SetISBN(ISBN);
}
}
}
}
功能似乎工作,因为它看起来要输入新的价值观,但它运行后,当我再次显示书籍的旧值不会被替换。请帮助
下面是一组功能中的一个例子:
void CBooks::SetPrice(double NewPrice)
{
m_Price = NewPrice;
}
当您使用调试器逐步执行代码时,您观察到了什么? –