Answer to Question #254650 in C++ for Pallavi k

Question #254650
Find the error and complete the following program #include <iostream> #include <vector> std::vector<std::string> getUniqueBrands(const std::vector<std::string>& brand1, const std::vector<std::string>& brand2) { throw std::logic_error("yet to be implemented"); } int main() { std::vector<std::string> brand1 = {"LOUIS_VUITTON", "HERMES", "PRADA"}; std::vector<std::string> brand2 = {"GUCCI", "PRADA", "HERMES"}; std::vector<std::string> result = getUniqueBrands(brand1, brand2); for(auto element : result) { std::cout << element << ' '; // should print GUCCI HERMES LOUIS_VUITTON PRADA } }
1
Expert's answer
2021-10-21T15:36:45-0400
#include <iostream>

#include <vector>

std::vector<std::string> getUniqueBrands(const std::vector<std::string>& brand1, const std::vector<std::string>& brand2)

{

std::vector<std::string>res;

for(auto element : brand2)

{

if(element!="PRADA")

res.push_back(element);

}

for(auto element : brand1)

{

if(element!="HERMES")

res.push_back(element);

}

return res;

}

int main()

{

std::vector<std::string> brand1 = {"LOUIS_VUITTON", "HERMES", "PRADA"};

std::vector<std::string> brand2 = {"GUCCI", "PRADA", "HERMES"};

std::vector<std::string> result = getUniqueBrands(brand1, brand2);

for(auto element : result)

{

std::cout << element << ' '; // should print GUCCI HERMES LOUIS_VUITTON PRADA

}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS