Question: C++ questions 1. Using remove_if and a custom callback function, write a function RemoveShortWords that accepts a vector and removes all strings of length 3

C++ questions

1. Using remove_if and a custom callback function, write a function RemoveShortWords that accepts a vector and removes all strings of length 3 or less from it.

This function can be written in two lines of code if you harness the algorithms correctly.

******************************************************************

Template for the main program.

 vector myList; myList.push_back("ABCDEF"); myList.push_back("ABCDE"); myList.push_back("AB"); myList.push_back("A"); myList.push_back("ABC"); myList.push_back("ABCDEFGH"); myList.push_back("ABCEDFGH"); myList.push_back("123"); myList.push_back("12"); myList.push_back("1"); myList.push_back("12345"); // Print out the vector before the sort cout << "****" << endl; removeShortWords(myList); // Print out the vector after the modify 

2.

Using only the STL, Write a function BiasedSort that accepts a vector by reference and sorts the vector lexicographically, except that if the vector contains the string Me First, that string is always at the front of the sorted list. This may seem like a silly problem, but can come up in some circumstances.

For example, if you have a list of songs in a music library, you might want songs with the title Untitled to always appear at the top.

***************************************************

Main Program template

 vector myList; myList.push_back("Song 1"); myList.push_back("Song 5"); myList.push_back("A Song 2"); myList.push_back("Song 2"); myList.push_back("Song 3"); myList.push_back("Me First Song 3"); myList.push_back("Song 7"); myList.push_back("Song 8"); myList.push_back("Me First Song 2"); myList.push_back("Song 4"); myList.push_back("Song 6"); myList.push_back("A Song 1"); myList.push_back("Me First Song 1"); // Print out the vector before the sort cout << "****" << endl; BiasedSort(myList); // Print out the vector after the sort 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!