Answer to Question #331982 in C++ for Shraddha

Question #331982

#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::count << element<< ' ';

//should print GUCHHI HERMES LOUIS_VUITTON PRADA

}

}




1
Expert's answer
2022-04-21T14:38:08-0400
#include <iostream>
#include <vector>
#include <string>

std::vector<std::string> getUniqueBrands(const std::vector<std::string>& brand1, const std::vector<std::string>& brand2)
{
	std::vector<std::string> result;
	for (auto element : brand2)
	{
		if (element != "PRADA")
			result.push_back(element);
	}
	for (auto element : brand1)
	{
		if (element != "HERMES")
			result.push_back(element);
	}
	return result;
}

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 GUCHHI 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