Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions