Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write C++ Code sample code // Created by Y. Wu, Jan 31, 2023 // You are given an input containter (of any STL set/vec/etc) of

Write C++ Code

image text in transcribedsample code

// Created by Y. Wu, Jan 31, 2023

// You are given an input containter (of any STL set/vec/etc) of certain type (e.g., int, string, etc), a container of forbidden items (which may be any STL container type, and so may not be sorted), and a new censored value (of the same type). You are to output (STL container of the same type) the sorted list of items from the input such that this list contains all the items from the input, and any value appearing in the forbidden list is converted to the censored value.

// For example, suppose the input: [1 -1 2, 5, 2], forbidden list [-1], censored value = 0, then the output is: [0, 1, 2, 2, 5]

// Now define the function ECCensor ...

test code

// Test ECCensor. To compile: c++ ECCensorTest.cpp -o test

#include "ECCensor.cpp"

#include

#include

#include

#include

using namespace std;

template

void ASSERT_EQ(T x, T y)

{

if( x == y )

{

cout

}

else

{

cout

}

}

void Test1( )

{

vector vecIn;

vecIn.push_back(1);

vecIn.push_back(-1);

vecIn.push_back(2);

vecIn.push_back(5);

vecIn.push_back(2);

vector listForbidden;

listForbidden.push_back(10);

listForbidden.push_back(-1);

vector listOuts;

ECCensor(vecIn, listForbidden, 0, listOuts );

ASSERT_EQ((int)listOuts.size(), 5);

ASSERT_EQ(listOuts[0], 0);

ASSERT_EQ(listOuts[1], 1);

ASSERT_EQ(listOuts[2], 2);

ASSERT_EQ(listOuts[3], 2);

ASSERT_EQ(listOuts[4], 5);

}

int main()

{

Test1();

}

1 Merging containers You are to implement a function called ECMergeContainers, which takes two parameters: (i) a list (container) of some lists (containers), and (ii) a container for output. Here, container is a STL container e.g., vector, set, etc. ECMergeContainers will merge all the lists of containers into a single container (which should be sorted). 1. Your code must be as flexible as possible. That is, you should allow different kinds of STL containers to be the input and output. 2. Your code must be concise: use no more than 10 lines of code inside the function! 3. For output, some containers allow duplicates and you should keep the duplicate. If the output container doesn't allow duplicate (like set), then it is OK to discard duplicate

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

o Dependent Pairs) Answered: 1 week ago

Answered: 1 week ago

Question

4. What actions should Bouleau & Huntley take now?

Answered: 1 week ago