In this program there is a function in the public section in store.hpp-it reads:
ID: 3728993 • Letter: I
Question
In this program there is a function in the public section in store.hpp-it reads: void productSearch(std::string str); the return is a cout statement. If the store.hpp file has instead the following: std::vector productSearch(std::string str); and the return is supposed to be a sorted vector of ID codes for every product whose title or description contains the search string, how does that change the store.cpp file? I am thinking you have to create a vector file in the function and return that vector-can you help with this problem?
Explanation / Answer
Hi,
Yes. You are right.
Approach will be like -
a. I am assuming that you have product table. You can query like - Select id from Product where title like '%str%' or description '%str%' order by id;
b. You need to create vector file -
c. iterate resulset of the query and add all id to the vector. Since we have used order by in the query all the id will be in sorted format.
d. Return the vector.
Thanks!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.